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.
This commit is contained in:
John MacFarlane 2016-09-28 12:33:05 +02:00
parent 03167bb447
commit e95047ed85
5 changed files with 26 additions and 1 deletions

View file

@ -3063,6 +3063,16 @@ For example:
is to look at the image resolution and the dpi metadata embedded in
the image file.
Spans
-----
#### Extension: `bracketed_spans` ####
A bracketed sequence of inlines, as one would use to begin
a link, will be treated as a span with attributes if it is
followed immediately by attributes:
[This is *some text*]{.class key="val"}
Footnotes
---------

View file

@ -84,6 +84,7 @@ data Extension =
| Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
| Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
| Ext_native_spans -- ^ Use Span inlines for contents of <span>
| Ext_bracketed_spans -- ^ Bracketed spans with attributes
| Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
-- iff container has attribute 'markdown'
| Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
@ -145,6 +146,7 @@ pandocExtensions = Set.fromList
, Ext_markdown_in_html_blocks
, Ext_native_divs
, Ext_native_spans
, Ext_bracketed_spans
, Ext_escaped_line_breaks
, Ext_fancy_lists
, Ext_startnum

View file

@ -1482,6 +1482,7 @@ inline = choice [ whitespace
, strongOrEmph
, note
, cite
, bracketedSpan
, link
, image
, math
@ -1750,6 +1751,13 @@ link = try $ do
setState $ st{ stateAllowLinks = True }
regLink B.linkWith lab <|> referenceLink B.linkWith (lab,raw)
bracketedSpan :: MarkdownParser (F Inlines)
bracketedSpan = try $ do
guardEnabled Ext_bracketed_spans
(lab,_) <- reference
attr <- attributes
return $ B.spanWith attr <$> lab
regLink :: (Attr -> String -> String -> Inlines -> Inlines)
-> F Inlines -> MarkdownParser (F Inlines)
regLink constructor lab = try $ do

View file

@ -163,4 +163,6 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
,Para [Link ("",[],[]) [Str "foo2"] ("","")]
,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"]
,BulletList
[[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."]]]]
[[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."]]]
,Header 2 ("bracketed-spans",[],[]) [Str "Bracketed",Space,Str "spans"]
,Para [Span ("id",["class"],[("key","val")]) [Emph [Str "foo"],Space,Str "bar",Space,Str "baz",Space,Link ("",[],[]) [Str "link"] ("url","")]]]

View file

@ -287,3 +287,6 @@ bar
- blah blah blah blah blah blah blah blah blah blah blah blah blah blah 2015.
## Bracketed spans
[*foo* bar baz [link](url)]{.class #id key=val}