1. shemnon
  2. FlowDown

Commits

shemnon  committed 6a95a47

multimarkdown style tables
Temorarily use GitHub as the default stylesheet

  • Participants
  • Parent commits 337088a
  • Branches master

Comments (0)

Files changed (9)

File flowdown-app/src/main/java/FlowDown/FlowDownView.java

View file
  • Ignore whitespace
     CheckMenuItem micbOptionSmartQuotes;
 
     @FXML
+    CheckMenuItem micbOptionTables;
+
+    @FXML
     CheckMenuItem micbOptionWikiLinks;
 
     @FXML
 
         sourceTextArea.textProperty().addListener((observableValue, oldString, newString) -> updateMarkdown(newString));
 
-        styleCombo.getItems().setAll(MarkdownToNodeGenerator.STYLESHEET_DEFAULT, MarkdownToNodeGenerator.STYLESHEET_GITHUB, "Test.css");
+        styleCombo.getItems().setAll(MarkdownToNodeGenerator.STYLESHEET_FLOWDOWN, MarkdownToNodeGenerator.STYLESHEET_GITHUB, "Test.css");
         styleCombo.setValue(MarkdownToNodeGenerator.STYLESHEET_DEFAULT);
 
         mdNode = new MarkdownNode();
 
 
     public void setMarkDownStylesheets(String... stylesheets) {
+       contentScrollPane.getStylesheets().clear();
        contentScrollPane.getStylesheets().setAll(stylesheets);
     }
 }

File flowdown-app/src/main/java/FlowDown/Main.java

View file
  • Ignore whitespace
         model.optionHardLineWraps.bindBidirectional(view.micbOptionHardLineWraps.selectedProperty());
         model.optionSmartDashesAndDots.bindBidirectional(view.micbOptionSmartDashesAndDots.selectedProperty());
         model.optionSmartQuotes.bindBidirectional(view.micbOptionSmartQuotes.selectedProperty());
+        model.optionTables.bindBidirectional(view.micbOptionTables.selectedProperty());
         model.optionWikiLinks.bindBidirectional(view.micbOptionWikiLinks.selectedProperty());
 
 

File flowdown-app/src/main/resources/FlowDown/FlowDownView.fxml

View file
  • Ignore whitespace
             <SeparatorMenuItem mnemonicParsing="false" />
             <CheckMenuItem mnemonicParsing="false" onAction="$onUpdateConfig" text="Smart Dashes and Dots" fx:id="micbOptionSmartDashesAndDots" />
             <CheckMenuItem mnemonicParsing="false" onAction="$onUpdateConfig" text="Smart Quotes" fx:id="micbOptionSmartQuotes" />
+            <SeparatorMenuItem mnemonicParsing="false" />
+            <CheckMenuItem mnemonicParsing="false" onAction="$onUpdateConfig" text="Tables" fx:id="micbOptionTables" />
           </items>
         </Menu>
       </menus>
       <items>
         <Pane fx:id="toolbarSpacer" prefHeight="0.0" prefWidth="-1.0" />
         <Label alignment="BASELINE_RIGHT" minHeight="-Infinity" minWidth="-Infinity" text="Stylesheet:" />
-        <ComboBox fx:id="styleCombo" editable="true" minHeight="-Infinity" minWidth="-Infinity" onAction="$onRefreshCSS" prefHeight="-1.0" prefWidth="150.0" promptText="FlowDown.css">
+        <ComboBox fx:id="styleCombo" editable="true" minHeight="-Infinity" minWidth="-Infinity" onAction="$onRefreshCSS" prefHeight="-1.0" prefWidth="150.0">
           <items>
             <FXCollections fx:factory="observableArrayList">
               <String fx:value="Item 1" />

File markdown-node/src/main/java/org/bitbucket/shemnon/mdnode/DebugVisitor.java

View file
  • Ignore whitespace
 
 import org.pegdown.ast.*;
 
