git.iko.soy/typeable/pandoc
on master help sign in
OPML reader: enable raw HTML and other extensions by default for notes.
808f6d3John MacFarlane
src/Text/Pandoc/Extensions.hs+1
@@ -343,6 +343,7 @@ getDefaultExtensions "textile" = extensionsFromList
343 Ext_smart,
343 Ext_smart,
344 Ext_raw_html,
344 Ext_raw_html,
345 Ext_auto_identifiers]
345 Ext_auto_identifiers]
346+getDefaultExtensions "opml" = pandocExtensions -- affects notes
346getDefaultExtensions _ = extensionsFromList
347getDefaultExtensions _ = extensionsFromList
347 [Ext_auto_identifiers]
348 [Ext_auto_identifiers]
348
349
src/Text/Pandoc/Readers/OPML.hs+14−9
@@ -12,7 +12,7 @@ import Text.Pandoc.Class (PandocMonad)
12import Text.Pandoc.Options
12import Text.Pandoc.Options
13import Text.Pandoc.Readers.HTML (readHtml)
13import Text.Pandoc.Readers.HTML (readHtml)
14import Text.Pandoc.Readers.Markdown (readMarkdown)
14import Text.Pandoc.Readers.Markdown (readMarkdown)
15−import Text.Pandoc.Shared (crFilter)
15+import Text.Pandoc.Shared (crFilter, blocksToInlines)
16import Text.XML.Light
16import Text.XML.Light
17
17
18type OPML m = StateT OPMLState m
18type OPML m = StateT OPMLState m
@@ -22,6 +22,7 @@ data OPMLState = OPMLState{
22 , opmlDocTitle :: Inlines
22 , opmlDocTitle :: Inlines
23 , opmlDocAuthors :: [Inlines]
23 , opmlDocAuthors :: [Inlines]
24 , opmlDocDate :: Inlines
24 , opmlDocDate :: Inlines
25+ , opmlOptions :: ReaderOptions
25 } deriving Show
26 } deriving Show
26
27
27instance Default OPMLState where
28instance Default OPMLState where
@@ -29,13 +30,14 @@ instance Default OPMLState where
29 , opmlDocTitle = mempty
30 , opmlDocTitle = mempty
30 , opmlDocAuthors = []
31 , opmlDocAuthors = []
31 , opmlDocDate = mempty
32 , opmlDocDate = mempty
33+ , opmlOptions = def
32− }
34+ }
33
35
34readOPML :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
36readOPML :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
35−readOPML _ inp = do
37+readOPML opts inp = do
36 (bs, st') <- runStateT
38 (bs, st') <- runStateT
37 (mapM parseBlock $ normalizeTree $
39 (mapM parseBlock $ normalizeTree $
38− parseXML (unpack (crFilter inp))) def
40+ parseXML (unpack (crFilter inp))) def{ opmlOptions = opts }
39 return $
41 return $
40 setTitle (opmlDocTitle st') $
42 setTitle (opmlDocTitle st') $
41 setAuthors (opmlDocAuthors st') $
43 setAuthors (opmlDocAuthors st') $
@@ -69,13 +71,16 @@ attrValue attr elt =
69-- exceptT = either throwError return
71-- exceptT = either throwError return
70
72
71asHtml :: PandocMonad m => String -> OPML m Inlines
73asHtml :: PandocMonad m => String -> OPML m Inlines
72−asHtml s =
74+asHtml s = do
73− (\(Pandoc _ bs) -> case bs of
75+ opts <- gets opmlOptions
74− [Plain ils] -> fromList ils
76+ Pandoc _ bs <- readHtml def{ readerExtensions = readerExtensions opts } (pack s)
75− _ -> mempty) <$> lift (readHtml def (pack s))
77+ return $ fromList $ blocksToInlines bs
76
78
77asMarkdown :: PandocMonad m => String -> OPML m Blocks
79asMarkdown :: PandocMonad m => String -> OPML m Blocks
80+asMarkdown s = do
81+ opts <- gets opmlOptions
78−asMarkdown s = (\(Pandoc _ bs) -> fromList bs) <$> lift (readMarkdown def (pack s))
82+ Pandoc _ bs <- readMarkdown def{ readerExtensions = readerExtensions opts } (pack s)
83+ return $ fromList bs
79
84
80getBlocks :: PandocMonad m => Element -> OPML m Blocks
85getBlocks :: PandocMonad m => Element -> OPML m Blocks
81getBlocks e = mconcat <$> mapM parseBlock (elContent e)
86getBlocks e = mconcat <$> mapM parseBlock (elContent e)
test/command/4164.mdnew file+35
@@ -0,0 +1,35 @@
1+```
2+% pandoc -f opml -t markdown
3+<?xml version="1.0"?> <opml version="1.0"> <head> <title> test </title> </head> <body> <outline text="test"> <outline text="try" _note="Here is inline html:&#xA;&#xA;&lt;div&gt; &#xA;&lt;balise&gt;&#xA;bla bla&#xA;&lt;/div&gt;"/> </outline> </body> </opml>
4+^D
5+test
6+====
7+
8+try
9+---
10+
11+Here is inline html:
12+
13+<div>
14+
15+<balise> bla bla
16+
17+</div>
18+
19+```
20+
21+```
22+% pandoc -f opml-raw_html-native_divs -t markdown
23+<?xml version="1.0"?> <opml version="1.0"> <head> <title> test </title> </head> <body> <outline text="test"> <outline text="try" _note="Here is inline html:&#xA;&#xA;&lt;div&gt; &#xA;&lt;balise&gt;&#xA;bla bla&#xA;&lt;/div&gt;"/> </outline> </body> </opml>
24+^D
25+test
26+====
27+
28+try
29+---
30+
31+Here is inline html:
32+
33+\<div\> \<balise\> bla bla \</div\>
34+
35+```