sirthias / pegdown

A pure-Java Markdown processor based on a parboiled PEG parser supporting a number of extensions
http://pegdown.org
Apache License 2.0
1.29k stars 218 forks source link

Parser can't be subclassed outside of org.pegdown package #54

Open blizzy78 opened 12 years ago

blizzy78 commented 12 years ago

(This has been discussed in #28, but the solution from commit 07dda00be3a49166f5714b4e01d7204b88c5869f is incomplete.)

Subclassing Parser does only work if the subclass resides in the same package as Parser, that is, org.pegdown. The MyParser subclass introduced in commit 07dda00be3a49166f5714b4e01d7204b88c5869f is inside that package. Relocating it to any other package results in an IllegalAccessError.

atomicleopard commented 10 years ago

I've also run into this issue - I wanted to redefine the list of html tags which are considered block level elements, found in Parser#HTML_TAGS. I tried to override the Parser#isHtmlTag method, but found this caused a runtime exception unless my Parser was in the org.pegdown package.

Caused by: java.lang.IllegalAccessError: tried to access class org.pegdown.Parser$4 from class com.pkg.PegdownCustomisedParser$$parboiled
at com.pkg.PegdownCustomisedParser$$parboiled.OrderedList(Unknown Source)
at com.pkg.PegdownCustomisedParser$$parboiled.Block(Unknown Source)
at com.pkg.PegdownCustomisedParser$$parboiled.Root(Unknown Source)
at org.pegdown.Parser.parseToParsingResult(Parser.java:1487)
at org.pegdown.Parser.parseInternal(Parser.java:1474)
at org.pegdown.Parser.parse(Parser.java:85)
at org.pegdown.PegDownProcessor.parseMarkdown(PegDownProcessor.java:171)
at org.pegdown.PegDownProcessor.markdownToHtml(PegDownProcessor.java:156)
at org.pegdown.PegDownProcessor.markdownToHtml(PegDownProcessor.java:151)
at org.pegdown.PegDownProcessor.markdownToHtml(PegDownProcessor.java:139)
at org.pegdown.PegDownProcessor.markdownToHtml(PegDownProcessor.java:112)
jirutka commented 10 years ago

I’ve discovered a workaround for situations when we need to override some of the top inline or block rules. It’s not possible to simply override the rule, but what we actually can do is to “hide” the rule. Let me explain it with example: https://gist.github.com/jirutka/6429757.