summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorSiphalor <info@siphalor.de>2022-08-25 19:18:11 +0200
committerGitHub <noreply@github.com>2022-08-25 10:18:11 -0700
commit8670f6dc5b943a6e7eabaf69776724d54d80c9bb (patch)
tree0e52fcb3b90bb475b4f8712ba0107f9d8bc23e78 /src/Text
parent201e86d9aa1506eb3675b4ba727787ae13b109ba (diff)
Markdown reader: fenced code block shortcuts with attributes (#8174)
This allows the combination of the fenced code block shortcut form with attributes: ```` ```haskell {.class #id} ``` ```` The code syntax class will be combined with the attribute classes. This syntax allows for more intuitive writing and for better compatibility with other Markdown parsers such as GitHub or Codeberg. Closes #8174.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 1e12a2314..3242122db 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -688,9 +688,13 @@ codeBlockFenced = try $ do
rawattr <-
(Left <$> (guardEnabled Ext_raw_attribute >> try rawAttribute))
<|>
- (Right <$> option ("",[],[])
- ((guardEnabled Ext_fenced_code_attributes >> try attributes)
- <|> ((\x -> ("",[toLanguageId x],[])) <$> many1Char nonspaceChar)))
+ (Right <$> (do
+ languageId <- option Nothing (Just . toLanguageId <$> try (many1Char $ satisfy (\x -> x `notElem` ['`', '{', '}'] && not (isSpace x))))
+ skipMany spaceChar
+ maybeAttr <- option Nothing (Just <$> (guardEnabled Ext_fenced_code_attributes >> try attributes))
+ return $ case maybeAttr of
+ Nothing -> ("", maybeToList languageId, [])
+ Just (elementId, classes, attrs) -> (elementId, maybe classes (: classes) languageId, attrs)))
blankline
contents <- T.intercalate "\n" <$>
manyTill (gobbleAtMostSpaces indentLevel >> anyLine)