git.iko.soy/typeable/pandoc
on master help sign in
Changed encodeUTF8 to toUTF8, decodeUTF8 to fromUTF8,
30375bbfiddlosopher
src/Main.hs+5−7
@@ -30,8 +30,8 @@ writers.
30-}
30-}
31module Main where
31module Main where
32import Text.Pandoc
32import Text.Pandoc
33−import Text.Pandoc.UTF8 ( encodeUTF8, decodeUTF8 )
33+import Text.Pandoc.UTF8
34−import Text.Pandoc.ASCIIMathML ( asciiMathMLScript )
34+import Text.Pandoc.ASCIIMathML
35import Text.Pandoc.Shared ( joinWithSep, tabsToSpaces )
35import Text.Pandoc.Shared ( joinWithSep, tabsToSpaces )
36import Text.Regex ( mkRegex, matchRegex )
36import Text.Regex ( mkRegex, matchRegex )
37import System.Environment ( getArgs, getProgName, getEnvironment )
37import System.Environment ( getArgs, getProgName, getEnvironment )
@@ -439,9 +439,7 @@ main = do
439 Nothing -> stateColumns defaultParserState
439 Nothing -> stateColumns defaultParserState
440
440
441 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
441 let tabFilter = if preserveTabs then id else (tabsToSpaces tabStop)
442− let addBlank str = str
443 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
442 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
444− let filter = tabFilter . addBlank . removeCRs
445 let startParserState =
443 let startParserState =
446 defaultParserState { stateParseRaw = parseRaw,
444 defaultParserState { stateParseRaw = parseRaw,
447 stateTabStop = tabStop,
445 stateTabStop = tabStop,
@@ -475,10 +473,10 @@ main = do
475 writerStrictMarkdown = strict,
473 writerStrictMarkdown = strict,
476 writerReferenceLinks = referenceLinks }
474 writerReferenceLinks = referenceLinks }
477
475
478− (readSources sources) >>= (hPutStr output . encodeUTF8 .
476+ (readSources sources) >>= (hPutStr output . toUTF8 .
479 (writer writerOptions) .
477 (writer writerOptions) .
480− (reader startParserState) . filter .
478+ (reader startParserState) . tabFilter .
481− decodeUTF8 . (joinWithSep "\n")) >>
479+ removeCRs . fromUTF8 . (joinWithSep "\n")) >>
482 hClose output
480 hClose output
483
481
484 where
482 where
src/Text/Pandoc.hs+2−2
@@ -38,9 +38,9 @@ inline links:
38> import Text.Pandoc
38> import Text.Pandoc
39>
39>
40> markdownToRST :: String -> String
40> markdownToRST :: String -> String
41−> markdownToRST = encodeUTF8 .
41+> markdownToRST = toUTF8 .
42> (writeRST defaultWriterOptions {writerReferenceLinks = True}) .
42> (writeRST defaultWriterOptions {writerReferenceLinks = True}) .
43−> (readMarkdown defaultParserState) . decodeUTF8
43+> (readMarkdown defaultParserState) . fromUTF8
44>
44>
45> main = interact markdownToRST
45> main = interact markdownToRST
46
46
src/Text/Pandoc/UTF8.hs+16−16
@@ -7,38 +7,38 @@
7-- Modified by Martin Norbaeck
7-- Modified by Martin Norbaeck
8-- to pass illegal UTF-8 sequences through unchanged.
8-- to pass illegal UTF-8 sequences through unchanged.
9module Text.Pandoc.UTF8 (
9module Text.Pandoc.UTF8 (
10− decodeUTF8,
10+ fromUTF8,
11− encodeUTF8
11+ toUTF8
12 ) where
12 ) where
13
13
14-- From the Char module supplied with HBC.
14-- From the Char module supplied with HBC.
15
15
16-- | Take a UTF-8 string and decode it into a Unicode string.
16-- | Take a UTF-8 string and decode it into a Unicode string.
17−decodeUTF8 :: String -> String
17+fromUTF8 :: String -> String
18−decodeUTF8 "" = ""
18+fromUTF8 "" = ""
19−decodeUTF8 (c:c':cs) | '\xc0' <= c && c <= '\xdf' &&
19+fromUTF8 (c:c':cs) | '\xc0' <= c && c <= '\xdf' &&
20− '\x80' <= c' && c' <= '\xbf' =
20+ '\x80' <= c' && c' <= '\xbf' =
21− toEnum ((fromEnum c `mod` 0x20) * 0x40 + fromEnum c' `mod` 0x40) : decodeUTF8 cs
21+ toEnum ((fromEnum c `mod` 0x20) * 0x40 + fromEnum c' `mod` 0x40) : fromUTF8 cs
22−decodeUTF8 (c:c':c'':cs) | '\xe0' <= c && c <= '\xef' &&
22+fromUTF8 (c:c':c'':cs) | '\xe0' <= c && c <= '\xef' &&
23 '\x80' <= c' && c' <= '\xbf' &&
23 '\x80' <= c' && c' <= '\xbf' &&
24 '\x80' <= c'' && c'' <= '\xbf' =
24 '\x80' <= c'' && c'' <= '\xbf' =
25− toEnum ((fromEnum c `mod` 0x10 * 0x1000) + (fromEnum c' `mod` 0x40) * 0x40 + fromEnum c'' `mod` 0x40) : decodeUTF8 cs
25+ toEnum ((fromEnum c `mod` 0x10 * 0x1000) + (fromEnum c' `mod` 0x40) * 0x40 + fromEnum c'' `mod` 0x40) : fromUTF8 cs
26−decodeUTF8 (c:cs) = c : decodeUTF8 cs
26+fromUTF8 (c:cs) = c : fromUTF8 cs
27
27
28-- | Take a Unicode string and encode it as a UTF-8 string.
28-- | Take a Unicode string and encode it as a UTF-8 string.
29−encodeUTF8 :: String -> String
29+toUTF8 :: String -> String
30−encodeUTF8 "" = ""
30+toUTF8 "" = ""
31−encodeUTF8 (c:cs) =
31+toUTF8 (c:cs) =
32 if c > '\x0000' && c < '\x0080' then
32 if c > '\x0000' && c < '\x0080' then
33− c : encodeUTF8 cs
33+ c : toUTF8 cs
34 else if c < toEnum 0x0800 then
34 else if c < toEnum 0x0800 then
35 let i = fromEnum c
35 let i = fromEnum c
36 in toEnum (0xc0 + i `div` 0x40) :
36 in toEnum (0xc0 + i `div` 0x40) :
37 toEnum (0x80 + i `mod` 0x40) :
37 toEnum (0x80 + i `mod` 0x40) :
38− encodeUTF8 cs
38+ toUTF8 cs
39 else
39 else
40 let i = fromEnum c
40 let i = fromEnum c
41 in toEnum (0xe0 + i `div` 0x1000) :
41 in toEnum (0xe0 + i `div` 0x1000) :
42 toEnum (0x80 + (i `mod` 0x1000) `div` 0x40) :
42 toEnum (0x80 + (i `mod` 0x1000) `div` 0x40) :
43 toEnum (0x80 + i `mod` 0x40) :
43 toEnum (0x80 + i `mod` 0x40) :
44− encodeUTF8 cs
44+ toUTF8 cs