本文整理汇总了Java中org.pegdown.VerbatimSerializer类的典型用法代码示例。如果您正苦于以下问题:Java VerbatimSerializer类的具体用法?Java VerbatimSerializer怎么用?Java VerbatimSerializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
VerbatimSerializer类属于org.pegdown包,在下文中一共展示了VerbatimSerializer类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: markdownToHtml
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
/**
* Convert Markdown into HTML (just the body content) with inline styles
*
* @param markdown Markdown to convert into HTML
* @return String containing HTML (just the body content)
* @throws MarkdownException
*/
String markdownToHtml(String markdown) throws MarkdownException {
Map<String, VerbatimSerializer> verbatimSerializers = new HashMap<>();
verbatimSerializers.put(MyCustomVerbatimSerializer.DEFAULT, MyCustomVerbatimSerializer.INSTANCE);
String htmlBody = processor.markdownToHtml(markdown.toCharArray(), new LinkRenderer(), verbatimSerializers);
LOG.debug("Body before styles: {}",htmlBody);
String htmlWithStyleInline = "";
try {
htmlWithStyleInline = new HtmlStyleSheetInliner().inlineStyleSheet(htmlBody, styleSheet);
} catch (SAXException | IOException | TransformerException e) {
e.printStackTrace();
throw new MarkdownException("Could not turn Markdown to HTML");
}
LOG.debug("Body after styles: {}",htmlWithStyleInline);
return htmlWithStyleInline;
}
示例2: renderToHtml
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
@Override
public String renderToHtml(String markdownSource) {
// synchronizing on pegdown instance since neither the processor nor the underlying parser is thread-safe.
synchronized (pegdown) {
RootNode astRoot = pegdown.parseMarkdown(markdownSource.toCharArray());
MarkdownToHtmlSerializer serializer = new MarkdownToHtmlSerializer(new LinkRenderer(),
Collections.singletonMap(VerbatimSerializer.DEFAULT, PrettifyVerbatimSerializer.INSTANCE));
return serializer.toHtml(astRoot);
}
}
示例3: markdownToHtml
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
@Override
public String markdownToHtml(char[] markdownSource,
LinkRenderer linkRenderer,
Map<String, VerbatimSerializer> verbatimSerializerMap) {
try {
RootNode astRoot = parseMarkdown(markdownSource);
return new ToHtmlNoLinkSerializer(linkRenderer,
verbatimSerializerMap).toHtml(astRoot);
} catch (ParsingTimeoutException e) {
return null;
}
}
示例4: toHtml
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
@Override
public String toHtml(String source) {
try {
Map<String, VerbatimSerializer> serializers = new HashMap<>();
PlantUmlVerbatimSerializer.addToMap(serializers);
LinkRenderer linkRenderer = new TypeLinkRenderer();
return processor.markdownToHtml(source, linkRenderer, serializers);
} catch (Exception e) {
LOGGER.error("Could not convert given source to markdown: {}", source, e);
return source;
}
}
示例5: addToMap
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
/**
* Register an instance of {@link PlantUmlVerbatimSerializer} in the given serializer's map.
*/
public static void addToMap(final Map<String, VerbatimSerializer> serializerMap) {
PlantUmlVerbatimSerializer serializer = new PlantUmlVerbatimSerializer();
for (Type type : Type.values()) {
String name = type.getName();
serializerMap.put(name, serializer);
}
}
示例6: markdownToHtml
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
public String markdownToHtml(char[] markdownSource, LinkRenderer linkRenderer, Map<String, VerbatimSerializer> verbatimSerializerMap) {
try {
RootNode astRoot = parseMarkdown(markdownSource);
return new NS2GToHtmlSerializer(linkRenderer, verbatimSerializerMap).toHtml(astRoot);
} catch (ParsingTimeoutException e) {
return null;
}
}
示例7: MarkdownToHtmlSerializer
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
public MarkdownToHtmlSerializer(final LinkRenderer linkRenderer, final Map<String, VerbatimSerializer> verbatimSerializers) {
super(linkRenderer, verbatimSerializers);
}
示例8: ToHtmlNoLinkSerializer
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
public ToHtmlNoLinkSerializer(LinkRenderer linkRenderer,
Map<String, VerbatimSerializer> verbatimSerializerMap) {
super(linkRenderer, verbatimSerializerMap);
}
示例9: MultiMarkdownToHtmlSerializer
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
public MultiMarkdownToHtmlSerializer(LinkRenderer linkRenderer, Map<String, VerbatimSerializer> verbatimSerializers) {
super(linkRenderer, verbatimSerializers);
project = null;
document = null;
}
示例10: NS2GToHtmlSerializer
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
public NS2GToHtmlSerializer(LinkRenderer linkRenderer, Map<String, VerbatimSerializer> verbatimSerializerMap) {
super(linkRenderer, verbatimSerializerMap);
}
示例11: exec
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException
{
if (arguments.size() != 1)
{
throw new TemplateModelException("Error, method expects one argument (String)");
}
SimpleScalar freemarkerArg = (SimpleScalar) arguments.get(0);
String markdownSource = freemarkerArg.getAsString();
SoftReference<String> cachedResult = cache.get(markdownSource);
String cachedResultString;
if (cachedResult != null && (cachedResultString = cachedResult.get()) != null)
{
return cachedResultString;
}
try
{
// build the plugins object with our extensions
PegDownPlugins plugins = PegDownPlugins.builder().build();
PegDownProcessor processor = new PegDownProcessor(Extensions.FENCED_CODE_BLOCKS, MAX_PARSING_TIME_MILLIS, plugins);
// build the node and then serialize it so that we can make sure the serializer uses our plugins
RootNode outputNode = processor.parseMarkdown(markdownSource.toCharArray());
// Our plugin is also a serializer, so build a plugins list for serialization as well
List<ToHtmlSerializerPlugin> serializerPlugins = new ArrayList<>(1);
ToHtmlSerializer serializer = new ToHtmlSerializerExtended(new LinkRenderer(), Collections.<String, VerbatimSerializer> emptyMap(),
serializerPlugins);
String result = serializer.toHtml(outputNode);
cache.put(markdownSource, new SoftReference<>(result));
return result;
}
catch (Throwable t)
{
LOG.log(Level.WARNING, "Failed to parse markdown due to: " + t.getMessage() + " markdown source: " + markdownSource, t);
// Return the unformatted markdown, as this is better than failing the report completely.
return markdownSource;
}
}
示例12: ToHtmlSerializerExtended
import org.pegdown.VerbatimSerializer; //导入依赖的package包/类
public ToHtmlSerializerExtended(LinkRenderer linkRenderer, Map<String, VerbatimSerializer> verbatimSerializers,
List<ToHtmlSerializerPlugin> plugins)
{
super(linkRenderer, verbatimSerializers, plugins);
}