本文整理了Java中org.commonmark.parser.Parser.builder()
方法的一些代码示例,展示了Parser.builder()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.builder()
方法的具体详情如下:
包路径:org.commonmark.parser.Parser
类名称:Parser
方法名:builder
[英]Create a new builder for configuring a Parser.
[中]创建用于配置解析器的新生成器。
代码示例来源:origin: ZHENFENG13/My-Blog
/**
* markdown转换为html
*
* @param markdown
* @return
*/
public static String mdToHtml(String markdown) {
if (StringUtils.isBlank(markdown)) {
return "";
}
java.util.List<Extension> extensions = Arrays.asList(TablesExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
String content = renderer.render(document);
content = Commons.emoji(content);
return content;
}
代码示例来源:origin: jamesagnew/hapi-fhir
public Cell addMarkdown(String md) {
try {
Parser parser = Parser.builder().build();
Node document = parser.parse(md);
HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
String html = renderer.render(document);
pieces.addAll(htmlToParagraphPieces(html));
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
private List<Piece> htmlToParagraphPieces(String html) throws IOException, FHIRException {
代码示例来源:origin: nice-swa/my-site
/**
* markdown转换为html
*
* @param markdown
* @return
*/
public static String mdToHtml(String markdown) {
if (StringUtils.isBlank(markdown)) {
return "";
}
java.util.List<Extension> extensions = Arrays.asList(TablesExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
String content = renderer.render(document);
content = Commons.emoji(content);
return content;
}
代码示例来源:origin: tomoya92/pybbs
public static String render(String content) {
List<Extension> extensions = Arrays.asList(
AutolinkExtension.create(),
TablesExtension.create());
Parser parser = Parser.builder()
.extensions(extensions)
.build();
// 回车一次就可以实现换行
HtmlRenderer renderer = HtmlRenderer.builder()
.softbreak("<br/>")
.attributeProviderFactory(context -> new MyAttributeProvider())
.extensions(extensions)
.build();
Node document = parser.parse(content == null ? "" : content);
return renderer.render(document);
}
代码示例来源:origin: synchrony/smsn
private Document parseToMarkdownDocument(final InputStream input) throws IOException {
Parser parser = Parser.builder().build();
Node document = parser.parseReader(new InputStreamReader(input));
return (Document) document;
}
代码示例来源:origin: gsvigruha/cosyan
private static void markdownToHtml(String resourcesDir) throws IOException {
File docRoot = new File(resourcesDir + File.separator + "doc");
Collection<File> files = FileUtils.listFiles(docRoot, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE).stream()
.sorted((f1, f2) -> f1.getName().compareTo(f2.getName())).collect(Collectors.toList());
JSONArray items = new JSONArray();
String webRoot = "web" + File.separator + "app" + File.separator + "help";
for (File markdown : files) {
Parser parser = Parser.builder().build();
Node document = parser.parse(FileUtils.readFileToString(markdown, Charset.defaultCharset()));
HtmlRenderer renderer = HtmlRenderer.builder().build();
String suffix = markdown.getAbsolutePath().substring(docRoot.getAbsolutePath().length() + 1, markdown.getAbsolutePath().length() - 3);
File html = new File(webRoot + File.separator + suffix + ".html");
FileUtils.writeStringToFile(html, renderer.render(document), Charset.defaultCharset());
JSONObject object = new JSONObject();
object.put("url", suffix);
object.put("title", ((Text) document.getFirstChild().getFirstChild()).getLiteral());
items.put(object);
}
FileUtils.writeStringToFile(new File(webRoot + File.separator + "list"), items.toString(), Charset.defaultCharset());
}
代码示例来源:origin: aint/laverna-android
/**
* A method which returns Parser which parses input text to a tree of nodes.
* @return a Parser object.
*/
private Parser getParser() {
return Parser.builder()
.extensions(getExtensions())
.build();
}
代码示例来源:origin: g00glen00b/spring-samples
@PostConstruct
public void initialize() {
List<Extension> extensions = Collections.singletonList(TablesExtension.create());
parser = Parser.builder().extensions(extensions).build();
htmlRenderer = HtmlRenderer.builder().extensions(extensions).build();
}
代码示例来源:origin: ca.uhn.hapi.fhir/hapi-fhir-utilities
public Cell addMarkdown(String md) {
try {
Parser parser = Parser.builder().build();
Node document = parser.parse(md);
HtmlRenderer renderer = HtmlRenderer.builder().escapeHtml(true).build();
String html = renderer.render(document);
pieces.addAll(htmlToParagraphPieces(html));
} catch (Exception e) {
e.printStackTrace();
}
return this;
}
private List<Piece> htmlToParagraphPieces(String html) throws IOException, FHIRException {
代码示例来源:origin: com.xmlcalabash/xmlcalabash
public void load(URI id, String media, InputStream content, long len) throws IOException {
Reader rdr = new InputStreamReader(content);
Parser parser = Parser.builder().build();
Node document = parser.parseReader(rdr);
HtmlRenderer renderer = HtmlRenderer.builder().build();
// We rely on the fact that the CommonMark parser returns well-formed markup consisting
// of the paragraphs and other bits that would occur inside a <body> element and
// that it returns them with no namespace declarations.
String markup = "<body xmlns='http://www.w3.org/1999/xhtml'>" + renderer.render(document) + "</body>";
XdmNode parsed = runtime.parse(new InputSource(new StringReader(markup)));
// Let's craft a baseURI for the document...
String path = id.getPath();
int lastSlash = path.lastIndexOf("/");
String base = path.substring(0, lastSlash+1);
String filename = path.substring(lastSlash+1);
int lastDot = filename.lastIndexOf(".");
if (lastDot > 0) {
base = base + filename.substring(0, lastDot) + ".html";
} else {
base = base + filename + ".html";
}
URI baseURI = id.resolve(base);
TreeWriter tree = new TreeWriter(runtime);
tree.startDocument(baseURI);
tree.addSubtree(parsed);
tree.endDocument();
result.write(tree.getResult());
}
});
代码示例来源:origin: protegeproject/webprotege
TablesExtension.create(),
InsExtension.create());
Parser parser = Parser.builder()
.extensions(extensions)
.build();
代码示例来源:origin: 94fzb/zrlog
public static String renderMd(String md) {
Parser parser = Parser.builder().build();
Node document = parser.parse(md);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
代码示例来源:origin: org.opensingular/singular-form-wicket
private static String renderMarkdown(String message) {
Parser parser = Parser.builder().build();
Node node = parser.parse(message);
return HtmlRenderer.builder().build().render(node);
}
}
代码示例来源:origin: xiancloud/xian
/**
* @param md the markdown string.
* @return converted html
*/
public static String mdToHtml(String md) {
Parser parser = Parser.builder().build();
Node document = parser.parse(md);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
}
}
代码示例来源:origin: tfssweb/tale
/**
* markdown转换为html
*
* @param markdown
* @return
*/
public static String mdToHtml(String markdown) {
if (StringKit.isBlank(markdown)) {
return "";
}
List<Extension> extensions = Arrays.asList(TablesExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder().extensions(extensions).build();
String content = renderer.render(document);
content = Commons.emoji(content);
// 支持网易云音乐输出
if (TaleConst.BCONF.getBoolean("app.support_163_music", true) && content.contains("[mp3:")) {
content = content.replaceAll("\\[mp3:(\\d+)\\]", "<iframe frameborder=\"no\" border=\"0\" marginwidth=\"0\" marginheight=\"0\" width=350 height=106 src=\"//music.163.com/outchain/player?type=2&id=$1&auto=0&height=88\"></iframe>");
}
// 支持gist代码输出
if (TaleConst.BCONF.getBoolean("app.support_gist", true) && content.contains("https://gist.github.com/")) {
content = content.replaceAll("<script src=\"https://gist.github.com/(\\w+)/(\\w+)\\.js\"></script>", "<script src=\"https://gist.github.com/$1/$2\\.js\"></script>");
}
return content;
}
代码示例来源:origin: JayTange/Jantent
/**
* markdown转换为html
*
* @param markdown
* @return
*/
public static String mdToHtml(String markdown) {
if (StringUtils.isBlank(markdown)) {
return "";
}
List<Extension> extensions = Arrays.asList(TablesExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
Node document = parser.parse(markdown);
HtmlRenderer renderer = HtmlRenderer.builder()
.attributeProviderFactory(context -> new LinkAttributeProvider())
.extensions(extensions).build();
String content = renderer.render(document);
content = Commons.emoji(content);
return content;
}
代码示例来源:origin: com.github.nic-luo/rober-sql
private List<SQLTextItem> parseText(String text){
List<SQLTextItem> textList = new ArrayList<SQLTextItem>();
Parser parser = Parser.builder().build();
Node node = parser.parse(text);
代码示例来源:origin: synchrony/smsn
@Test
public void commonMarkParsesSimpleMarkdown() {
Parser parser = Parser.builder().build();
Node document = parser.parse("This is *Sparta*");
HtmlRenderer renderer = HtmlRenderer.builder().build();
String doc = renderer.render(document);
assertEquals("<p>This is <em>Sparta</em></p>\n", doc);
}
内容来源于网络,如有侵权,请联系作者删除!