com.vladsch.flexmark.ext.tables.TablesExtension Java Examples

The following examples show how to use com.vladsch.flexmark.ext.tables.TablesExtension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MarkdownEditerController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
protected void makeConverter() {
    try {
        parserOptions = new MutableDataSet();
        parserOptions.setFrom(ParserEmulationProfile.valueOf(emulationSelector.getValue()));
        parserOptions.set(Parser.EXTENSIONS, Arrays.asList(
                //                    AbbreviationExtension.create(),
                //                    DefinitionExtension.create(),
                //                    FootnoteExtension.create(),
                //                    TypographicExtension.create(),
                TablesExtension.create()
        ));
        parserOptions.set(HtmlRenderer.INDENT_SIZE, indentSize)
                //                    .set(HtmlRenderer.PERCENT_ENCODE_URLS, true)
                //                    .set(TablesExtension.COLUMN_SPANS, false)
                .set(TablesExtension.TRIM_CELL_WHITESPACE, trimCheck.isSelected())
                .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected())
                .set(TablesExtension.DISCARD_EXTRA_COLUMNS, discardCheck.isSelected())
                .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected());

        parser = Parser.builder(parserOptions).build();
        renderer = HtmlRenderer.builder(parserOptions).build();

    } catch (Exception e) {
        logger.error(e.toString());
    }
}
 
Example #2
Source File: MarkDownUtil.java    From smart-doc with Apache License 2.0 5 votes vote down vote up
/**
 * Convert markdown to html.
 *
 * @param content markdown contents
 * @return html contents
 */
public static String toHtml(String content) {
    MutableDataSet options = new MutableDataSet();
    options.setFrom(ParserEmulationProfile.MARKDOWN);
    // enable table parse!
    options.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), StrikethroughExtension.create()));

    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();

    Node document = parser.parse(content);
    return renderer.render(document);
}
 
Example #3
Source File: Markdown2HtmlUtil.java    From plumemo with Apache License 2.0 5 votes vote down vote up
/**
 * Markdownz转为Html
 * @param content
 * @return
 */
public static String html(String content){

    MutableDataSet options = new MutableDataSet();
    options.setFrom(ParserEmulationProfile.MARKDOWN);
    options.set(Parser.EXTENSIONS, Arrays.asList(new Extension[]{TablesExtension.create()}));
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();
    Node document = parser.parse(content);

    return renderer.render(document);
}
 
Example #4
Source File: MarkdownToHtmlController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
@Override
public boolean makeMoreParameters() {
    try {
        parserOptions = new MutableDataSet();
        parserOptions.setFrom(ParserEmulationProfile.valueOf(emulationSelector.getValue()));
        parserOptions.set(Parser.EXTENSIONS, Arrays.asList(
                //                    AbbreviationExtension.create(),
                //                    DefinitionExtension.create(),
                //                    FootnoteExtension.create(),
                //                    TypographicExtension.create(),
                TablesExtension.create()
        ));
        parserOptions.set(HtmlRenderer.INDENT_SIZE, indentSize)
                //                    .set(HtmlRenderer.PERCENT_ENCODE_URLS, true)
                //                    .set(TablesExtension.COLUMN_SPANS, false)
                .set(TablesExtension.TRIM_CELL_WHITESPACE, trimCheck.isSelected())
                .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected())
                .set(TablesExtension.DISCARD_EXTRA_COLUMNS, discardCheck.isSelected())
                .set(TablesExtension.APPEND_MISSING_COLUMNS, appendCheck.isSelected());

        parser = Parser.builder(parserOptions).build();
        renderer = HtmlRenderer.builder(parserOptions).build();
    } catch (Exception e) {
        logger.error(e.toString());
        return false;
    }

    return super.makeMoreParameters();
}
 
Example #5
Source File: DefaultMarkdownManager.java    From onedev with MIT License 5 votes vote down vote up
@Override
public String render(String markdown) {
	List<Extension> extensions = new ArrayList<>();
	extensions.add(AnchorLinkExtension.create());
	extensions.add(TablesExtension.create());
	extensions.add(TaskListExtension.create());
	extensions.add(DefinitionExtension.create());
	extensions.add(TocExtension.create());
	extensions.add(AutolinkExtension.create());
	extensions.addAll(contributedExtensions);

	MutableDataHolder options = new MutableDataSet()
			.set(HtmlRenderer.GENERATE_HEADER_ID, true)
			.set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true)
			.set(AnchorLinkExtension.ANCHORLINKS_WRAP_TEXT, false)
			.set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "<span class='header-anchor'></span>")
			.set(Parser.SPACE_IN_LINK_URLS, true)
			.setFrom(ParserEmulationProfile.GITHUB_DOC)
			.set(TablesExtension.COLUMN_SPANS, false)
			.set(TablesExtension.APPEND_MISSING_COLUMNS, true)
			.set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
			.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true)
			.set(Parser.EXTENSIONS, extensions);

	Parser parser = Parser.builder(options).build();

	HtmlRenderer htmlRenderer = HtmlRenderer.builder(options).build();
	
	Node document = parser.parse(markdown);
	return htmlRenderer.render(document);
}
 
