Skip to content

Commit ccdb4d7

Browse files
committed
update samples
1 parent eee271d commit ccdb4d7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Diff for: flexmark-java-samples/src/com/vladsch/flexmark/java/samples/FormatterWithMods2.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void visit(Image node) {
5555
private void visit(LinkNodeBase node) {
5656
if (node.getPageRef().startsWith("/")) {
5757
node.setUrlChars(PrefixedSubSequence.prefixOf("https:", node.getPageRef()));
58-
node.setChars(SegmentedSequence.create(node.getChars(), Arrays.asList(node.getSegmentsForChars())));
58+
node.setChars(node.getChars().getBuilder().addAll(Arrays.asList(node.getSegmentsForChars())).toSequence());
5959
}
6060
}
6161
}

Diff for: flexmark-java-samples/src/com/vladsch/flexmark/java/samples/SyntheticLinkSample.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.vladsch.flexmark.ast.LinkNode;
55
import com.vladsch.flexmark.ast.Text;
66
import com.vladsch.flexmark.ast.TextBase;
7+
import com.vladsch.flexmark.formatter.Formatter;
78
import com.vladsch.flexmark.html.HtmlRenderer;
89
import com.vladsch.flexmark.parser.Parser;
910
import com.vladsch.flexmark.parser.PostProcessor;
@@ -72,8 +73,8 @@ public void process(@NotNull NodeTracker state, @NotNull Node node) {
7273
BasedSequence linkAddress = PrefixedSubSequence.prefixOf("http://commonmark.org", linkText.getEmptySuffix());
7374

7475
linkNode = new Link(BasedSequence.NULL, linkText, BasedSequence.NULL, BasedSequence.NULL, linkAddress, BasedSequence.NULL);
75-
7676
linkNode.setCharsFromContent();
77+
7778
linkNode.appendChild(contentNode);
7879
textBase.appendChild(linkNode);
7980
state.nodeAddedWithChildren(linkNode);
@@ -118,12 +119,13 @@ public Document processDocument(@NotNull Document document) {
118119
// here you can append some markdown text but keep it based on original input by
119120
// using PrefixedSubSequence with only prefix without any characters from input string
120121

121-
// here we create a based sequence of "inserted" text with offset set to end of input string
122-
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()));
123-
124122
// parse using the same options as the document but remove the SyntheticLinkExtension to prevent infinite recursion
125123
MutableDataHolder options = Parser.removeExtensions(new MutableDataSet(document), SyntheticLinkExtension.class);
126-
Node insertedDocument = Parser.builder(options).build().parse(insertedText);
124+
125+
// here we create a based sequence of "inserted" text with offset set to end of input string
126+
String insertedText = "Some inserted text with a link [flexmark-java](https://github.com/vsch/flexmark-java) in paragraph.";
127+
128+
Node insertedDocument = Parser.builder(options).build().parse(document.getChars().append(insertedText).toString());
127129

128130
// now can append nodes from inserted to document
129131
document.takeChildren(insertedDocument);
@@ -184,5 +186,8 @@ public static void main(String[] args) {
184186
Node document = parser.parse("Some markdown content");
185187
String html = renderer.render(document);
186188
System.out.println(html);
189+
190+
String markdown = Formatter.builder(options).build().render(document);
191+
System.out.println(markdown);
187192
}
188193
}

0 commit comments

Comments
 (0)