From 808f6d3fa1816401d9eb1d6a5d1821fb783cc1d5 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Sun, 17 Dec 2017 09:47:24 -0800
Subject: OPML reader: enable raw HTML and other extensions by default for
 notes.

This fixes a regression in 2.0.

Note that extensions can now be individually disabled, e.g.
`-f opml-smart-raw_html`.

Closes #4164.
---
 src/Text/Pandoc/Extensions.hs   |  1 +
 src/Text/Pandoc/Readers/OPML.hs | 23 ++++++++++++++---------
 2 files changed, 15 insertions(+), 9 deletions(-)

(limited to 'src')

diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs
index 771898d70..bea293891 100644
--- a/src/Text/Pandoc/Extensions.hs
+++ b/src/Text/Pandoc/Extensions.hs
@@ -343,6 +343,7 @@ getDefaultExtensions "textile"         = extensionsFromList
                                            Ext_smart,
                                            Ext_raw_html,
                                            Ext_auto_identifiers]
+getDefaultExtensions "opml"            = pandocExtensions -- affects notes
 getDefaultExtensions _                 = extensionsFromList
                                           [Ext_auto_identifiers]
 
diff --git a/src/Text/Pandoc/Readers/OPML.hs b/src/Text/Pandoc/Readers/OPML.hs
index 1a1375b16..68f3252a9 100644
--- a/src/Text/Pandoc/Readers/OPML.hs
+++ b/src/Text/Pandoc/Readers/OPML.hs
@@ -12,7 +12,7 @@ import Text.Pandoc.Class (PandocMonad)
 import Text.Pandoc.Options
 import Text.Pandoc.Readers.HTML (readHtml)
 import Text.Pandoc.Readers.Markdown (readMarkdown)
-import Text.Pandoc.Shared (crFilter)
+import Text.Pandoc.Shared (crFilter, blocksToInlines)
 import Text.XML.Light
 
 type OPML m = StateT OPMLState m
@@ -22,6 +22,7 @@ data OPMLState = OPMLState{
                       , opmlDocTitle     :: Inlines
                       , opmlDocAuthors   :: [Inlines]
                       , opmlDocDate      :: Inlines
+                      , opmlOptions      :: ReaderOptions
                       } deriving Show
 
 instance Default OPMLState where
@@ -29,13 +30,14 @@ instance Default OPMLState where
                  , opmlDocTitle = mempty
                  , opmlDocAuthors = []
                  , opmlDocDate = mempty
-                  }
+                 , opmlOptions = def
+                 }
 
 readOPML :: PandocMonad m => ReaderOptions -> Text -> m Pandoc
-readOPML _ inp  = do
+readOPML opts inp  = do
   (bs, st') <- runStateT
                  (mapM parseBlock $ normalizeTree $
-                    parseXML (unpack (crFilter inp))) def
+                    parseXML (unpack (crFilter inp))) def{ opmlOptions = opts }
   return $
     setTitle (opmlDocTitle st') $
     setAuthors (opmlDocAuthors st') $
@@ -69,13 +71,16 @@ attrValue attr elt =
 -- exceptT = either throwError return
 
 asHtml :: PandocMonad m => String -> OPML m Inlines
-asHtml s =
-  (\(Pandoc _ bs) -> case bs of
-                                [Plain ils] -> fromList ils
-                                _           -> mempty) <$> lift (readHtml def (pack s))
+asHtml s = do
+  opts <- gets opmlOptions
+  Pandoc _ bs <- readHtml def{ readerExtensions = readerExtensions opts } (pack s)
+  return $ fromList $ blocksToInlines bs
 
 asMarkdown :: PandocMonad m => String -> OPML m Blocks
-asMarkdown s = (\(Pandoc _ bs) -> fromList bs) <$> lift (readMarkdown def (pack s))
+asMarkdown s = do
+  opts <- gets opmlOptions
+  Pandoc _ bs <- readMarkdown def{ readerExtensions = readerExtensions opts }  (pack s)
+  return $ fromList bs
 
 getBlocks :: PandocMonad m => Element -> OPML m Blocks
 getBlocks e =  mconcat <$> mapM parseBlock (elContent e)
-- 
cgit v1.2.3