git.iko.soy/typeable/pandoc
on master help sign in
Removed module Text.Pandoc.CharacterReferences.

Moved characterReference parser to Text.Pandoc.Parsing. decodeCharacterReferences is now replaced by fromEntities in Text.Pandoc.XML.

commite2c157f86f985e4ab5c702fff87b647f4ae842c8 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 5 Feb 2012, 22:52 (15 years ago) parent9bf6e66
6 files changed+21−80
changelog+5 pandoc.cabal−1 src/Text/Pandoc/CharacterReferences.hs−72 src/Text/Pandoc/Parsing.hs+11−1 src/Text/Pandoc/Readers/Markdown.hs+3−3 src/Text/Pandoc/Writers/HTML.hs+2−3
changelog+5
@@ -418,6 +418,11 @@ pandoc (1.9)
418418
419419 * Removed `Text.Pandoc.S5`, which is no longer needed.
420420
421+ * Removed `Text.Pandoc.CharacterReferences`. Moved
422+ `characterReference` to `Text.Pandoc.Parsing`.
423+ `decodeCharacterReferences` is replaced by `fromEntities`
424+ in `Text.Pandoc.XML`.
425+
421426 * Added `Text.Pandoc.ImageSize`. This is intened for use
422427 in `docx` and `odt` writers, so the size and dpi of images
423428 can be calculated.
pandoc.cabal−1
@@ -233,7 +233,6 @@ Library
233233
234234 Exposed-Modules: Text.Pandoc,
235235 Text.Pandoc.Pretty,
236− Text.Pandoc.CharacterReferences,
237236 Text.Pandoc.Shared,
238237 Text.Pandoc.Parsing,
239238 Text.Pandoc.Highlighting,
src/Text/Pandoc/CharacterReferences.hsdeleted−72
@@ -1,72 +0,0 @@
1−{-
2−Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
3−
4−This program is free software; you can redistribute it and/or modify
5−it under the terms of the GNU General Public License as published by
6−the Free Software Foundation; either version 2 of the License, or
7−(at your option) any later version.
8−
9−This program is distributed in the hope that it will be useful,
10−but WITHOUT ANY WARRANTY; without even the implied warranty of
11−MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12−GNU General Public License for more details.
13−
14−You should have received a copy of the GNU General Public License
15−along with this program; if not, write to the Free Software
16−Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17−-}
18−
19−{- |
20− Module : Text.Pandoc.CharacterReferences
21− Copyright : Copyright (C) 2006-2010 John MacFarlane
22− License : GNU GPL, version 2 or above
23−
24− Maintainer : John MacFarlane <jgm@berkeley.edu>
25− Stability : alpha
26− Portability : portable
27−
28−Functions for parsing character references.
29−-}
30−module Text.Pandoc.CharacterReferences (
31− characterReference,
32− decodeCharacterReferences,
33− ) where
34−import Text.ParserCombinators.Parsec
35−import Text.HTML.TagSoup.Entity ( lookupNamedEntity, lookupNumericEntity )
36−import Data.Maybe ( fromMaybe )
37−
38−-- | Parse character entity.
39−characterReference :: GenParser Char st Char
40−characterReference = try $ do
41− char '&'
42− character <- numRef <|> entity
43− char ';'
44− return character
45−
46−numRef :: GenParser Char st Char
47−numRef = do
48− char '#'
49− num <- hexNum <|> decNum
50− return $ fromMaybe '?' $ lookupNumericEntity num
51−
52−hexNum :: GenParser Char st [Char]
53−hexNum = do
54− x <- oneOf "Xx"
55− num <- many1 hexDigit
56− return (x:num)
57−
58−decNum :: GenParser Char st [Char]
59−decNum = many1 digit
60−
61−entity :: GenParser Char st Char
62−entity = do
63− body <- many1 alphaNum
64− return $ fromMaybe '?' $ lookupNamedEntity body
65−
66−-- | Convert entities in a string to characters.
67−decodeCharacterReferences :: String -> String
68−decodeCharacterReferences str =
69− case parse (many (characterReference <|> anyChar)) str str of
70− Left err -> error $ "\nError: " ++ show err
71− Right result -> result
72−
src/Text/Pandoc/Parsing.hs+11−1
@@ -51,6 +51,7 @@ module Text.Pandoc.Parsing ( (>>~),
5151 failIfStrict,
5252 failUnlessLHS,
5353 escaped,
54+ characterReference,
5455 anyOrderedListMarker,
5556 orderedListMarker,
5657 charRef,
@@ -78,7 +79,6 @@ import Text.Pandoc.Definition
7879import Text.Pandoc.Generic
7980import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
8081import Text.ParserCombinators.Parsec
81−import Text.Pandoc.CharacterReferences ( characterReference )
8282import Data.Char ( toLower, toUpper, ord, isAscii, isAlphaNum, isDigit, isPunctuation )
8383import Data.List ( intercalate, transpose )
8484import Network.URI ( parseURI, URI (..), isAllowedInURI )
@@ -86,6 +86,7 @@ import Control.Monad ( join, liftM, guard )
8686import Text.Pandoc.Shared
8787import qualified Data.Map as M
8888import Text.TeXMath.Macros (applyMacros, Macro, parseMacroDefinitions)
89+import Text.HTML.TagSoup.Entity ( lookupEntity )
8990
9091-- | Like >>, but returns the operation on the left.
9192-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
@@ -337,6 +338,15 @@ escaped :: GenParser Char st Char -- ^ Parser for character to escape
337338 -> GenParser Char st Char
338339escaped parser = try $ char '\\' >> parser
339340
341+-- | Parse character entity.
342+characterReference :: GenParser Char st Char
343+characterReference = try $ do
344+ char '&'
345+ ent <- manyTill nonspaceChar (char ';')
346+ case lookupEntity ent of
347+ Just c -> return c
348+ Nothing -> return '?'
349+
340350-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
341351upperRoman :: GenParser Char st (ListNumberStyle, Int)
342352upperRoman = do
src/Text/Pandoc/Readers/Markdown.hs+3−3
@@ -42,7 +42,7 @@ import Text.Pandoc.Parsing
4242import Text.Pandoc.Readers.LaTeX ( rawLaTeXInline, rawLaTeXBlock )
4343import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockTag,
4444 isTextTag, isCommentTag )
45−import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
45+import Text.Pandoc.XML ( fromEntities )
4646import Text.ParserCombinators.Parsec
4747import Control.Monad (when, liftM, guard, mzero)
4848import Text.HTML.TagSoup
@@ -244,7 +244,7 @@ referenceTitle = try $ do
244244 <|> do delim <- char '\'' <|> char '"'
245245 manyTill litChar (try (char delim >> skipSpaces >>
246246 notFollowedBy (noneOf ")\n")))
247− return $ decodeCharacterReferences tit
247+ return $ fromEntities tit
248248
249249noteMarker :: GenParser Char ParserState [Char]
250250noteMarker = string "[^" >> many1Till (satisfy $ not . isBlank) (char ']')
@@ -1176,7 +1176,7 @@ linkTitle = try $ do
11761176 skipSpaces
11771177 delim <- oneOf "'\""
11781178 tit <- manyTill litChar (try (char delim >> skipSpaces >> eof))
1179− return $ decodeCharacterReferences tit
1179+ return $ fromEntities tit
11801180
11811181link :: GenParser Char ParserState Inline
11821182link = try $ do
src/Text/Pandoc/Writers/HTML.hs+2−3
@@ -31,7 +31,6 @@ Conversion of 'Pandoc' documents to HTML.
3131-}
3232module Text.Pandoc.Writers.HTML ( writeHtml , writeHtmlString ) where
3333import Text.Pandoc.Definition
34−import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
3534import Text.Pandoc.Shared
3635import Text.Pandoc.Templates
3736import Text.Pandoc.Generic
@@ -39,7 +38,7 @@ import Text.Pandoc.Readers.TeXMath
3938import Text.Pandoc.Slides
4039import Text.Pandoc.Highlighting ( highlight, styleToCss,
4140 formatHtmlInline, formatHtmlBlock )
42−import Text.Pandoc.XML (stripTags, escapeStringForXML)
41+import Text.Pandoc.XML (stripTags, escapeStringForXML, fromEntities)
4342import Network.HTTP ( urlEncode )
4443import Numeric ( showHex )
4544import Data.Char ( ord, toLower )
@@ -344,7 +343,7 @@ obfuscateChar char =
344343
345344-- | Obfuscate string using entities.
346345obfuscateString :: String -> String
347−obfuscateString = concatMap obfuscateChar . decodeCharacterReferences
346+obfuscateString = concatMap obfuscateChar . fromEntities
348347
349348attrsToHtml :: WriterOptions -> Attr -> [Attribute]
350349attrsToHtml opts (id',classes',keyvals) =