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 217 forks source link

STRIKETHROUGH doesn't work without FENCED_CODE_BLOCKS #131

Closed weavejester closed 9 years ago

weavejester commented 10 years ago

Curiously, the STRIKETHROUGH extension doesn't appear to work on its own in 1.4.2. It only works if the FENCED_CODE_BLOCKS extension is also active.

new PegDownProcessor(Extensions/STRIKETHROUGH)
  .markdownToHtml("~~foo~~");
// produces "<p>~~foo~~</p>"

new PegDownProcessor(Extensions/FENCED_CODE_BLOCKS)
  .markdownToHtml("~~foo~~");
// produces "<p>~~foo~~</p>"

new PegDownProcessor(Extensions/FENCED_CODE_BLOCKS + Extensions/STRIKETHROUGH)
  .markdownToHtml("~~foo~~");
// produces "<p><del>foo</del></p>"
berndv commented 10 years ago

Think there is just the addition of the "~" char to the list of special chars missing for option STRIKETHROUGH. See org.pegdown.Parser.

    public Rule SpecialChar() {
        String chars = "*_`&[]<>!#\\";
        if (ext(QUOTES)) {
            chars += "'\"";
        }
        if (ext(SMARTS)) {
            chars += ".-";
        }
        if (ext(AUTOLINKS)) {
            chars += "(){}";
        }
        if (ext(DEFINITIONS)) {
            chars += ":";
        }
        if (ext(TABLES)) {
            chars += "|";
        }
        if (ext(DEFINITIONS) | ext(FENCED_CODE_BLOCKS)) {
            chars += "~";
        }
        for (Character ch : plugins.getSpecialChars()) {
            if (!chars.contains(ch.toString())) {
                chars += ch;
            }
        }
        return AnyOf(chars);
    }
sirthias commented 9 years ago

Closed by #181.