Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Can I use flexmark to turn a Markdown string into a List of Texts for use in a JavaFX TextFlow? #2

#1

GitHub Issue 116

Basically, I want to have an original text style

Text original = new Text();
original.setFont(...);
original.setSize(...);

Have an input markdown string

String md = "So _this_ is italic and **this** is bold";

Is there a way to get a List of Texts with their formatting? Or even just split the string into an array of another object that contains style data?

  • replies 3
  • views 2.2K
  • likes 0
#2

@TsundereBug, you can walk the AST to extract text and style.

Your example string results in the following HTML and AST:

```````````````````````````````` example Issue 116: 1
So _this_ is italic and **this** is bold
.
<p>So <em>this</em> is italic and <strong>this</strong> is bold</p>
.
Document[0, 41]
  Paragraph[0, 41]
    Text[0, 3] chars:[0, 3, "So "]
    Emphasis[3, 9] textOpen:[3, 4, "_"] text:[4, 8, "this"] textClose:[8, 9, "_"]
      Text[4, 8] chars:[4, 8, "this"]
    Text[9, 24] chars:[9, 24, " is i …  and "]
    StrongEmphasis[24, 32] textOpen:[24, 26, "**"] text:[26, 30, "this"] textClose:[30, 32, "**"]
      Text[26, 30] chars:[26, 30, "this"]
    Text[32, 40] chars:[32, 40, " is bold"]
````````````````````````````````

You can start with the TextCollectingVisitor and add the emphasis nodes to the list of processed nodes and store the information as these are encountered to contain the text of their children.

vsch accepted post #2 as the answer
#3
vsch unaccepted post #2
#4