git.iko.soy/typeable/pandoc
on master help sign in
Moved renderTags' from HTML reader & SelfContained to Shared.
a6f2b96John MacFarlane
src/Text/Pandoc/Readers/HTML.hs+1−13
@@ -45,7 +45,7 @@ import Text.Pandoc.Options
45import Text.Pandoc.Parsing
45import Text.Pandoc.Parsing
46import Data.Maybe ( fromMaybe, isJust )
46import Data.Maybe ( fromMaybe, isJust )
47import Data.List ( intercalate )
47import Data.List ( intercalate )
48−import Data.Char ( isDigit, toLower )
48+import Data.Char ( isDigit )
49import Control.Monad ( liftM, guard, when, mzero )
49import Control.Monad ( liftM, guard, when, mzero )
50
50
51isSpace :: Char -> Bool
51isSpace :: Char -> Bool
@@ -95,18 +95,6 @@ block = choice
95 , pRawHtmlBlock
95 , pRawHtmlBlock
96 ]
96 ]
97
97
98−-- repeated in SelfContained -- consolidate eventually
99−renderTags' :: [Tag String] -> String
100−renderTags' = renderTagsOptions
101− renderOptions{ optMinimize = \x ->
102− let y = map toLower x
103− in y == "hr" || y == "br" ||
104− y == "img" || y == "meta" ||
105− y == "link"
106− , optRawTag = \x ->
107− let y = map toLower x
108− in y == "script" || y == "style" }
109−
110pList :: TagParser [Block]
98pList :: TagParser [Block]
111pList = pBulletList <|> pOrderedList <|> pDefinitionList
99pList = pBulletList <|> pOrderedList <|> pDefinitionList
112
100
src/Text/Pandoc/Readers/Markdown.hs+9−3
@@ -776,11 +776,10 @@ rawHtmlBlocks = do
776 if "markdown" `notElem`
776 if "markdown" `notElem`
777 map fst as
777 map fst as
778 then mzero
778 then mzero
779− else return $ substitute
779+ else return $
780− " markdown=\"1\"" "" raw
780+ stripMarkdownAttribute raw
781 | otherwise -> return raw
781 | otherwise -> return raw
782 _ -> return raw )
782 _ -> return raw )
783− -- TODO remove markdown="1" attribute from raw tags
784 sps <- do sp1 <- many spaceChar
783 sps <- do sp1 <- many spaceChar
785 sp2 <- option "" (blankline >> return "\n")
784 sp2 <- option "" (blankline >> return "\n")
786 sp3 <- many spaceChar
785 sp3 <- many spaceChar
@@ -793,6 +792,13 @@ rawHtmlBlocks = do
793 let combined = concat htmlBlocks
792 let combined = concat htmlBlocks
794 return $ if last combined == '\n' then init combined else combined
793 return $ if last combined == '\n' then init combined else combined
795
794
795+-- remove markdown="1" attribute
796+stripMarkdownAttribute :: String -> String
797+stripMarkdownAttribute s = renderTags' $ map filterAttrib $ parseTags s
798+ where filterAttrib (TagOpen t as) = TagOpen t
799+ [(k,v) | (k,v) <- as, k /= "markdown"]
800+ filterAttrib x = x
801+
796--
802--
797-- Tables
803-- Tables
798--
804--
src/Text/Pandoc/SelfContained.hs+1−12
@@ -42,7 +42,7 @@ import System.FilePath (takeExtension, dropExtension, takeDirectory, (</>))
42import Data.Char (toLower, isAscii, isAlphaNum)
42import Data.Char (toLower, isAscii, isAlphaNum)
43import Codec.Compression.GZip as Gzip
43import Codec.Compression.GZip as Gzip
44import qualified Data.ByteString.Lazy as L
44import qualified Data.ByteString.Lazy as L
45−import Text.Pandoc.Shared (findDataFile)
45+import Text.Pandoc.Shared (findDataFile, renderTags')
46import Text.Pandoc.MIME (getMimeType)
46import Text.Pandoc.MIME (getMimeType)
47import System.Directory (doesFileExist)
47import System.Directory (doesFileExist)
48
48
@@ -163,14 +163,3 @@ makeSelfContained userdata inp = do
163 out' <- mapM (convertTag userdata) tags
163 out' <- mapM (convertTag userdata) tags
164 return $ renderTags' out'
164 return $ renderTags' out'
165
165
166−-- repeated from HTML reader:
167−renderTags' :: [Tag String] -> String
168−renderTags' = renderTagsOptions
169− renderOptions{ optMinimize = \x ->
170− let y = map toLower x
171− in y == "hr" || y == "br" ||
172− y == "img" || y == "meta" ||
173− y == "link"
174− , optRawTag = \x ->
175− let y = map toLower x
176− in y == "script" || y == "style" }
src/Text/Pandoc/Shared.hs+22
@@ -59,6 +59,8 @@ module Text.Pandoc.Shared (
59 uniqueIdent,
59 uniqueIdent,
60 isHeaderBlock,
60 isHeaderBlock,
61 headerShift,
61 headerShift,
62+ -- * TagSoup HTML handling
63+ renderTags',
62 -- * File handling
64 -- * File handling
63 inDirectory,
65 inDirectory,
64 findDataFile,
66 findDataFile,
@@ -89,6 +91,8 @@ import Text.Pandoc.Pretty (charWidth)
89import System.Locale (defaultTimeLocale)
91import System.Locale (defaultTimeLocale)
90import Data.Time
92import Data.Time
91import System.IO (stderr)
93import System.IO (stderr)
94+import Text.HTML.TagSoup (renderTagsOptions, RenderOptions(..), Tag(..),
95+ renderOptions)
92
96
93--
97--
94-- List processing
98-- List processing
@@ -448,6 +452,22 @@ headerShift n = bottomUp shift
448 shift (Header level inner) = Header (level + n) inner
452 shift (Header level inner) = Header (level + n) inner
449 shift x = x
453 shift x = x
450
454
455+--
456+-- TagSoup HTML handling
457+--
458+
459+-- | Render HTML tags.
460+renderTags' :: [Tag String] -> String
461+renderTags' = renderTagsOptions
462+ renderOptions{ optMinimize = \x ->
463+ let y = map toLower x
464+ in y == "hr" || y == "br" ||
465+ y == "img" || y == "meta" ||
466+ y == "link"
467+ , optRawTag = \x ->
468+ let y = map toLower x
469+ in y == "script" || y == "style" }
470+
451--
471--
452-- File handling
472-- File handling
453--
473--
@@ -501,3 +521,5 @@ safeRead s = case reads s of
501 (d,x):_
521 (d,x):_
502 | all isSpace x -> return d
522 | all isSpace x -> return d
503 _ -> fail $ "Could not read `" ++ s ++ "'"
523 _ -> fail $ "Could not read `" ++ s ++ "'"
524+
525+