git.iko.soy/typeable/pandoc
on master help sign in
Markdown reader: added bracket syntax for native spans.
e95047eJohn MacFarlane
MANUAL.txt+10
@@ -3063,6 +3063,16 @@ For example:
3063 is to look at the image resolution and the dpi metadata embedded in
3063 is to look at the image resolution and the dpi metadata embedded in
3064 the image file.
3064 the image file.
3065
3065
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"}
3066
3076
3067Footnotes
3077Footnotes
3068---------
3078---------
src/Text/Pandoc/Options.hs+2
@@ -84,6 +84,7 @@ data Extension =
84 | Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
84 | Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
85 | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
85 | Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
86 | Ext_native_spans -- ^ Use Span inlines for contents of <span>
86 | Ext_native_spans -- ^ Use Span inlines for contents of <span>
87+ | Ext_bracketed_spans -- ^ Bracketed spans with attributes
87 | Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
88 | Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
88 -- iff container has attribute 'markdown'
89 -- iff container has attribute 'markdown'
89 | Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
90 | Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
@@ -145,6 +146,7 @@ pandocExtensions = Set.fromList
145 , Ext_markdown_in_html_blocks
146 , Ext_markdown_in_html_blocks
146 , Ext_native_divs
147 , Ext_native_divs
147 , Ext_native_spans
148 , Ext_native_spans
149+ , Ext_bracketed_spans
148 , Ext_escaped_line_breaks
150 , Ext_escaped_line_breaks
149 , Ext_fancy_lists
151 , Ext_fancy_lists
150 , Ext_startnum
152 , Ext_startnum
src/Text/Pandoc/Readers/Markdown.hs+8
@@ -1482,6 +1482,7 @@ inline = choice [ whitespace
1482 , strongOrEmph
1482 , strongOrEmph
1483 , note
1483 , note
1484 , cite
1484 , cite
1485+ , bracketedSpan
1485 , link
1486 , link
1486 , image
1487 , image
1487 , math
1488 , math
@@ -1750,6 +1751,13 @@ link = try $ do
1750 setState $ st{ stateAllowLinks = True }
1751 setState $ st{ stateAllowLinks = True }
1751 regLink B.linkWith lab <|> referenceLink B.linkWith (lab,raw)
1752 regLink B.linkWith lab <|> referenceLink B.linkWith (lab,raw)
1752
1753
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+
1753regLink :: (Attr -> String -> String -> Inlines -> Inlines)
1761regLink :: (Attr -> String -> String -> Inlines -> Inlines)
1754 -> F Inlines -> MarkdownParser (F Inlines)
1762 -> F Inlines -> MarkdownParser (F Inlines)
1755regLink constructor lab = try $ do
1763regLink 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
163,Para [Link ("",[],[]) [Str "foo2"] ("","")]
163,Para [Link ("",[],[]) [Str "foo2"] ("","")]
164,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"]
164,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"]
165,BulletList
165,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
287
287
288- blah blah blah blah blah blah blah blah blah blah blah blah blah blah 2015.
288- blah blah blah blah blah blah blah blah blah blah blah blah blah blah 2015.
289
289
290+## Bracketed spans
291+
292+[*foo* bar baz [link](url)]{.class #id key=val}