diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2023-03-03 18:14:06 -0800 |
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2023-03-03 18:14:06 -0800 |
| commit | 8898c5336dfdd9c43cec20cf9763f65d9ff9dbb5 (patch) | |
| tree | 3cea7a9b699d709986a3b3fdf8fc04d78464ff65 /src | |
| parent | becabf5d682b6f3fad1d48354ae3d8a26b74fa7a (diff) | |
Asciidoc writer: Properly escape `|` in table cells.
Closes #8665.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/AsciiDoc.hs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/Text/Pandoc/Writers/AsciiDoc.hs b/src/Text/Pandoc/Writers/AsciiDoc.hs index 2a9401a4f..e4a34f251 100644 --- a/src/Text/Pandoc/Writers/AsciiDoc.hs +++ b/src/Text/Pandoc/Writers/AsciiDoc.hs @@ -109,12 +109,18 @@ pandocToAsciiDoc opts (Pandoc meta blocks) = do Just tpl -> renderTemplate tpl context -- | Escape special characters for AsciiDoc. -escapeString :: Text -> Text -escapeString t - | T.any (== '{') t = T.concatMap escChar t - | otherwise = t - where escChar '{' = "\\{" - escChar c = T.singleton c +escapeString :: PandocMonad m => Text -> ADW m (Doc Text) +escapeString t = do + parentTableLevel <- gets tableNestingLevel + let needsEscape '{' = True + needsEscape '|' = parentTableLevel > 0 + needsEscape _ = False + let escChar c | needsEscape c = "\\" <> T.singleton c + | otherwise = T.singleton c + if T.any needsEscape t + then return $ literal $ T.concatMap escChar t + else return $ literal t + -- | Ordered list start parser for use in Para below. olMarker :: Parsec Text ParserState Char @@ -538,7 +544,7 @@ inlineToAsciiDoc _ (Code _ str) = do if isAsciidoctor then text "`+" <> contents <> "+`" else text "`" <> contents <> "`" -inlineToAsciiDoc _ (Str str) = return $ literal $ escapeString str +inlineToAsciiDoc _ (Str str) = escapeString str inlineToAsciiDoc _ (Math InlineMath str) = do isAsciidoctor <- gets asciidoctorVariant modify $ \st -> st{ hasMath = True } |