-import java.lang.invoke.MethodHandle;
-
 /**
  * Created with IntelliJ IDEA.
  * User: shemnon
  * Date: 3 Mar 2013
  * Time: 11:13 AM
- * To change this template use File | Settings | File Templates.
  */
 public class DebugVisitor extends MarkdownVisitor {
 
     int indentLevel = 0;
-    String indent = "                                             ";
+    String indent = "                                                                  ";
 
     public void invoke (Runnable mh, String name) {
         System.out.print(indent.substring(0, indentLevel));
         try {
             mh.run();
         } catch (Throwable throwable) {
-            throwable.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
+            throwable.printStackTrace();
         }
         indentLevel -= 2;
 
-
-
         System.out.print(indent.substring(0, indentLevel));
         System.out.print('/');
         System.out.println(name);
     }
 
     @Override
+    public void visit(TableCaptionNode node) {
+        invoke(() -> super.visit(node), "TableCaption");
+    }
+
+    @Override
     public void visit(TableHeaderNode node) {
         invoke(() -> super.visit(node), "TableHeader");
     }

File markdown-node/src/main/java/org/bitbucket/shemnon/mdnode/MarkdownToNodeGenerator.java

View file
  • Ignore whitespace
  */
 public class MarkdownToNodeGenerator {
 
-    public static final String STYLESHEET_DEFAULT = "FlowDown.css";
+    public static final String STYLESHEET_FLOWDOWN = "FlowDown.css";
     public static final String STYLESHEET_GITHUB = "Github.css";
+    public static final String STYLESHEET_DEFAULT = STYLESHEET_GITHUB;
 
     public static final String STYLE_CLASS_BODY = "md-body";
     public static final String STYLE_CLASS_CODE = "md-code";
     public static final String STYLE_CLASS_UNORDERED_LIST = "md-unordered-list";
     public static final String STYLE_CLASS_BULLET = "md-bullet";
     public static final String STYLE_CLASS_LIST_CONTENT = "md-list-content";
+    public static final String STYLE_CLASS_SEPARATOR = "md-separator";
+
+    public static final String STYLE_CLASS_TABLE = "md-table";
+    public static final String STYLE_CLASS_TABLE_HEADER = "md-table-header";
+    public static final String STYLE_CLASS_TABLE_ROW = "md-table-row";
+    public static final String STYLE_CLASS_TABLE_CAPTION = "md-table-caption";
 
     public static final int DEFAULT_PARSER_FLAGS = 0;
 

File markdown-node/src/main/java/org/bitbucket/shemnon/mdnode/MarkdownVisitor.java

View file
  • Ignore whitespace
 package org.bitbucket.shemnon.mdnode;
 
 import javafx.application.Platform;
+import javafx.geometry.HPos;
 import javafx.geometry.Pos;
 import javafx.geometry.VPos;
 import javafx.scene.control.Separator;
     Pane currentCollector;
 
     LinkedList<Integer> listCount = new LinkedList<>();
+    LinkedList<Integer> tableRowCount = new LinkedList<>();
+    LinkedList<Integer> tableColumnCount = new LinkedList<>();
 
     void pushNode(Pane n) {
         nodeStack.push(n);
                 pushNode(tf);
                 break;
             case HRule:
-                //TODO style it?
-                currentCollector.getChildren().add(new Separator());
+                Separator sep = new Separator();
+                sep.getStyleClass().add(MarkdownToNodeGenerator.STYLE_CLASS_SEPARATOR);
+                currentCollector.getChildren().add(sep);
                 break;
         }
     }
 
     @Override
     public void visit(Node node) {
-        System.out.println("Node");
+//        System.out.println("Node");
     }
 
     @Override
 
     @Override
     public void visit(TableBodyNode node) {
-        System.out.println("TableBody Node");
         visitChildren(node);
     }
 
     @Override
     public void visit(TableCaptionNode node) {
-        //TODO Table captions not supported right now
+        FlowPane fp = new FlowPane();
+
+
+        Integer row = tableRowCount.pop();
+        if (row > 0) {
+            row++;
+        }
+        GridPane.setRowIndex(fp, row);
+        GridPane.setColumnIndex(fp, 0);
+        tableRowCount.push(row+1);
+
+        GridPane.setColumnSpan(fp, GridPane.REMAINING);
+        fp.setAlignment(Pos.BASELINE_CENTER);
+
+        fp.getStyleClass().setAll(cssClasses);
+        fp.getStyleClass().add(MarkdownToNodeGenerator.STYLE_CLASS_TABLE_CAPTION);
+
+
+        TextFlow tf = new TextFlow();
+        tf.setMinWidth(Region.USE_PREF_SIZE);
+        tf.setMinHeight(Region.USE_PREF_SIZE);
+        tf.setMaxWidth(Region.USE_PREF_SIZE);
+        tf.setMaxHeight(Region.USE_PREF_SIZE);
+
+        tf.getStyleClass().setAll(cssClasses);
+
+        fp.getChildren().setAll(tf);
+
+        currentCollector.getChildren().add(fp);
+        pushNode(tf);
+        visitChildren(node);
+        popNode();
     }
 
     @Override
     public void visit(TableCellNode node) {
-        System.out.println("TableCell Node");
+        FlowPane fp = new FlowPane();
+
+        Integer col = tableColumnCount.pop();
+        GridPane.setRowIndex(fp, tableRowCount.peek());
+        GridPane.setColumnIndex(fp, col);
+        HPos hpos = ((GridPane)currentCollector).getColumnConstraints().get(col).getHalignment();
+        if (hpos != null) {
+            switch (hpos) {
+                case RIGHT:
+                    fp.setAlignment(Pos.BASELINE_RIGHT);
+                    break;
+                case LEFT:
+                    fp.setAlignment(Pos.BASELINE_LEFT);
+                    break;
+                case CENTER:
+                    fp.setAlignment(Pos.BASELINE_CENTER);
+                    break;
+            }
+        }
+        tableColumnCount.push(col+1);
+
+        GridPane.setColumnSpan(fp, node.getColSpan());
+        fp.getStyleClass().setAll(cssClasses);
+
+        TextFlow tf = new TextFlow();
+        tf.setMinWidth(Region.USE_PREF_SIZE);
+        tf.setMinHeight(Region.USE_PREF_SIZE);
+        tf.setMaxWidth(Region.USE_PREF_SIZE);
+        tf.setMaxHeight(Region.USE_PREF_SIZE);
+
+        tf.getStyleClass().setAll(cssClasses);
+
+        fp.getChildren().setAll(tf);
+
+        currentCollector.getChildren().add(fp);
+        pushNode(tf);
         visitChildren(node);
+        popNode();
     }
 
     @Override
     public void visit(TableColumnNode node) {
-        System.out.println("TableColumn Node");
+        System.out.println("TableColumn Node??");
         visitChildren(node);
     }
 
     @Override
     public void visit(TableHeaderNode node) {
-        System.out.println("TableHeader Node");
+        cssClasses.add(MarkdownToNodeGenerator.STYLE_CLASS_TABLE_HEADER);
         visitChildren(node);
+        cssClasses.remove(MarkdownToNodeGenerator.STYLE_CLASS_TABLE_HEADER);
     }
 
     @Override
     public void visit(TableNode node) {
-        System.out.println("TableNode Node");
+        tableRowCount.push(0);
+        GridPane gp = new GridPane();
+        gp.setHgap(0);
+        gp.setVgap(0);
+        gp.getStyleClass().add(MarkdownToNodeGenerator.STYLE_CLASS_TABLE);
+        List<ColumnConstraints> ccl = new ArrayList<>();
+        for (TableColumnNode tcn : node.getColumns()) {
+            ColumnConstraints cc = new ColumnConstraints();
+            switch (tcn.getAlignment()) {
+                case Left:
+                    cc.setHalignment(HPos.LEFT);
+                    break;
+                case Center:
+                    cc.setHalignment(HPos.CENTER);
+                    break;
+                case Right:
+                    cc.setHalignment(HPos.RIGHT);
+                    break;
+            }
+            ccl.add(cc);
+        }
+        gp.getColumnConstraints().setAll(ccl);
+        currentCollector.getChildren().add(gp);
+        pushNode(gp);
         visitChildren(node);
+        popNode();
+        tableRowCount.pop();
     }
 
     @Override
     public void visit(TableRowNode node) {
-        System.out.println("TableRow Node");
+        boolean odd = false;
+        int row = tableRowCount.pop();
+        if ((row & 0x1) == 0x1) {
+            odd = true;
+        }
+        tableRowCount.push(row + 1);
+        tableColumnCount.push(0);
+        cssClasses.add(MarkdownToNodeGenerator.STYLE_CLASS_TABLE_ROW);
+        if (odd) {
+            cssClasses.add("odd");
+        }
         visitChildren(node);
+        cssClasses.remove(MarkdownToNodeGenerator.STYLE_CLASS_TABLE_ROW);
+        tableColumnCount.pop();
+        if (odd) {
+            cssClasses.remove("odd");
+        }
     }
 }

