com.vladsch.flexmark.html.AttributeProvider Java Examples

The following examples show how to use com.vladsch.flexmark.html.AttributeProvider. 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: MarkdownParser.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected String doInBackground(String... strings) {
    Parser parser = Parser.builder(OPTIONS)
            .extensions(EXTENSIONS)
            .build();

    HtmlRenderer renderer = HtmlRenderer.builder(OPTIONS)
            .escapeHtml(true)
            .attributeProviderFactory(new IndependentAttributeProviderFactory() {
                @Override
                public AttributeProvider create(NodeRendererContext context) {
                    return new CustomAttributeProvider();
                }
            })
            .nodeRendererFactory(new NodeRendererFactoryImpl())
            .extensions(EXTENSIONS)
            .build();

    return renderer.render(parser.parse(strings[0]));
}
 
Example #2
Source File: MarkdownView.java    From MarkdownView with Apache License 2.0 6 votes vote down vote up
private String parseBuildAndRender(String text) {
    Parser parser = Parser.builder(OPTIONS)
            .extensions(EXTENSIONS)
            .build();

    HtmlRenderer renderer = HtmlRenderer.builder(OPTIONS)
            .escapeHtml(mEscapeHtml)
            .attributeProviderFactory(new IndependentAttributeProviderFactory() {
                @Override
                public AttributeProvider create(NodeRendererContext context) {
                    return new CustomAttributeProvider();
                }
            })
            .nodeRendererFactory(new NodeRendererFactoryImpl())
            .extensions(EXTENSIONS)
            .build();

    return renderer.render(parser.parse(text));
}
 
Example #3
Source File: SourcePositionTrackExtension.java    From onedev with MIT License 4 votes vote down vote up
@Override
public void extend(Builder rendererBuilder, String rendererType) {
	rendererBuilder.attributeProviderFactory(new IndependentAttributeProviderFactory() {
		
		@Override
		public AttributeProvider create(NodeRendererContext context) {
			return new AttributeProvider() {

				@Override
				public void setAttributes(Node node, AttributablePart part, Attributes attributes) {
					if (node instanceof Block) {
						int startOffset = node.getStartOffset();
						int endOffset = node.getEndOffset();
						Node document = node.getDocument();
						if (document != null) {
							int leadingWhitespaces = 0;
							for (int i=startOffset; i<endOffset; i++) {
								if (Character.isWhitespace(document.getChars().charAt(i))) {
									leadingWhitespaces++;
								} else {
									break;
								}
							}
							int trailingWhitespaces = 0;
							for (int i=endOffset-1; i>=startOffset; i--) {
								if (Character.isWhitespace(document.getChars().charAt(i))) {
									trailingWhitespaces++;
								} else {
									break;
								}
							}
							attributes.addValue("data-" + DATA_START_ATTRIBUTE, String.valueOf(startOffset+leadingWhitespaces));
							attributes.addValue("data-" + DATA_END_ATTRIBUTE, String.valueOf(endOffset-trailingWhitespaces));
						}
					}
				}
				
			};
		}
	});
}
 
Example #4
Source File: FlexmarkPreviewRenderer.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public AttributeProvider create(LinkResolverContext context) {
	return new MyAttributeProvider();
}
 
Example #5
Source File: FlexmarkAttributeProvider.java    From markdown-page-generator-plugin with MIT License 4 votes vote down vote up
@Override
public AttributeProvider apply(LinkResolverContext context) {
    return new FlexmarkAttributeProvider(context);
}