git.iko.soy/typeable/pandoc
on master help sign in
Removed Text.Regex dependencies by rewriting using plain Haskell:

+ from Text.Pandoc.Writers.RTF + from Text.Pandoc.Writers.HTML + from Main + from pandoc.cabal git-svn-id: https://pandoc.googlecode.com/svn/trunk@1219 788f1e2b-df1e-0410-8736-df70ead52e1b

commitba6981a4a1bf050c9faadd1ddc6388209a66405d authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 9 Feb 2008, 03:21 (19 years ago) parent087739a
4 files changed+59−54
Main.hs+33−37 Text/Pandoc/Writers/HTML.hs+12−5 Text/Pandoc/Writers/RTF.hs+13−11 pandoc.cabal+1−1
Main.hs+33−37
@@ -32,9 +32,9 @@ module Main where
3232import Text.Pandoc
3333import Text.Pandoc.UTF8
3434import Text.Pandoc.Shared ( joinWithSep, HTMLMathMethod (..) )
35−import Text.Regex ( mkRegex, matchRegex )
3635import System.Environment ( getArgs, getProgName, getEnvironment )
3736import System.Exit ( exitWith, ExitCode (..) )
37+import System.FilePath ( takeExtension )
3838import System.Console.GetOpt
3939import System.IO
4040import Data.Maybe ( fromMaybe )
@@ -338,48 +338,44 @@ usageMessage programName options = usageInfo
338338 options
339339
340340-- Determine default reader based on source file extensions
341−defaultReaderName :: [String] -> String
341+defaultReaderName :: [FilePath] -> String
342342defaultReaderName [] = "markdown"
343343defaultReaderName (x:xs) =
344− let x' = map toLower x in
345− case (matchRegex (mkRegex ".*\\.(.*)") x') of
346− Nothing -> defaultReaderName xs -- no extension
347− Just ["xhtml"] -> "html"
348− Just ["html"] -> "html"
349− Just ["htm"] -> "html"
350− Just ["tex"] -> "latex"
351− Just ["latex"] -> "latex"
352− Just ["ltx"] -> "latex"
353− Just ["rst"] -> "rst"
354− Just ["native"] -> "native"
355− Just _ -> "markdown"
344+ case takeExtension (map toLower x) of
345+ ".xhtml" -> "html"
346+ ".html" -> "html"
347+ ".htm" -> "html"
348+ ".tex" -> "latex"
349+ ".latex" -> "latex"
350+ ".ltx" -> "latex"
351+ ".rst" -> "rst"
352+ ".native" -> "native"
353+ _ -> defaultReaderName xs
356354
357355-- Determine default writer based on output file extension
358−defaultWriterName :: String -> String
356+defaultWriterName :: FilePath -> String
359357defaultWriterName "-" = "html" -- no output file
360358defaultWriterName x =
361− let x' = map toLower x in
362− case (matchRegex (mkRegex ".*\\.(.*)") x') of
363− Nothing -> "markdown" -- no extension
364− Just [""] -> "markdown" -- empty extension
365− Just ["tex"] -> "latex"
366− Just ["latex"] -> "latex"
367− Just ["ltx"] -> "latex"
368− Just ["context"] -> "context"
369− Just ["ctx"] -> "context"
370− Just ["rtf"] -> "rtf"
371− Just ["rst"] -> "rst"
372− Just ["s5"] -> "s5"
373− Just ["native"] -> "native"
374− Just ["txt"] -> "markdown"
375− Just ["text"] -> "markdown"
376− Just ["md"] -> "markdown"
377− Just ["markdown"] -> "markdown"
378− Just ["db"] -> "docbook"
379− Just ["xml"] -> "docbook"
380− Just ["sgml"] -> "docbook"
381− Just [[x]] | x `elem` ['1'..'9'] -> "man"
382− Just _ -> "html"
359+ case takeExtension (map toLower x) of
360+ "" -> "markdown" -- empty extension
361+ "tex" -> "latex"
362+ "latex" -> "latex"
363+ "ltx" -> "latex"
364+ "context" -> "context"
365+ "ctx" -> "context"
366+ "rtf" -> "rtf"
367+ "rst" -> "rst"
368+ "s5" -> "s5"
369+ "native" -> "native"
370+ "txt" -> "markdown"
371+ "text" -> "markdown"
372+ "md" -> "markdown"
373+ "markdown" -> "markdown"
374+ "db" -> "docbook"
375+ "xml" -> "docbook"
376+ "sgml" -> "docbook"
377+ [x] | x `elem` ['1'..'9'] -> "man"
378+ _ -> "html"
383379
384380main = do
385381
Text/Pandoc/Writers/HTML.hs+12−5
@@ -33,7 +33,6 @@ import Text.Pandoc.ASCIIMathML
3333import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
3434import Text.Pandoc.Shared
3535import Text.Pandoc.Readers.TeXMath
36−import Text.Regex ( mkRegex, matchRegex )
3736import Numeric ( showHex )
3837import Data.Char ( ord, toLower, isAlpha )
3938import Data.List ( isPrefixOf, intersperse, find )
@@ -162,13 +161,21 @@ footnoteSection opts notes =
162161 then noHtml
163162 else thediv ! [theclass "footnotes"] $ hr +++ (olist << notes)
164163
164+
165+-- | Parse a mailto link; return Just (name, domain) or Nothing.
166+parseMailto :: String -> Maybe (String, String)
167+parseMailto ('m':'a':'i':'l':'t':'o':':':address) =
168+ let (name, rest) = span (/='@') address
169+ domain = drop 1 rest
170+ in Just (name, domain)
171+parseMailto _ = Nothing
172+
165173-- | Obfuscate a "mailto:" link using Javascript.
166174obfuscateLink :: WriterOptions -> String -> String -> Html
167175obfuscateLink opts text src =
168− let emailRegex = mkRegex "^mailto:([^@]*)@(.*)$"
169− src' = map toLower src
170− in case (matchRegex emailRegex src') of
171− (Just [name, domain]) ->
176+ let src' = map toLower src
177+ in case parseMailto src' of
178+ (Just (name, domain)) ->
172179 let domain' = substitute "." " dot " domain
173180 at' = obfuscateChar '@'
174181 (linkText, altText) =
Text/Pandoc/Writers/RTF.hs+13−11
@@ -31,9 +31,8 @@ module Text.Pandoc.Writers.RTF ( writeRTF ) where
3131import Text.Pandoc.Definition
3232import Text.Pandoc.Shared
3333import Text.Pandoc.Readers.TeXMath
34−import Text.Regex ( matchRegexAll, mkRegex )
3534import Data.List ( isSuffixOf )
36−import Data.Char ( ord )
35+import Data.Char ( ord, isDigit )
3736
3837-- | Convert Pandoc to a string in rich text format.
3938writeRTF :: WriterOptions -> Pandoc -> String
@@ -230,15 +229,18 @@ listItemToRTF alignment indent marker [] =
230229 rtfCompact (indent + listIncrement) (0 - listIncrement) alignment
231230 (marker ++ "\\tx" ++ (show listIncrement) ++ "\\tab ")
232231listItemToRTF alignment indent marker list =
233− let (first:rest) = map (blockToRTF (indent + listIncrement) alignment) list in
234− -- insert the list marker into the (processed) first block
235− let modFirst = case matchRegexAll (mkRegex "\\\\fi-?[0-9]+") first of
236− Just (before, matched, after, _) ->
237− before ++ "\\fi" ++ show (0 - listIncrement) ++
238− " " ++ marker ++ "\\tx" ++
239− show listIncrement ++ "\\tab" ++ after
240− Nothing -> first in
241− modFirst ++ concat rest
232+ let (first:rest) = map (blockToRTF (indent + listIncrement) alignment) list
233+ listMarker = "\\fi" ++ show (0 - listIncrement) ++ " " ++ marker ++ "\\tx" ++
234+ show listIncrement ++ "\\tab"
235+ insertListMarker ('\\':'f':'i':'-':d:xs) | isDigit d =
236+ listMarker ++ dropWhile isDigit xs
237+ insertListMarker ('\\':'f':'i':d:xs) | isDigit d =
238+ listMarker ++ dropWhile isDigit xs
239+ insertListMarker (x:xs) =
240+ x : insertListMarker xs
241+ insertListmarker [] = []
242+ -- insert the list marker into the (processed) first block
243+ in insertListMarker first ++ concat rest
242244
243245-- | Convert definition list item (label, list of blocks) to RTF.
244246definitionListItemToRTF :: Alignment -- ^ alignment
pandoc.cabal+1−1
@@ -41,7 +41,7 @@ Library
4141 Build-Depends: base >= 3, pretty, containers
4242 else
4343 Build-Depends: base < 3
44− Build-Depends: parsec, xhtml, mtl, regex-compat, network, highlighting-kate
44+ Build-Depends: parsec, xhtml, mtl, network, filepath, highlighting-kate
4545 Hs-Source-Dirs: .
4646 Exposed-Modules: Text.Pandoc,
4747 Text.Pandoc.Blocks,