Example #6
Source File: FlexmarkParser.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public FlexmarkParser() {
  MutableDataSet options = new MutableDataSet();
  options.set(Parser.EXTENSIONS, Arrays.asList(StrikethroughExtension.create(),
      TablesExtension.create(),
      UMLExtension.create(),
      AutolinkExtension.create(),
      WikiLinkExtension.create(),
      TypographicExtension.create()));
  options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");
  parser = Parser.builder(options).build();
  renderer = HtmlRenderer.builder(options).build();
}
 
Example #7
Source File: Utils.java    From para with Apache License 2.0 5 votes vote down vote up
private static MutableDataHolder getMarkdownOptions() {
	return new MutableDataSet()
			.set(HtmlRenderer.ESCAPE_HTML, true)
			.set(EmojiExtension.USE_IMAGE_TYPE, EmojiImageType.UNICODE_FALLBACK_TO_IMAGE)
			// for full GFM table compatibility add the following table extension options:
			.set(TablesExtension.COLUMN_SPANS, false)
			.set(TablesExtension.APPEND_MISSING_COLUMNS, true)
			.set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
			.set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true)
			.set(Parser.EXTENSIONS, Arrays.asList(TablesExtension.create(), EmojiExtension.create(),
					StrikethroughExtension.create(), TaskListExtension.create()));
}
 
Example #8
Source File: MarkDownModel.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private List<Extension> createExtensions() {
    List<Extension> extensions = new LinkedList<>();
    extensions.add(TablesExtension.create());
    extensions.add(StrikethroughExtension.create());
    extensions.add(EmojiExtension.create());
    return extensions;
}
 
Example #9
Source File: DataRequirementsProvider.java    From cqf-ruler with Apache License 2.0 4 votes vote down vote up
private CqfMeasure processMarkDown(CqfMeasure measure) {

        MutableDataSet options = new MutableDataSet();

        options.setFrom(ParserEmulationProfile.GITHUB_DOC);
        options.set(Parser.EXTENSIONS, Arrays.asList(
                AutolinkExtension.create(),
                //AnchorLinkExtension.create(),
                //EmojiExtension.create(),
                StrikethroughExtension.create(),
                TablesExtension.create(),
                TaskListExtension.create()
        ));

        // uncomment and define location of emoji images from https://github.com/arvida/emoji-cheat-sheet.com
        // options.set(EmojiExtension.ROOT_IMAGE_PATH, "");

        // Uncomment if GFM anchor links are desired in headings
        // options.set(AnchorLinkExtension.ANCHORLINKS_SET_ID, false);
        // options.set(AnchorLinkExtension.ANCHORLINKS_ANCHOR_CLASS, "anchor");
        // options.set(AnchorLinkExtension.ANCHORLINKS_SET_NAME, true);
        // options.set(AnchorLinkExtension.ANCHORLINKS_TEXT_PREFIX, "<span class=\"octicon octicon-link\"></span>");

        // References compatibility
        options.set(Parser.REFERENCES_KEEP, KeepType.LAST);

        // Set GFM table parsing options
        options.set(TablesExtension.COLUMN_SPANS, false)
                .set(TablesExtension.MIN_HEADER_ROWS, 1)
                .set(TablesExtension.MAX_HEADER_ROWS, 1)
                .set(TablesExtension.APPEND_MISSING_COLUMNS, true)
                .set(TablesExtension.DISCARD_EXTRA_COLUMNS, true)
                .set(TablesExtension.WITH_CAPTION, false)
                .set(TablesExtension.HEADER_SEPARATOR_COLUMN_MATCH, true);

        // Setup List Options for GitHub profile which is kramdown for documents
        options.setFrom(ParserEmulationProfile.GITHUB_DOC);

        options.set(HtmlRenderer.SOFT_BREAK, "<br />\n");


        Parser parser = Parser.builder(options).build();
        HtmlRenderer renderer = HtmlRenderer.builder(options).build();

        measure.setDescription(markdownToHtml(parser, renderer, measure.getDescription()));
        measure.setPurpose(markdownToHtml(parser, renderer, measure.getPurpose()));
        // measure.setCopyright(markdownToHtml(parser, renderer, measure.getCopyright()));
        measure.setRationale(markdownToHtml(parser, renderer, measure.getRationale()));
        measure.setClinicalRecommendationStatement(markdownToHtml(parser, renderer, measure.getClinicalRecommendationStatement()));
        measure.setGuidance(markdownToHtml(parser, renderer, measure.getGuidance()));

        measure.setDefinition(measure.getDefinition().stream()
            .map(x -> markdownToHtml(parser, renderer, x.getValueAsString()))
            .map(MarkdownType::new)
            .collect(Collectors.toList()));

        return measure;
    }
 
Example #10
Source File: PMarkdownOptions.java    From jphp with Apache License 2.0 4 votes vote down vote up
@Signature
public PMarkdownOptions addTableExtension() {
    parserExtensions.add(TablesExtension.create());
    return this;
}