diff --git a/MANUAL.txt b/MANUAL.txt index f4e91e6c6..adcbf535a 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -3857,6 +3857,18 @@ This is equivalent to: qsort [] = [] ``` +This shortcut form may be combined with attributes: + + ```haskell {.numberLines} + qsort [] = [] + ``` + +Which is equivalent to: + + ``` {.haskell .numberLines} + qsort [] = [] + ``` + If the `fenced_code_attributes` extension is disabled, but input contains class attribute(s) for the code block, the first class attribute will be printed after the opening fence as a bare 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) diff --git a/test/command/8174.md b/test/command/8174.md new file mode 100644 index 000000000..61fe37b93 --- /dev/null +++ b/test/command/8174.md @@ -0,0 +1,44 @@ +```` +% pandoc -t native +```yaml {#id} +some: code +``` +^D +[ CodeBlock ( "id" , [ "yaml" ] , [] ) "some: code" ] +```` + +```` +% pandoc -t native +```yaml {.class #id} +some: code +``` +^D +[ CodeBlock + ( "id" , [ "yaml" , "class" ] , [] ) "some: code" +] +```` + + +```` +% pandoc -t native +```ab``` +^D +[ Para [ Code ( "" , [] , [] ) "ab" ] ] +```` + +```` +% pandoc -t native +```ab```{.class} +^D +[ Para [ Code ( "" , [ "class" ] , [] ) "ab" ] ] +```` + + +```` +% pandoc -t native +``` foo}{.bar} +test +``` +^D +[ Para [ Code ( "" , [] , [] ) "foo}{.bar} test" ] ] +````