use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.
the class ComboAppHtmlAttributeParserTest method assertRendering.
// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
String parseSource = expectedHtml;
if (options != null && options.get(NO_FILE_EOL)) {
parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
}
Node node = parser().withOptions(options).parse(parseSource);
String renderedResult = renderer().withOptions(options).render(node);
String expectedResult = source;
actualSource(renderedResult, optionsSet);
boolean useActualHtml = useActualHtml();
// include source for better assertion errors
String expected;
String actual;
if (example() != null && example().getSection() != null) {
StringBuilder outExpected = new StringBuilder();
DumpSpecReader.addSpecExample(outExpected, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
expected = outExpected.toString();
StringBuilder outActual = new StringBuilder();
DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
actual = outActual.toString();
} else {
expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet);
}
specExample(expected, actual, optionsSet);
if (options != null && options.get(FAIL)) {
thrown.expect(ComparisonFailure.class);
}
assertEquals(expected, actual);
}
use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.
the class ComboHtmlAttributeParserIssueTest method assertRendering.
// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
String parseSource = expectedHtml;
if (options != null && options.get(NO_FILE_EOL)) {
parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
}
Node node = parser().withOptions(options).parse(parseSource);
String renderedResult = renderer().withOptions(options).render(node);
String expectedResult = source;
actualSource(renderedResult, optionsSet);
boolean useActualHtml = useActualHtml();
// include source for better assertion errors
String expected;
String actual;
if (example() != null && example().getSection() != null) {
StringBuilder outExpected = new StringBuilder();
DumpSpecReader.addSpecExample(outExpected, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
expected = outExpected.toString();
StringBuilder outActual = new StringBuilder();
DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
actual = outActual.toString();
} else {
expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet);
}
specExample(expected, actual, optionsSet);
if (options != null && options.get(FAIL)) {
thrown.expect(ComparisonFailure.class);
}
assertEquals(expected, actual);
}
use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.
the class ComboHtmlParserIssueTest method assertRendering.
// reverse source and html
@Override
protected void assertRendering(String source, String expectedHtml, String optionsSet) {
DataHolder options = optionsSet == null ? null : getOptions(example(), optionsSet);
String parseSource = expectedHtml;
if (options != null && options.get(NO_FILE_EOL)) {
parseSource = DumpSpecReader.trimTrailingEOL(parseSource);
}
Node node = parser().withOptions(options).parse(parseSource);
String renderedResult = renderer().withOptions(options).render(node);
String expectedResult = source;
actualSource(renderedResult, optionsSet);
boolean useActualHtml = useActualHtml();
// include source for better assertion errors
String expected;
String actual;
if (example() != null && example().getSection() != null) {
StringBuilder outExpected = new StringBuilder();
DumpSpecReader.addSpecExample(outExpected, expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
expected = outExpected.toString();
StringBuilder outActual = new StringBuilder();
DumpSpecReader.addSpecExample(outActual, useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet, true, example().getSection(), example().getExampleNumber());
actual = outActual.toString();
} else {
expected = DumpSpecReader.addSpecExample(expectedResult, expectedHtml, "", optionsSet);
actual = DumpSpecReader.addSpecExample(useActualHtml ? renderedResult : expectedResult, expectedHtml, "", optionsSet);
}
specExample(expected, actual, optionsSet);
if (options != null && options.get(FAIL)) {
thrown.expect(ComparisonFailure.class);
}
assertEquals(expected, actual);
}
use of com.vladsch.flexmark.util.options.DataHolder in project flexmark-java by vsch.
the class CustomContextDataSample method main.
public static void main(String[] args) {
final DataHolder options = PegdownOptionsAdapter.flexmarkOptions(Extensions.ALL, CustomExtension.create());
Parser parser = Parser.builder(options).build();
HtmlRenderer renderer = HtmlRenderer.builder(options).build();
String markdown = "";
XhtmlContent xhtmlContent = null;
// You can re-use parser and renderer instances
Document document = (Document) parser.parse(markdown);
document.set(XHTML_CONTENT, xhtmlContent);
// "<p>This is <em>Sparta</em></p>\n"
String html = renderer.render(document);
System.out.println(html);
}
use of com.vladsch.flexmark.util.options.DataHolder 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);
}
Aggregations