Skip to content

Markdown reader: handle inline code more eagerly within lists. #5628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ listLine continuationIndent = try $ do

listLineCommon :: PandocMonad m => MarkdownParser m String
listLineCommon = concat <$> manyTill
( many1 (satisfy $ \c -> c /= '\n' && c /= '<')
( many1 (satisfy $ \c -> c `notElem` ['\n', '<', '`'])
<|> fmap snd (withRaw code)
<|> fmap snd (htmlTag isCommentTag)
<|> count 1 anyChar
) newline
Expand Down Expand Up @@ -932,14 +933,14 @@ listItem :: PandocMonad m
-> MarkdownParser m a
-> MarkdownParser m (F Blocks)
listItem fourSpaceRule start = try $ do
(first, continuationIndent) <- rawListItem fourSpaceRule start
continuations <- many (listContinuation continuationIndent)
-- parsing with ListItemState forces markers at beginning of lines to
-- count as list item markers, even if not separated by blank space.
-- see definition of "endline"
state <- getState
let oldContext = stateParserContext state
setState $ state {stateParserContext = ListItemState}
(first, continuationIndent) <- rawListItem fourSpaceRule start
continuations <- many (listContinuation continuationIndent)
-- parse the extracted block, which may contain various block elements:
let raw = concat (first:continuations)
contents <- parseFromString' parseBlocks raw
Expand Down Expand Up @@ -1583,8 +1584,9 @@ code = try $ do
starts <- many1 (char '`')
skipSpaces
result <- (trim . concat) <$>
manyTill (many1 (noneOf "`\n") <|> many1 (char '`') <|>
(char '\n' >> notFollowedBy' blankline >> return " "))
manyTill (notFollowedBy (inList >> listStart) >>
(many1 (noneOf "`\n") <|> many1 (char '`') <|>
(char '\n' >> notFollowedBy' blankline >> return " ")))
(try (skipSpaces >> count (length starts) (char '`') >>
notFollowedBy (char '`')))
rawattr <-
Expand Down
83 changes: 83 additions & 0 deletions test/command/5627.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
```
% pandoc -t html
## Example

1. One
2. Two `-->something<!--`
3. Three

~~~html
--><!--<script>alert('Escaped!')</script>
~~~

~~~html
Something
~~~
^D
<h2 id="example">Example</h2>
<ol type="1">
<li>One</li>
<li>Two <code>--&gt;something&lt;!--</code></li>
<li>Three</li>
</ol>
<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>
<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>
```

```
% pandoc -t html
## Example 2

- `-->something<!--`
- `-->something<!--`
- bye `-->something else<!--`

~~~html
--><!--<script>alert('Escaped!')</script>
~~~

~~~html
Something
~~~
^D
<h2 id="example-2">Example 2</h2>
<ul>
<li><code>--&gt;something&lt;!--</code></li>
<li><code>--&gt;something&lt;!--</code></li>
<li>bye <code>--&gt;something else&lt;!--</code></li>
</ul>
<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>
<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>
```

```
% pandoc -t html
## Example 3

1. `-->one<!--`
5. bye `-->two <!--`
3. ` three, not in block
1. four, not in block `
2. five
5. six
6. seven `
- separate unordered list `
42. forty-two, separate ordered list
^D
<h2 id="example-3">Example 3</h2>
<ol type="1">
<li><code>--&gt;one&lt;!--</code></li>
<li>bye <code>--&gt;two &lt;!--</code></li>
<li>` three, not in block</li>
<li>four, not in block `</li>
<li>five</li>
<li>six</li>
<li>seven `</li>
</ol>
<ul>
<li>separate unordered list `</li>
</ul>
<ol start="42" type="1">
<li>forty-two, separate ordered list</li>
</ol>
```