File markdown-node/src/main/resources/org/bitbucket/shemnon/mdnode/FlowDown.css

View file
  • Ignore whitespace
  *   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 /* Based on the webkit default stylesheet
+ * http://trac.webkit.org/browser/trunk/Source/WebCore/css/html.css
  */
 
  Text {
   -fx-padding: 1.16em 0 1.16em;
 }
 
+GridPane {
+  -fx-border-color: grey;
+  -fx-padding: 1px;
+}
+
+FlowPane.md-table-header {
+  -fx-font-weight: bold;
+  -fx-border-insets: 1px;
+  -fx-border-color: grey;
+  -fx-padding: 1px;
+}
+
+FlowPane.md-table-row {
+  -fx-border-insets: 1px;
+  -fx-border-color: grey;
+  -fx-padding: 1px;
+}
+

File markdown-node/src/main/resources/org/bitbucket/shemnon/mdnode/Github.css

View file
  • Ignore whitespace
   -fx-fill: #777777;
 }
 
+
+GridPane {
+  -fx-border-width: 0px 0px 1px 1px;
+  -fx-border-color: #cccccc;
+}
+
+FlowPane.md-table-header {
+  -fx-font-weight: bold;
+  -fx-border-insets: 0px;
+  -fx-border-width: 1px 1px 0px 0px;
+  -fx-border-color: #cccccc;
+  -fx-padding: 6px 13px;
+}
+
+FlowPane.md-table-row {
+  -fx-border-insets: 0px;
+  -fx-border-insets: 0px;
+  -fx-border-width: 1px 1px 0px 0px;
+  -fx-border-color: #cccccc;
+  -fx-padding: 6px 13px;
+}
+
+.md-table-caption {
+  -fx-border-insets: 0px;
+  -fx-border-insets: 0px;
+  -fx-border-width: 1px 1px 0px 0px;
+  -fx-border-color: #cccccc;
+}
+
+FlowPane.odd {
+  -fx-background-color: #f8f8f8;
+}
+

File markdown-node/src/main/resources/org/bitbucket/shemnon/mdnode/Test.css

View file
  • Ignore whitespace
 /* Based on the webkit default stylesheet
  */
 
- VBox {
+VBox {
  -fx-border-color: green;
- }
+}
 
- HBox {
+HBox {
  -fx-border-color: blue;
- }
+}
 
- TextFlow {
+TextFlow {
  -fx-border-color: red;
- }
+}
 
- .md-para {
+.md-para {
  -fx-background-color: #0000ff33;
  }
 
   -fx-padding: 1.16em 0 1.16em;
 }
 
+GridPane {
+  -fx-border-color: cyan;
+  -fx-padding: 1px;
+}
+
+FlowPane.md-table-header {
+  -fx-font-weight: bold;
+  -fx-border-insets: 1px;
+  -fx-border-color: cyan;
+  -fx-padding: 1px;
+}
+
+FlowPane.md-table-row {
+  -fx-border-insets: 1px;
+  -fx-border-color: cyan;
+  -fx-padding: 1px;
+}