diff --git a/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/FormatterWithMods2.java b/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/FormatterWithMods2.java index f28b7bfe27..03797be19b 100644 --- a/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/FormatterWithMods2.java +++ b/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/FormatterWithMods2.java @@ -55,7 +55,7 @@ private void visit(Image node) { private void visit(LinkNodeBase node) { if (node.getPageRef().startsWith("/")) { node.setUrlChars(PrefixedSubSequence.prefixOf("https:", node.getPageRef())); - node.setChars(SegmentedSequence.create(node.getChars(), Arrays.asList(node.getSegmentsForChars()))); + node.setChars(node.getChars().getBuilder().addAll(Arrays.asList(node.getSegmentsForChars())).toSequence()); } } } diff --git a/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/SyntheticLinkSample.java b/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/SyntheticLinkSample.java index d0888af245..3c1c8b708b 100644 --- a/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/SyntheticLinkSample.java +++ b/flexmark-java-samples/src/com/vladsch/flexmark/java/samples/SyntheticLinkSample.java @@ -4,6 +4,7 @@ import com.vladsch.flexmark.ast.LinkNode; import com.vladsch.flexmark.ast.Text; import com.vladsch.flexmark.ast.TextBase; +import com.vladsch.flexmark.formatter.Formatter; import com.vladsch.flexmark.html.HtmlRenderer; import com.vladsch.flexmark.parser.Parser; import com.vladsch.flexmark.parser.PostProcessor; @@ -72,8 +73,8 @@ public void process(@NotNull NodeTracker state, @NotNull Node node) { BasedSequence linkAddress = PrefixedSubSequence.prefixOf("http://commonmark.org", linkText.getEmptySuffix()); linkNode = new Link(BasedSequence.NULL, linkText, BasedSequence.NULL, BasedSequence.NULL, linkAddress, BasedSequence.NULL); - linkNode.setCharsFromContent(); + linkNode.appendChild(contentNode); textBase.appendChild(linkNode); state.nodeAddedWithChildren(linkNode); @@ -118,12 +119,13 @@ public Document processDocument(@NotNull Document document) { // here you can append some markdown text but keep it based on original input by // using PrefixedSubSequence with only prefix without any characters from input string - // here we create a based sequence of "inserted" text with offset set to end of input string - BasedSequence insertedText = PrefixedSubSequence.prefixOf("Some inserted text with a link [flexmark-java](https://github.com/vsch/flexmark-java) in paragraph.", document.getChars().subSequence(document.getChars().length())); - // parse using the same options as the document but remove the SyntheticLinkExtension to prevent infinite recursion MutableDataHolder options = Parser.removeExtensions(new MutableDataSet(document), SyntheticLinkExtension.class); - Node insertedDocument = Parser.builder(options).build().parse(insertedText); + + // here we create a based sequence of "inserted" text with offset set to end of input string + String insertedText = "Some inserted text with a link [flexmark-java](https://github.com/vsch/flexmark-java) in paragraph."; + + Node insertedDocument = Parser.builder(options).build().parse(document.getChars().append(insertedText).toString()); // now can append nodes from inserted to document document.takeChildren(insertedDocument); @@ -184,5 +186,8 @@ public static void main(String[] args) { Node document = parser.parse("Some markdown content"); String html = renderer.render(document); System.out.println(html); + + String markdown = Formatter.builder(options).build().render(document); + System.out.println(markdown); } }