git.iko.soy/typeable/pandoc
on master help sign in
Vimwiki reader: Add nested syntax highlighting (#6257)

Nested syntaxes are specified like this: {{{sql SELECT * FROM table }}} The preformatted code block parser has been extended to check if the first attribute of the block is not a `key=value` pair, and in that case it will be considered as a class. Closes #6256.

commit8dbd4938f29aceb079316c9215b515744543b4d5 authorVlad Hanciuta <wladsh@gmail.com> dateTue 7 Apr 2020, 00:41 (7 years ago) parent663a5a9
3 files changed+13−1
src/Text/Pandoc/Readers/Vimwiki.hs+5−1 test/vimwiki-reader.native+2 test/vimwiki-reader.wiki+6
src/Text/Pandoc/Readers/Vimwiki.hs+5−1
@@ -236,7 +236,11 @@ preformatted = try $ do
236236makeAttr :: Text -> Attr
237237makeAttr s =
238238 let xs = splitTextBy (`elem` (" \t" :: String)) s in
239− ("", [], mapMaybe nameValue xs)
239+ ("", syntax xs, mapMaybe nameValue xs)
240+
241+syntax :: [Text] -> [Text]
242+syntax (s:_) | not $ T.isInfixOf "=" s = [s]
243+syntax _ = []
240244
241245nameValue :: Text -> Maybe (Text, Text)
242246nameValue s =
test/vimwiki-reader.native+2
@@ -49,6 +49,8 @@ Pandoc (Meta {unMeta = fromList [("date",MetaInlines [Str "2017-05-01"]),("title
4949,CodeBlock ("",[],[]) " Tyger! Tyger! burning bright\n In the forests of the night,\n What immortal hand or eye\n Could frame thy fearful symmetry?\n In what distant deeps or skies\n Burnt the fire of thine eyes?\n On what wings dare he aspire?\n What the hand dare sieze the fire?"
5050,Header 3 ("preformatted text with attributes",[],[]) [Str "preformatted",Space,Str "text",Space,Str "with",Space,Str "attributes"]
5151,CodeBlock ("",[],[("class","python"),("style","color:blue")]) " for i in range(1, 5):\n print(i)"
52+,Header 3 ("preformatted text with nested syntax",[],[]) [Str "preformatted",Space,Str "text",Space,Str "with",Space,Str "nested",Space,Str "syntax"]
53+,CodeBlock ("",["sql"],[]) "SELECT * FROM table"
5254,Header 3 ("empty preformatted text",[],[]) [Str "empty",Space,Str "preformatted",Space,Str "text"]
5355,CodeBlock ("",[],[]) ""
5456,Header 2 ("block quotes",[],[]) [Str "block",Space,Str "quotes"]
test/vimwiki-reader.wiki+6
@@ -117,6 +117,12 @@ Just two backticks: ``
117117 print(i)
118118 }}}
119119
120+=== preformatted text with nested syntax ===
121+
122+{{{sql
123+SELECT * FROM table
124+}}}
125+
120126=== empty preformatted text ===
121127
122128{{{