git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: added bracket syntax for native spans.

See #168. Text.Pandoc.Options.Extension has a new constructor `Ext_brackted_spans`, which is enabled by default in pandoc's Markdown.

commite95047ed85872fbc44e261df74add4e4f9bef30d authorJohn MacFarlane <jgm@berkeley.edu> dateWed 28 Sep 2016, 12:33 (10 years ago) parent03167bb
5 files changed+26−1
MANUAL.txt+10 src/Text/Pandoc/Options.hs+2 src/Text/Pandoc/Readers/Markdown.hs+8 tests/markdown-reader-more.native+3−1 tests/markdown-reader-more.txt+3
MANUAL.txt+10
@@ -3063,6 +3063,16 @@ For example:
30633063 is to look at the image resolution and the dpi metadata embedded in
30643064 the image file.
30653065
3066+Spans
3067+-----
3068+
3069+#### Extension: `bracketed_spans` ####
3070+
3071+A bracketed sequence of inlines, as one would use to begin
3072+a link, will be treated as a span with attributes if it is
3073+followed immediately by attributes:
3074+
3075+ [This is *some text*]{.class key="val"}
30663076
30673077Footnotes
30683078---------
src/Text/Pandoc/Options.hs+2
@@ -84,6 +84,7 @@ data Extension =
8484 | Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
8585 | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
8686 | Ext_native_spans -- ^ Use Span inlines for contents of <span>
87+ | Ext_bracketed_spans -- ^ Bracketed spans with attributes
8788 | Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
8889 -- iff container has attribute 'markdown'
8990 | Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
@@ -145,6 +146,7 @@ pandocExtensions = Set.fromList
145146 , Ext_markdown_in_html_blocks
146147 , Ext_native_divs
147148 , Ext_native_spans
149+ , Ext_bracketed_spans
148150 , Ext_escaped_line_breaks
149151 , Ext_fancy_lists
150152 , Ext_startnum
src/Text/Pandoc/Readers/Markdown.hs+8
@@ -1482,6 +1482,7 @@ inline = choice [ whitespace
14821482 , strongOrEmph
14831483 , note
14841484 , cite
1485+ , bracketedSpan
14851486 , link
14861487 , image
14871488 , math
@@ -1750,6 +1751,13 @@ link = try $ do
17501751 setState $ st{ stateAllowLinks = True }
17511752 regLink B.linkWith lab <|> referenceLink B.linkWith (lab,raw)
17521753
1754+bracketedSpan :: MarkdownParser (F Inlines)
1755+bracketedSpan = try $ do
1756+ guardEnabled Ext_bracketed_spans
1757+ (lab,_) <- reference
1758+ attr <- attributes
1759+ return $ B.spanWith attr <$> lab
1760+
17531761regLink :: (Attr -> String -> String -> Inlines -> Inlines)
17541762 -> F Inlines -> MarkdownParser (F Inlines)
17551763regLink constructor lab = try $ do
tests/markdown-reader-more.native+3−1
@@ -163,4 +163,6 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
163163,Para [Link ("",[],[]) [Str "foo2"] ("","")]
164164,Header 2 ("wrapping-shouldnt-introduce-new-list-items",[],[]) [Str "Wrapping",Space,Str "shouldn\8217t",Space,Str "introduce",Space,Str "new",Space,Str "list",Space,Str "items"]
165165,BulletList
166− [[Plain [Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "2015."]]]]
166+ [[Plain [Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "blah",Space,Str "2015."]]]
167+,Header 2 ("bracketed-spans",[],[]) [Str "Bracketed",Space,Str "spans"]
168+,Para [Span ("id",["class"],[("key","val")]) [Emph [Str "foo"],Space,Str "bar",Space,Str "baz",Space,Link ("",[],[]) [Str "link"] ("url","")]]]
tests/markdown-reader-more.txt+3
@@ -287,3 +287,6 @@ bar
287287
288288- blah blah blah blah blah blah blah blah blah blah blah blah blah blah 2015.
289289
290+## Bracketed spans
291+
292+[*foo* bar baz [link](url)]{.class #id key=val}