git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: handle inline code more eagerly within lists. (#5628)

Closes #5627.

commit9c4ba81357ab0d72d41c3e69c87a3939f90e9751 authorBrian Leung <29217594+leungbk@users.noreply.github.com> dateSat 6 Jul 2019, 14:14 (7 years ago) parent1e80288
2 files changed+90−5
src/Text/Pandoc/Readers/Markdown.hs+7−5 test/command/5627.md+83
src/Text/Pandoc/Readers/Markdown.hs+7−5
@@ -857,7 +857,8 @@ listLine continuationIndent = try $ do
857857
858858listLineCommon :: PandocMonad m => MarkdownParser m String
859859listLineCommon = concat <$> manyTill
860− ( many1 (satisfy $ \c -> c /= '\n' && c /= '<')
860+ ( many1 (satisfy $ \c -> c `notElem` ['\n', '<', '`'])
861+ <|> fmap snd (withRaw code)
861862 <|> fmap snd (htmlTag isCommentTag)
862863 <|> count 1 anyChar
863864 ) newline
@@ -932,14 +933,14 @@ listItem :: PandocMonad m
932933 -> MarkdownParser m a
933934 -> MarkdownParser m (F Blocks)
934935listItem fourSpaceRule start = try $ do
935− (first, continuationIndent) <- rawListItem fourSpaceRule start
936− continuations <- many (listContinuation continuationIndent)
937936 -- parsing with ListItemState forces markers at beginning of lines to
938937 -- count as list item markers, even if not separated by blank space.
939938 -- see definition of "endline"
940939 state <- getState
941940 let oldContext = stateParserContext state
942941 setState $ state {stateParserContext = ListItemState}
942+ (first, continuationIndent) <- rawListItem fourSpaceRule start
943+ continuations <- many (listContinuation continuationIndent)
943944 -- parse the extracted block, which may contain various block elements:
944945 let raw = concat (first:continuations)
945946 contents <- parseFromString' parseBlocks raw
@@ -1583,8 +1584,9 @@ code = try $ do
15831584 starts <- many1 (char '`')
15841585 skipSpaces
15851586 result <- (trim . concat) <$>
1586− manyTill (many1 (noneOf "`\n") <|> many1 (char '`') <|>
1587− (char '\n' >> notFollowedBy' blankline >> return " "))
1587+ manyTill (notFollowedBy (inList >> listStart) >>
1588+ (many1 (noneOf "`\n") <|> many1 (char '`') <|>
1589+ (char '\n' >> notFollowedBy' blankline >> return " ")))
15881590 (try (skipSpaces >> count (length starts) (char '`') >>
15891591 notFollowedBy (char '`')))
15901592 rawattr <-
test/command/5627.mdnew file+83
@@ -0,0 +1,83 @@
1+```
2+% pandoc -t html
3+## Example
4+
5+1. One
6+2. Two `-->something<!--`
7+3. Three
8+
9+~~~html
10+--><!--<script>alert('Escaped!')</script>
11+~~~
12+
13+~~~html
14+Something
15+~~~
16+^D
17+<h2 id="example">Example</h2>
18+<ol type="1">
19+<li>One</li>
20+<li>Two <code>--&gt;something&lt;!--</code></li>
21+<li>Three</li>
22+</ol>
23+<div class="sourceCode" id="cb1"><pre class="sourceCode html"><code class="sourceCode html"><span id="cb1-1"><a href="#cb1-1"></a>--&gt;<span class="co">&lt;!--&lt;script&gt;alert(&#39;Escaped!&#39;)&lt;/script&gt;</span></span></code></pre></div>
24+<div class="sourceCode" id="cb2"><pre class="sourceCode html"><code class="sourceCode html"><span id="cb2-1"><a href="#cb2-1"></a>Something</span></code></pre></div>
25+```
26+
27+```
28+% pandoc -t html
29+## Example 2
30+
31+- `-->something<!--`
32+- `-->something<!--`
33+- bye `-->something else<!--`
34+
35+~~~html
36+--><!--<script>alert('Escaped!')</script>
37+~~~
38+
39+~~~html
40+Something
41+~~~
42+^D
43+<h2 id="example-2">Example 2</h2>
44+<ul>
45+<li><code>--&gt;something&lt;!--</code></li>
46+<li><code>--&gt;something&lt;!--</code></li>
47+<li>bye <code>--&gt;something else&lt;!--</code></li>
48+</ul>
49+<div class="sourceCode" id="cb1"><pre class="sourceCode html"><code class="sourceCode html"><span id="cb1-1"><a href="#cb1-1"></a>--&gt;<span class="co">&lt;!--&lt;script&gt;alert(&#39;Escaped!&#39;)&lt;/script&gt;</span></span></code></pre></div>
50+<div class="sourceCode" id="cb2"><pre class="sourceCode html"><code class="sourceCode html"><span id="cb2-1"><a href="#cb2-1"></a>Something</span></code></pre></div>
51+```
52+
53+```
54+% pandoc -t html
55+## Example 3
56+
57+1. `-->one<!--`
58+5. bye `-->two <!--`
59+3. ` three, not in block
60+1. four, not in block `
61+2. five
62+5. six
63+6. seven `
64+- separate unordered list `
65+42. forty-two, separate ordered list
66+^D
67+<h2 id="example-3">Example 3</h2>
68+<ol type="1">
69+<li><code>--&gt;one&lt;!--</code></li>
70+<li>bye <code>--&gt;two &lt;!--</code></li>
71+<li>` three, not in block</li>
72+<li>four, not in block `</li>
73+<li>five</li>
74+<li>six</li>
75+<li>seven `</li>
76+</ol>
77+<ul>
78+<li>separate unordered list `</li>
79+</ul>
80+<ol start="42" type="1">
81+<li>forty-two, separate ordered list</li>
82+</ol>
83+```