Pegdown Custom ParserPlugin绑定失败

时间:2014-10-12 11:53:39

标签: java reflection parboiled

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

CustomPlugin:

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 ***************
...

Pegdown用法:

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一起使用。
  3. 我在讨论Here时发现了问题,但我太新手不能单独处理Maven插件和思考。

1 个答案:

答案 0 :(得分:0)

唯一的解决方案是等待This Issue关闭,直到我认为Pegdown和Java 8没有运气。