use of com.vladsch.flexmark.util.options.MutableDataSet in project flexmark-java by vsch.
the class SyntheticLinkFormatterSample method main.
public static void main(String[] args) {
MutableDataSet options = new MutableDataSet();
// set optional extensions
options.set(Parser.EXTENSIONS, Arrays.asList(SyntheticLinkExtension.create()));
// uncomment to convert soft-breaks to hard breaks
// options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Formatter formatter = Formatter.builder(options).build();
// You can re-use parser and renderer instances
Node document = parser.parse("Some markdown content");
String markdown = formatter.render(document);
System.out.println(markdown);
}
use of com.vladsch.flexmark.util.options.MutableDataSet in project flexmark-java by vsch.
the class TextCollectingVisitorTest method test_basic.
@Test
public void test_basic() {
DataHolder options = new MutableDataSet().set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create()));
Parser parser = Parser.builder(options).build();
String markdown = "| First Header | Second Header |\n" + "| ------------- | ------------- |\n" + "| Content Cell | Content Cell |\n" + "\n" + "| Left-aligned | Center-aligned | Right-aligned |\n" + "| :--- | :---: | ---: |\n" + "| git status | git status | git status |\n" + "| git diff | git diff | git diff |\n" + "";
Node document = parser.parse(markdown);
TextCollectingVisitor collectingVisitor = new TextCollectingVisitor();
final String text = collectingVisitor.collectAndGetText(document);
System.out.println(text);
final String astText = new AstCollectingVisitor().collectAndGetAstText(document);
System.out.println(astText);
}
use of com.vladsch.flexmark.util.options.MutableDataSet in project flexmark-java by vsch.
the class RenderingTestCase method getOptions.
/**
* process comma separated list of option sets and combine them for final set to use
*
* @param example spec example instance for which options are being processed
* @param optionSets comma separate list of option set names
* @return combined set from applying these options together
*/
public DataHolder getOptions(SpecExample example, String optionSets) {
if (optionSets == null)
return null;
String[] optionNames = optionSets.replace('\u00A0', ' ').split(",");
DataHolder options = null;
boolean isFirst = true;
for (String optionName : optionNames) {
String option = optionName.trim();
if (option.isEmpty() || option.startsWith("-"))
continue;
if (option.equals(IGNORE_OPTION_NAME)) {
// noinspection ConstantConditions
throwIgnoredOption(example, optionSets, option);
} else if (option.equals(FAIL_OPTION_NAME)) {
if (options == null) {
options = new MutableDataSet().set(FAIL, true);
} else {
options = new MutableDataSet(options).set(FAIL, true);
}
} else if (option.equals(NO_FILE_EOL_OPTION_NAME)) {
if (options == null) {
options = new MutableDataSet().set(NO_FILE_EOL, true);
} else {
options = new MutableDataSet(options).set(NO_FILE_EOL, true);
}
} else if (option.equals(FILE_EOL_OPTION_NAME)) {
if (options == null) {
options = new MutableDataSet().set(NO_FILE_EOL, false);
} else {
options = new MutableDataSet(options).set(NO_FILE_EOL, true);
}
} else {
if (options == null) {
options = options(option);
if (options == null) {
throw new IllegalStateException("Option " + option + " is not implemented in the RenderingTestCase subclass");
}
} else {
DataHolder dataSet = options(option);
if (dataSet != null) {
if (isFirst) {
options = new MutableDataSet(options);
isFirst = false;
}
((MutableDataSet) options).setAll(dataSet);
} else {
throw new IllegalStateException("Option " + option + " is not implemented in the RenderingTestCase subclass");
}
}
if (IGNORE.getFrom(options)) {
// noinspection ConstantConditions
throwIgnoredOption(example, optionSets, option);
}
}
}
return options;
}
use of com.vladsch.flexmark.util.options.MutableDataSet in project flexmark-java by vsch.
the class ParserTest method indentationWithLines.
@Test
public void indentationWithLines() {
String given = " - 1 space\n - 3 spaces\n - 5 spaces\n\t - tab + space";
MutableDataHolder options = new MutableDataSet().set(Parser.TRACK_DOCUMENT_LINES, true);
Parser parser = Parser.builder(options).build();
Document document = parser.parse(given);
assertThat(document.getFirstChild(), instanceOf(BulletList.class));
assertEquals("Document line count", 4, document.getLineCount());
// first level list
Node list = document.getFirstChild();
assertEquals("expect one child", list.getFirstChild(), list.getLastChild());
assertEquals("1 space", firstText(list.getFirstChild()));
assertEquals("node start line number", 0, list.getStartLineNumber());
assertEquals("node end line number", 3, list.getEndLineNumber());
// second level list
list = list.getFirstChild().getLastChild();
assertEquals("expect one child", list.getFirstChild(), list.getLastChild());
assertEquals("3 spaces", firstText(list.getFirstChild()));
assertEquals("node start line number", 1, list.getStartLineNumber());
assertEquals("node end line number", 3, list.getEndLineNumber());
// third level list
list = list.getFirstChild().getLastChild();
assertEquals("5 spaces", firstText(list.getFirstChild()));
assertEquals("tab + space", firstText(list.getFirstChild().getNext()));
assertEquals("node start line number", 2, list.getStartLineNumber());
assertEquals("node end line number", 3, list.getEndLineNumber());
}
use of com.vladsch.flexmark.util.options.MutableDataSet in project nzbhydra2 by theotherp.
the class Markdown method renderMarkdownAsHtml.
public static String renderMarkdownAsHtml(String markdown) {
MutableDataSet options = new MutableDataSet();
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
Node document = parser.parse(markdown);
return renderer.render(document);
}
Aggregations