git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: Handle `c++` and `objective-c` as language identifiers

in github-style fenced blocks. Closes #1318. Note: This is special-case handling of these two cases. It would be good to do something more systematic.

commite3ddc371dee9630dae71d61a69088b06cea8e909 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 27 May 2014, 12:44 (12 years ago) parent2d90803
1 file changed+8−1
src/Text/Pandoc/Readers/Markdown.hs+8−1
src/Text/Pandoc/Readers/Markdown.hs+8−1
@@ -618,12 +618,19 @@ codeBlockFenced = try $ do
618618 skipMany spaceChar
619619 attr <- option ([],[],[]) $
620620 try (guardEnabled Ext_fenced_code_attributes >> attributes)
621− <|> ((\x -> ("",[x],[])) <$> identifier)
621+ <|> ((\x -> ("",[toLanguageId x],[])) <$> many1 nonspaceChar)
622622 blankline
623623 contents <- manyTill anyLine (blockDelimiter (== c) (Just size))
624624 blanklines
625625 return $ return $ B.codeBlockWith attr $ intercalate "\n" contents
626626
627+-- correctly handle github language identifiers
628+toLanguageId :: String -> String
629+toLanguageId = map toLower . go
630+ where go "c++" = "cpp"
631+ go "objective-c" = "objectivec"
632+ go x = x
633+
627634codeBlockIndented :: MarkdownParser (F Blocks)
628635codeBlockIndented = do
629636 contents <- many1 (indentedLine <|>