0

在尝试将自定义 ParserPlugin 实现到我正在编写的库(Maven 项目,JDK 8)时,我遇到了 pegdown v1.4.2 的问题:

自定义插件:

public class CustomHeadersParserPlugin extends Parser implements BlockPluginParser {

public CustomHeadersParserPlugin() {super(HtmlMdProc.MDP_SETTINGS, HtmlMdProc.PROCESSING_TIME_LIMIT, DefaultParseRunnerProvider);
}

public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis) {
  super(options, maxParsingTimeInMillis, DefaultParseRunnerProvider);
}

public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider) {
  super(options, maxParsingTimeInMillis, parseRunnerProvider);
}

public CustomHeadersParserPlugin(Integer options, Long maxParsingTimeInMillis, ParseRunnerProvider parseRunnerProvider, PegDownPlugins plugins) {
  super(options, maxParsingTimeInMillis, parseRunnerProvider, plugins);
}

//************* CUSTOM RULES ***************
...

挂钩用法:

public class HtmlMdProc {

public static final int MDP_SETTINGS = Extensions.HARDWRAPS | Extensions.AUTOLINKS | Extensions.TABLES | Extensions.FENCED_CODE_BLOCKS;
public static final long PROCESSING_TIME_LIMIT = 5000l;
...
public HtmlMdProc markdown() {
  PegDownPlugins pdp = PegDownPlugins.builder().withPlugin(CustomHeadersParserPlugin.class).build();
  PegDownProcessor mdp = new PegDownProcessor(MDP_SETTINGS, PROCESSING_TIME_LIMIT, pdp);
  RootNode rn = mdp.parseMarkdown(text.toCharArray());
  String result = new CustomMarkdownToHtmlSerializer().toHtml(rn);
    if (result != null)
      this.text = result;
    else
      logger.debug("Could not process markdown in {} seconds", PROCESSING_TIME_LIMIT / 1000);
  return this;
}

测试:

@Test
public void testmarkdownWithoutCode() {
  String before = "Simple new line\nTest\n\nTest\nVot";
  String expected = "<p>Simple new line<br />Test</p><p>Test<br />Vot</p>".replaceAll("\r", "");
  HtmlMdProc textProc = new HtmlMdProc(before);
  String result = textProc.markdown().text();
  assertEquals(expected, result);
}

测试例外:

java.lang.RuntimeException: Error creating extended parser class: null
  at org.objectweb.asm.ClassReader.<init>(Unknown Source)
  at org.objectweb.asm.ClassReader.<init>(Unknown Source)
  at org.objectweb.asm.ClassReader.<init>(Unknown Source)
  at org.parboiled.transform.AsmUtils.createClassReader(AsmUtils.java:56)
  at org.parboiled.transform.ClassNodeInitializer.process(ClassNodeInitializer.java:62)
  at org.parboiled.transform.ParserTransformer.extendParserClass(ParserTransformer.java:44)
  at org.parboiled.transform.ParserTransformer.transformParser(ParserTransformer.java:38)
  at org.parboiled.Parboiled.createParser(Parboiled.java:54)
  at org.pegdown.plugins.PegDownPlugins$Builder.withPlugin(PegDownPlugins.java:113)
  at com.myorg.html.services.HtmlMdProc.markdown(HtmlMdProc.java:317)
  at com.myorg.html.services.HtmlMdProcTest.testmarkdownWithoutCode(HtmlMdProcTest.java:262)
  1. 我可以以某种方式绑定我的 CustomHeadersParserPlugin 以避免幽灵般的反射吗?
  2. 如果没有,请告诉我如何在 pom.xml 中设置 maven-bundle-plugin 以使其与 pegdown v 1.4.2 一起使用。

我在这里发现了讨论问题,但我太新手了,无法单独处理 Maven 插件和反射。

4

1 回答 1

0

唯一的解决方案是等待这个问题被关闭,直到我认为 Pegdown 和 Java 8 没有运气。

于 2014-12-26T15:54:58.500 回答