Commits

shemnon  committed 32d12b0

Change location of stylesheets, to allow for runtime overriding.

  • Participants
  • Parent commits ef51955

Comments (0)

Files changed (3)

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

 
 public class MarkdownNode extends OffThreadTransformingPane<String> {
 
-    MarkdownToNodeGenerator generator;
+    public static final String STYLESHEET_FLOWDOWN = "FlowDown.css";
+    public static final String STYLESHEET_GITHUB = "Github.css";
+    public static final String STYLESHEET_DEFAULT = STYLESHEET_GITHUB;
+
+    protected MarkdownToNodeGenerator generator;
 
     public MarkdownNode() {
-        generator = new MarkdownToNodeGenerator();
-        setTransformation(generator::createMarkdownNode);
+        this(new MarkdownToNodeGenerator());
+        getStylesheets().setAll(MarkdownToNodeGenerator.class.getResource(STYLESHEET_DEFAULT).toExternalForm());
+    }
+
+    public MarkdownNode(MarkdownToNodeGenerator generator) {
+        this.generator = generator;
+        setTransformation(this.generator::createMarkdownNode);
     }
 
     public void setParserFlags(int flags) {

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

  */
 public class MarkdownToNodeGenerator {
 
-    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_EMPH = "md-emph";
 
     public static final int DEFAULT_PARSER_FLAGS = 0;
 
-    private int parserFlags;
+    protected int parserFlags;
 
-    private MarkdownVisitor visitor;
+    protected MarkdownVisitor visitor;
 
     public javafx.scene.Node createMarkdownNode(String markdown) {
         if (markdown == null) {
 
         root.accept(ourVisitor);
 
-        result.getStylesheets().setAll(MarkdownToNodeGenerator.class.getResource(STYLESHEET_DEFAULT).toExternalForm());
         result.getStyleClass().setAll(STYLE_CLASS_BODY);
         result.layout(); // this is needed to get the list box bullets to align properly
 

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

 * Date: 2 Feb 2013
 * Time: 8:56 AM
 */
-class MarkdownVisitor implements Visitor {
+public class MarkdownVisitor implements Visitor {
 
     Set<String> cssClasses = new TreeSet<>();
 
-    Deque<Pane> nodeStack = new LinkedList<>();
+    protected Deque<Pane> nodeStack = new LinkedList<>();
     Map<String, ReferenceNode> references = new HashMap<>();
-    Pane currentCollector;
+    protected Pane currentCollector;
 
     LinkedList<Integer> listCount = new LinkedList<>();
     LinkedList<Integer> tableRowCount = new LinkedList<>();
     LinkedList<Integer> tableColumnCount = new LinkedList<>();
 
-    void pushNode(Pane n) {
+    public void pushNode(Pane n) {
         nodeStack.push(n);
         currentCollector = n;
     }
 
-    void popNode() {
-        nodeStack.pop();
+    public void popNode() {
+        if (!nodeStack.isEmpty()) {
+            nodeStack.pop();
+        }
         currentCollector = nodeStack.peek();
     }