List processing bug (on Android), and a fix.

40 views
Skip to first unread message

Bjarni Rúnar

unread,
Dec 31, 2009, 9:53:05 AM12/31/09
to MarkdownJ
Hello,

I had some trouble using markdownj on Android (in my WhereBlogger
app): it would fail to correctly render lists if they were followed by
any text - only lists at the very end of a block of text would be
handled properly.

I fixed this using the following regexp (in doLists), which
incidentally is also much faster than the regexp it replaces. I'm not
100% sure this is fully according to the Markdown spec, but it's a
clear improvement for me. Hope this helps!

Here's the code:

// Bjarni R. Einarsson <b...@klaki.net>:
// This list matching expression avoids the slow "minimum
match" (.+?) and
// does not get confused on my Android by trailing content.
Not sure if it
// is 100% Markdown compatible, but it is faster and more
reliable for me.
String wholeList =
"(" +
"(" + // List beginning is (
"[ ]{0," + lessThanTab + "}" + // 0-3 leading spaces
"([-+*]|\\d+[\\.])" + // - or + or * or 1.
or 2. ... ($3)
"[ ]+" + // Trailing spaces
")" + // )
"(?s:" + // Lists contain, repeatedly (
"[^\\n]+\\n?" + // A line of text ending in a single
newline (or end of input, matched below)
"|" + // ..or..
"\\n[ ]+" + // 2 newlines (above will match 1st)
and indented txt
")+" + // )+
"(" + // End of list is (
"\\n+" + // Some trailing newlines
"|" + // ..or..
"\\z" + // End of input
")" + // )
")";

Reply all
Reply to author
Forward
0 new messages