mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-27 01:45:56 +00:00
Markdown reader: reset sourcepos in parseWithString'...
...when parsing a block quote or list item. Otherwise it can happen that by the time parseWithString' is called, the position has already been set to the next file on the command line. Closes #11888. Closes #11888.
This commit is contained in:
@@ -281,6 +281,9 @@ extra-source-files:
|
||||
test/command/11486/scroll.revealjs
|
||||
test/command/11498.png
|
||||
test/command/11301-styles.opendocument
|
||||
test/command/11888/section1/lab.md
|
||||
test/command/11888/section2/lab.md
|
||||
test/command/11888/section3/lab.md
|
||||
test/asciidoc-reader.adoc
|
||||
test/asciidoc-reader.native
|
||||
test/asciidoc-reader-include.rb
|
||||
|
||||
@@ -815,6 +815,7 @@ emailBlockQuote = try $ do
|
||||
|
||||
blockQuote :: PandocMonad m => MarkdownParser m (F Blocks)
|
||||
blockQuote = do
|
||||
pos <- getPosition
|
||||
raw <- emailBlockQuote
|
||||
(mbAlert, raw') <-
|
||||
(do guardEnabled Ext_alerts
|
||||
@@ -830,7 +831,8 @@ blockQuote = do
|
||||
_ -> pure (Nothing, raw))
|
||||
<|> pure (Nothing, raw)
|
||||
-- parse the extracted block, which may contain various block elements:
|
||||
contents <- parseFromString' parseBlocks $ T.intercalate "\n" raw' <> "\n\n"
|
||||
contents <- parseFromString' (setPosition pos >> parseBlocks)
|
||||
$ T.intercalate "\n" raw' <> "\n\n"
|
||||
return $
|
||||
case mbAlert of
|
||||
Nothing -> B.blockQuote <$> contents
|
||||
@@ -972,11 +974,12 @@ listItem fourSpaceRule start = try $ do
|
||||
state <- getState
|
||||
let oldContext = stateParserContext state
|
||||
setState $ state {stateParserContext = ListItemState}
|
||||
pos <- getPosition
|
||||
(first, continuationIndent) <- rawListItem fourSpaceRule start
|
||||
continuations <- many (listContinuation continuationIndent)
|
||||
-- parse the extracted block, which may contain various block elements:
|
||||
let raw = T.concat (first:continuations)
|
||||
contents <- parseFromString' parseBlocks raw
|
||||
contents <- parseFromString' (setPosition pos >> parseBlocks) raw
|
||||
updateState (\st -> st {stateParserContext = oldContext})
|
||||
exts <- getOption readerExtensions
|
||||
return $ B.fromList . taskListItemFromAscii exts . B.toList <$> contents
|
||||
@@ -1017,8 +1020,9 @@ defListStart = do
|
||||
|
||||
definitionListItem :: PandocMonad m => MarkdownParser m (F (Inlines, [Blocks]))
|
||||
definitionListItem = try $ do
|
||||
pos <- getPosition
|
||||
rawLine' <- anyLine
|
||||
term <- parseFromString' (trimInlinesF <$> inlines) rawLine'
|
||||
term <- parseFromString' (setPosition pos >> (trimInlinesF <$> inlines)) rawLine'
|
||||
isTight <- (False <$ blanklines) <|> pure True
|
||||
fourSpaceRule <- (True <$ guardEnabled Ext_four_space_rule) <|> pure False
|
||||
contents <- many1 $ listItem fourSpaceRule defListStart
|
||||
@@ -1224,8 +1228,9 @@ lineBlock :: PandocMonad m => MarkdownParser m (F Blocks)
|
||||
lineBlock = do
|
||||
guardEnabled Ext_line_blocks
|
||||
try $ do
|
||||
pos <- getPosition
|
||||
lines' <- lineBlockLines >>=
|
||||
mapM (parseFromString' (trimInlinesF <$> inlines))
|
||||
mapM (parseFromString' (setPosition pos >> (trimInlinesF <$> inlines)))
|
||||
return $ B.lineBlock <$> sequence lines'
|
||||
|
||||
--
|
||||
@@ -1312,8 +1317,9 @@ rawTableLine indices = do
|
||||
tableLine :: PandocMonad m
|
||||
=> [Int]
|
||||
-> MarkdownParser m (F [Blocks])
|
||||
tableLine indices = rawTableLine indices >>=
|
||||
fmap sequence . mapM (parseFromString' (mconcat <$> many plain))
|
||||
tableLine indices = do
|
||||
raw <- rawTableLine indices
|
||||
sequence <$> mapM (parseFromString' (mconcat <$> many plain)) raw
|
||||
|
||||
-- Parse a multiline table row and return a list of blocks (columns).
|
||||
multilineRow :: PandocMonad m
|
||||
@@ -1398,7 +1404,7 @@ multilineTableHeader headless = try $ do
|
||||
then []
|
||||
else map (T.unlines . map trim) rawHeadsList
|
||||
heads <- fmap sequence $
|
||||
mapM (parseFromString' (mconcat <$> many plain).trim) rawHeads
|
||||
mapM (parseFromString' (mconcat <$> many plain) . trim) rawHeads
|
||||
return (fmap (:[]) heads, aligns, indices')
|
||||
|
||||
-- Parse a grid table: starts with row of '-' on top, then header
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
```
|
||||
% pandoc -f markdown+rebase_relative_paths command/11888/section1/lab.md command/11888/section2/lab.md command/11888/section3/lab.md
|
||||
^D
|
||||
<h1 id="heading-1">Heading 1</h1>
|
||||
<figure>
|
||||
<img src="command/11888/section1/media/Pic1_1.png" alt="pic 1" />
|
||||
<figcaption aria-hidden="true">pic 1</figcaption>
|
||||
</figure>
|
||||
<blockquote>
|
||||
<p>a blockquote</p>
|
||||
<figure>
|
||||
<img src="command/11888/section1/media/Pic1_2.png" alt="pic 2" />
|
||||
<figcaption aria-hidden="true">pic 2</figcaption>
|
||||
</figure>
|
||||
<p>with an image reference</p>
|
||||
<figure>
|
||||
<img src="command/11888/section1/media/Pic1_3.png" alt="pic 3" />
|
||||
<figcaption aria-hidden="true">pic 3</figcaption>
|
||||
</figure>
|
||||
</blockquote>
|
||||
<h1 id="heading-2">Heading 2</h1>
|
||||
<figure>
|
||||
<img src="command/11888/section2/media/Pic2_1.png" alt="pic 3" />
|
||||
<figcaption aria-hidden="true">pic 3</figcaption>
|
||||
</figure>
|
||||
<ol type="1">
|
||||
<li><p>A list</p>
|
||||
<figure>
|
||||
<img src="command/11888/section2/media/Pic2_2.png" alt="pic 4" />
|
||||
<figcaption aria-hidden="true">pic 4</figcaption>
|
||||
</figure></li>
|
||||
</ol>
|
||||
<h1 id="heading-3">Heading 3</h1>
|
||||
<figure>
|
||||
<img src="command/11888/section3/media/Pic3_1.png" alt="pic 5" />
|
||||
<figcaption aria-hidden="true">pic 5</figcaption>
|
||||
</figure>
|
||||
<ol type="1">
|
||||
<li><p>A list</p>
|
||||
<figure>
|
||||
<img src="command/11888/section3/media/Pic3_2.png" alt="pic 6" />
|
||||
<figcaption aria-hidden="true">pic 6</figcaption>
|
||||
</figure></li>
|
||||
</ol>
|
||||
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
# Heading 1
|
||||
|
||||

|
||||
|
||||
> a blockquote
|
||||
>
|
||||
> 
|
||||
>
|
||||
> with an image reference
|
||||
>
|
||||
> 
|
||||
@@ -0,0 +1,8 @@
|
||||
# Heading 2
|
||||
|
||||

|
||||
|
||||
1. A list
|
||||
|
||||

|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# Heading 3
|
||||
|
||||

|
||||
|
||||
1. A list
|
||||
|
||||

|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
okay
|
||||
^D
|
||||
2> [WARNING] Div at _chunk line 1 column 1 unclosed at _chunk line 5 column 1, closing implicitly.
|
||||
2> [WARNING] Div at line 1 column 1 unclosed at line 5 column 1, closing implicitly.
|
||||
<blockquote>
|
||||
<div class="fence">
|
||||
<p>that is not closed</p>
|
||||
|
||||
Reference in New Issue
Block a user