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:
parent
03167bb447
commit
e95047ed85
5 changed files with 26 additions and 1 deletions
10
MANUAL.txt
10
MANUAL.txt
|
@ -3063,6 +3063,16 @@ For example:
|
||||||
is to look at the image resolution and the dpi metadata embedded in
|
is to look at the image resolution and the dpi metadata embedded in
|
||||||
the image file.
|
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
|
Footnotes
|
||||||
---------
|
---------
|
||||||
|
|
|
@ -84,6 +84,7 @@ data Extension =
|
||||||
| Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
|
| Ext_markdown_in_html_blocks -- ^ Interpret as markdown inside HTML blocks
|
||||||
| Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
|
| Ext_native_divs -- ^ Use Div blocks for contents of <div> tags
|
||||||
| Ext_native_spans -- ^ Use Span inlines for contents of <span>
|
| 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
|
| Ext_markdown_attribute -- ^ Interpret text inside HTML as markdown
|
||||||
-- iff container has attribute 'markdown'
|
-- iff container has attribute 'markdown'
|
||||||
| Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
|
| Ext_escaped_line_breaks -- ^ Treat a backslash at EOL as linebreak
|
||||||
|
@ -145,6 +146,7 @@ pandocExtensions = Set.fromList
|
||||||
, Ext_markdown_in_html_blocks
|
, Ext_markdown_in_html_blocks
|
||||||
, Ext_native_divs
|
, Ext_native_divs
|
||||||
, Ext_native_spans
|
, Ext_native_spans
|
||||||
|
, Ext_bracketed_spans
|
||||||
, Ext_escaped_line_breaks
|
, Ext_escaped_line_breaks
|
||||||
, Ext_fancy_lists
|
, Ext_fancy_lists
|
||||||
, Ext_startnum
|
, Ext_startnum
|
||||||
|
|
|
@ -1482,6 +1482,7 @@ inline = choice [ whitespace
|
||||||
, strongOrEmph
|
, strongOrEmph
|
||||||
, note
|
, note
|
||||||
, cite
|
, cite
|
||||||
|
, bracketedSpan
|
||||||
, link
|
, link
|
||||||
, image
|
, image
|
||||||
, math
|
, math
|
||||||
|
@ -1750,6 +1751,13 @@ link = try $ do
|
||||||
setState $ st{ stateAllowLinks = True }
|
setState $ st{ stateAllowLinks = True }
|
||||||
regLink B.linkWith lab <|> referenceLink B.linkWith (lab,raw)
|
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)
|
regLink :: (Attr -> String -> String -> Inlines -> Inlines)
|
||||||
-> F Inlines -> MarkdownParser (F Inlines)
|
-> F Inlines -> MarkdownParser (F Inlines)
|
||||||
regLink constructor lab = try $ do
|
regLink constructor lab = try $ do
|
||||||
|
|
|
@ -163,4 +163,6 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
|
||||||
,Para [Link ("",[],[]) [Str "foo2"] ("","")]
|
,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"]
|
,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
|
,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","")]]]
|
||||||
|
|
|
@ -287,3 +287,6 @@ bar
|
||||||
|
|
||||||
- blah blah blah blah blah blah blah blah blah blah blah blah blah blah 2015.
|
- 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}
|
||||||
|
|
Loading…
Reference in a new issue