diff options
Diffstat (limited to 'Text')
-rw-r--r-- | Text/Pandoc/Readers/HTML.hs | 6 | ||||
-rw-r--r-- | Text/Pandoc/Readers/Markdown.hs | 12 | ||||
-rw-r--r-- | Text/Pandoc/Readers/RST.hs | 6 | ||||
-rw-r--r-- | Text/Pandoc/Shared.hs | 26 | ||||
-rw-r--r-- | Text/Pandoc/Writers/ConTeXt.hs | 6 | ||||
-rw-r--r-- | Text/Pandoc/Writers/Docbook.hs | 4 | ||||
-rw-r--r-- | Text/Pandoc/Writers/HTML.hs | 4 | ||||
-rw-r--r-- | Text/Pandoc/Writers/LaTeX.hs | 4 | ||||
-rw-r--r-- | Text/Pandoc/Writers/Man.hs | 8 | ||||
-rw-r--r-- | Text/Pandoc/Writers/Markdown.hs | 4 | ||||
-rw-r--r-- | Text/Pandoc/Writers/OpenDocument.hs | 3 | ||||
-rw-r--r-- | Text/Pandoc/Writers/RTF.hs | 6 | ||||
-rw-r--r-- | Text/Pandoc/Writers/S5.hs | 5 |
13 files changed, 44 insertions, 50 deletions
diff --git a/Text/Pandoc/Readers/HTML.hs b/Text/Pandoc/Readers/HTML.hs index 72e54ed23..a9025f0d2 100644 --- a/Text/Pandoc/Readers/HTML.hs +++ b/Text/Pandoc/Readers/HTML.hs @@ -46,7 +46,7 @@ import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.Pandoc.CharacterReferences ( decodeCharacterReferences ) import Data.Maybe ( fromMaybe ) -import Data.List ( takeWhile, dropWhile, isPrefixOf, isSuffixOf ) +import Data.List ( takeWhile, dropWhile, isPrefixOf, isSuffixOf, intercalate ) import Data.Char ( toLower, isAlphaNum ) import Network.URI ( parseURIReference, URI (..) ) @@ -534,7 +534,7 @@ definitionListItem :: GenParser Char ParserState ([Inline], [Block]) definitionListItem = try $ do terms <- sepEndBy1 (inlinesIn "dt") spaces defs <- sepEndBy1 (blocksIn "dd") spaces - let term = joinWithSep [LineBreak] terms + let term = intercalate [LineBreak] terms return (term, concat defs) -- @@ -580,7 +580,7 @@ code = try $ do -- remove internal line breaks, leading and trailing space, -- and decode character references return $ Code $ decodeCharacterReferences $ removeLeadingTrailingSpace $ - joinWithSep " " $ lines result + intercalate " " $ lines result rawHtmlInline :: GenParser Char ParserState Inline rawHtmlInline = do diff --git a/Text/Pandoc/Readers/Markdown.hs b/Text/Pandoc/Readers/Markdown.hs index 88ab38fcf..e2a98dd6d 100644 --- a/Text/Pandoc/Readers/Markdown.hs +++ b/Text/Pandoc/Readers/Markdown.hs @@ -32,7 +32,7 @@ module Text.Pandoc.Readers.Markdown ( readMarkdown ) where -import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy, findIndex ) +import Data.List ( transpose, isPrefixOf, isSuffixOf, lookup, sortBy, findIndex, intercalate ) import Data.Ord ( comparing ) import Data.Char ( isAlphaNum, isAlpha, isLower, isDigit ) import Data.Maybe @@ -234,7 +234,7 @@ noteBlock = try $ do optional blanklines endPos <- getPosition -- parse the extracted text, which may contain various block elements: - contents <- parseFromString parseBlocks $ (joinWithSep "\n" raw) ++ "\n\n" + contents <- parseFromString parseBlocks $ (intercalate "\n" raw) ++ "\n\n" let newnote = (ref, contents) st <- getState let oldnotes = stateNotes st @@ -381,7 +381,7 @@ codeBlockDelimited = try $ do (size, attr) <- codeBlockDelimiter Nothing contents <- manyTill anyLine (codeBlockDelimiter (Just size)) blanklines - return $ CodeBlock attr $ joinWithSep "\n" contents + return $ CodeBlock attr $ intercalate "\n" contents codeBlockIndented :: GenParser Char ParserState Block codeBlockIndented = do @@ -414,7 +414,7 @@ blockQuote :: GenParser Char ParserState Block blockQuote = do raw <- emailBlockQuote -- parse the extracted block, which may contain various block elements: - contents <- parseFromString parseBlocks $ (joinWithSep "\n" raw) ++ "\n\n" + contents <- parseFromString parseBlocks $ (intercalate "\n" raw) ++ "\n\n" return $ BlockQuote contents -- @@ -757,7 +757,7 @@ multilineTableHeader = try $ do let rawHeadsList = transpose $ map (\ln -> tail $ splitByIndices (init indices) ln) rawContent - let rawHeads = map (joinWithSep " ") rawHeadsList + let rawHeads = map (intercalate " ") rawHeadsList let aligns = zipWith alignType rawHeadsList lengths return ((map removeLeadingTrailingSpace rawHeads), aligns, indices) @@ -884,7 +884,7 @@ mathInline = try $ do words' <- sepBy1 mathWord (many1 (spaceChar <|> (newline >>~ notFollowedBy' blankline))) char '$' notFollowedBy digit - return $ joinWithSep " " words' + return $ intercalate " " words' emph :: GenParser Char ParserState Inline emph = ((enclosed (char '*') (notFollowedBy' strong >> char '*') inline) <|> diff --git a/Text/Pandoc/Readers/RST.hs b/Text/Pandoc/Readers/RST.hs index 08e55f97d..5533d309f 100644 --- a/Text/Pandoc/Readers/RST.hs +++ b/Text/Pandoc/Readers/RST.hs @@ -33,7 +33,7 @@ module Text.Pandoc.Readers.RST ( import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.ParserCombinators.Parsec -import Data.List ( findIndex, delete ) +import Data.List ( findIndex, delete, intercalate ) -- | Parse reStructuredText string and return Pandoc document. readRST :: ParserState -> String -> Pandoc @@ -144,7 +144,7 @@ fieldListItem indent = try $ do first <- manyTill anyChar newline rest <- option "" $ try $ lookAhead (string indent >> oneOf " \t") >> indentedBlock - return (name, joinWithSep " " (first:(lines rest))) + return (name, intercalate " " (first:(lines rest))) fieldList :: GenParser Char ParserState Block fieldList = try $ do @@ -583,7 +583,7 @@ code :: GenParser Char ParserState Inline code = try $ do string "``" result <- manyTill anyChar (try (string "``")) - return $ Code $ removeLeadingTrailingSpace $ joinWithSep " " $ lines result + return $ Code $ removeLeadingTrailingSpace $ intercalate " " $ lines result emph :: GenParser Char ParserState Inline emph = enclosed (char '*') (char '*') inline >>= diff --git a/Text/Pandoc/Shared.hs b/Text/Pandoc/Shared.hs index 9bb0c35f9..b3682e4b8 100644 --- a/Text/Pandoc/Shared.hs +++ b/Text/Pandoc/Shared.hs @@ -33,7 +33,6 @@ module Text.Pandoc.Shared ( splitBy, splitByIndices, substitute, - joinWithSep, -- * Text processing backslashEscapes, escapeStringUsing, @@ -110,7 +109,7 @@ import Text.PrettyPrint.HughesPJ ( Doc, fsep, ($$), (<>), empty, isEmpty, text ) import qualified Text.PrettyPrint.HughesPJ as PP import Text.Pandoc.CharacterReferences ( characterReference ) import Data.Char ( toLower, toUpper, ord, isLower, isUpper ) -import Data.List ( find, isPrefixOf ) +import Data.List ( find, isPrefixOf, intercalate ) import Control.Monad ( join ) import Network.URI ( parseURI, URI (..), isAllowedInURI ) import System.Directory @@ -145,13 +144,6 @@ substitute target replacement lst = then replacement ++ (substitute target replacement $ drop (length target) lst) else (head lst):(substitute target replacement $ tail lst) --- | Joins a list of lists, separated by another list. -joinWithSep :: [a] -- ^ List to use as separator - -> [[a]] -- ^ Lists to join - -> [a] -joinWithSep _ [] = [] -joinWithSep sep lst = foldr1 (\a b -> a ++ sep ++ b) lst - -- -- Text processing -- @@ -441,7 +433,7 @@ domain :: GenParser Char st [Char] domain = do first <- many1 domainChar dom <- many1 $ try (char '.' >> many1 domainChar ) - return $ joinWithSep "." (first:dom) + return $ intercalate "." (first:dom) -- | Parses an email address; returns string. emailAddress :: GenParser Char st [Char] @@ -732,7 +724,7 @@ indentBy num first str = let (firstLine:restLines) = lines str firstLineIndent = num + first in (replicate firstLineIndent ' ') ++ firstLine ++ "\n" ++ - (joinWithSep "\n" $ map ((replicate num ' ') ++ ) restLines) + (intercalate "\n" $ map ((replicate num ' ') ++ ) restLines) -- | Prettyprint list of Pandoc blocks elements. prettyBlockList :: Int -- ^ Number of spaces to indent list of blocks @@ -740,7 +732,7 @@ prettyBlockList :: Int -- ^ Number of spaces to indent list of blocks -> String prettyBlockList indent [] = indentBy indent 0 "[]" prettyBlockList indent blocks = indentBy indent (-2) $ "[ " ++ - (joinWithSep "\n, " (map prettyBlock blocks)) ++ " ]" + (intercalate "\n, " (map prettyBlock blocks)) ++ " ]" -- | Prettyprint Pandoc block element. prettyBlock :: Block -> String @@ -748,20 +740,20 @@ prettyBlock (BlockQuote blocks) = "BlockQuote\n " ++ (prettyBlockList 2 blocks) prettyBlock (OrderedList attribs blockLists) = "OrderedList " ++ show attribs ++ "\n" ++ indentBy 2 0 ("[ " ++ - (joinWithSep ", " $ map (\blocks -> prettyBlockList 2 blocks) + (intercalate ", " $ map (\blocks -> prettyBlockList 2 blocks) blockLists)) ++ " ]" prettyBlock (BulletList blockLists) = "BulletList\n" ++ - indentBy 2 0 ("[ " ++ (joinWithSep ", " + indentBy 2 0 ("[ " ++ (intercalate ", " (map (\blocks -> prettyBlockList 2 blocks) blockLists))) ++ " ]" prettyBlock (DefinitionList blockLists) = "DefinitionList\n" ++ - indentBy 2 0 ("[" ++ (joinWithSep ",\n" + indentBy 2 0 ("[" ++ (intercalate ",\n" (map (\(term, blocks) -> " (" ++ show term ++ ",\n" ++ indentBy 1 2 (prettyBlockList 2 blocks) ++ " )") blockLists))) ++ " ]" prettyBlock (Table caption aligns widths header rows) = "Table " ++ show caption ++ " " ++ show aligns ++ " " ++ show widths ++ "\n" ++ prettyRow header ++ " [\n" ++ - (joinWithSep ",\n" (map prettyRow rows)) ++ " ]" - where prettyRow cols = indentBy 2 0 ("[ " ++ (joinWithSep ", " + (intercalate ",\n" (map prettyRow rows)) ++ " ]" + where prettyRow cols = indentBy 2 0 ("[ " ++ (intercalate ", " (map (\blocks -> prettyBlockList 2 blocks) cols))) ++ " ]" prettyBlock block = show block diff --git a/Text/Pandoc/Writers/ConTeXt.hs b/Text/Pandoc/Writers/ConTeXt.hs index 3af997374..014751968 100644 --- a/Text/Pandoc/Writers/ConTeXt.hs +++ b/Text/Pandoc/Writers/ConTeXt.hs @@ -31,7 +31,7 @@ module Text.Pandoc.Writers.ConTeXt ( writeConTeXt ) where import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.Printf ( printf ) -import Data.List ( isSuffixOf ) +import Data.List ( isSuffixOf, intercalate ) import Control.Monad.State import Text.PrettyPrint.HughesPJ hiding ( Str ) @@ -87,7 +87,7 @@ contextHeader options (Meta title authors date) = do then "" else if length authors == 1 then stringToConTeXt $ head authors - else stringToConTeXt $ (joinWithSep ", " $ + else stringToConTeXt $ (intercalate ", " $ init authors) ++ " & " ++ last authors let datetext = if date == "" then "" @@ -168,7 +168,7 @@ blockToConTeXt (OrderedList (start, style', delim) lst) = do let specs2Items = filter (not . null) [start', delim', width''] let specs2 = if null specs2Items then "" - else "[" ++ joinWithSep "," specs2Items ++ "]" + else "[" ++ intercalate "," specs2Items ++ "]" let style'' = case style' of DefaultStyle -> orderedListStyles !! level Decimal -> "[n]" diff --git a/Text/Pandoc/Writers/Docbook.hs b/Text/Pandoc/Writers/Docbook.hs index 025727076..3e535a87e 100644 --- a/Text/Pandoc/Writers/Docbook.hs +++ b/Text/Pandoc/Writers/Docbook.hs @@ -32,7 +32,7 @@ import Text.Pandoc.Definition import Text.Pandoc.XML import Text.Pandoc.Shared import Text.Pandoc.Readers.TeXMath -import Data.List ( isPrefixOf, drop ) +import Data.List ( isPrefixOf, drop, intercalate ) import Text.PrettyPrint.HughesPJ hiding ( Str ) -- | Convert list of authors to a docbook <author> section @@ -50,7 +50,7 @@ authorToDocbook name = inTagsIndented "author" $ (firstname, lastname) = case lengthname of 0 -> ("","") 1 -> ("", name) - n -> (joinWithSep " " (take (n-1) namewords), last namewords) + n -> (intercalate " " (take (n-1) namewords), last namewords) in inTagsSimple "firstname" (text $ escapeStringForXML firstname) $$ inTagsSimple "surname" (text $ escapeStringForXML lastname) diff --git a/Text/Pandoc/Writers/HTML.hs b/Text/Pandoc/Writers/HTML.hs index 066a39090..b1e6dabc1 100644 --- a/Text/Pandoc/Writers/HTML.hs +++ b/Text/Pandoc/Writers/HTML.hs @@ -37,7 +37,7 @@ import Text.Pandoc.Readers.TeXMath import Text.Pandoc.Highlighting ( highlightHtml, defaultHighlightingCss ) import Numeric ( showHex ) import Data.Char ( ord, toLower, isAlpha ) -import Data.List ( isPrefixOf, intersperse ) +import Data.List ( isPrefixOf, intercalate ) import qualified Data.Set as S import Control.Monad.State import Text.XHtml.Transitional hiding ( stringToHtml ) @@ -252,7 +252,7 @@ inlineListToIdentifier' (x:xs) = xAsText ++ inlineListToIdentifier' xs where xAsText = case x of Str s -> filter (\c -> c == '-' || not (isPunctuation c)) $ - concat $ intersperse "-" $ words $ map toLower s + intercalate "-" $ words $ map toLower s Emph lst -> inlineListToIdentifier' lst Strikeout lst -> inlineListToIdentifier' lst Superscript lst -> inlineListToIdentifier' lst diff --git a/Text/Pandoc/Writers/LaTeX.hs b/Text/Pandoc/Writers/LaTeX.hs index a13c51b30..8b8f87c57 100644 --- a/Text/Pandoc/Writers/LaTeX.hs +++ b/Text/Pandoc/Writers/LaTeX.hs @@ -31,7 +31,7 @@ module Text.Pandoc.Writers.LaTeX ( writeLaTeX ) where import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.Printf ( printf ) -import Data.List ( (\\), isSuffixOf ) +import Data.List ( (\\), isSuffixOf, intercalate ) import Data.Char ( toLower ) import qualified Data.Set as S import Control.Monad.State @@ -92,7 +92,7 @@ latexHeader options (Meta title authors date) = do then text "\\VerbatimFootnotes % allows verbatim text in footnotes" else empty let authorstext = text $ "\\author{" ++ - joinWithSep "\\\\" (map stringToLaTeX authors) ++ "}" + intercalate "\\\\" (map stringToLaTeX authors) ++ "}" let datetext = if date == "" then empty else text $ "\\date{" ++ stringToLaTeX date ++ "}" diff --git a/Text/Pandoc/Writers/Man.hs b/Text/Pandoc/Writers/Man.hs index 0bd6b92ef..210c7ed07 100644 --- a/Text/Pandoc/Writers/Man.hs +++ b/Text/Pandoc/Writers/Man.hs @@ -32,7 +32,7 @@ module Text.Pandoc.Writers.Man ( writeMan) where import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.Printf ( printf ) -import Data.List ( isPrefixOf, drop, nub, intersperse ) +import Data.List ( isPrefixOf, drop, nub, intersperse, intercalate ) import Text.PrettyPrint.HughesPJ hiding ( Str ) import Control.Monad.State @@ -77,8 +77,8 @@ metaToMan options (Meta title authors date) = do doubleQuotes (text date) <+> hsep extras let foot = case length authors of 0 -> empty - 1 -> text ".SH AUTHOR" $$ (text $ joinWithSep ", " authors) - _ -> text ".SH AUTHORS" $$ (text $ joinWithSep ", " authors) + 1 -> text ".SH AUTHOR" $$ (text $ intercalate ", " authors) + _ -> text ".SH AUTHORS" $$ (text $ intercalate ", " authors) return $ if writerStandalone options then (head', foot) else (empty, empty) @@ -144,7 +144,7 @@ blockToMan opts (Table caption alignments widths headers rows) = modify (\(notes, preprocessors) -> (notes, "t":preprocessors)) let iwidths = map (printf "w(%0.2fn)" . (70 *)) widths -- 78n default width - 8n indent = 70n - let coldescriptions = text $ joinWithSep " " + let coldescriptions = text $ intercalate " " (zipWith (\align width -> aligncode align ++ width) alignments iwidths) ++ "." colheadings <- mapM (blockListToMan opts) headers diff --git a/Text/Pandoc/Writers/Markdown.hs b/Text/Pandoc/Writers/Markdown.hs index d8ad8454f..32ebcf758 100644 --- a/Text/Pandoc/Writers/Markdown.hs +++ b/Text/Pandoc/Writers/Markdown.hs @@ -34,7 +34,7 @@ import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.Pandoc.Blocks import Text.ParserCombinators.Parsec ( parse, GenParser ) -import Data.List ( group, isPrefixOf, drop, find, intersperse ) +import Data.List ( group, isPrefixOf, drop, find, intersperse, intercalate ) import Text.PrettyPrint.HughesPJ hiding ( Str ) import Control.Monad.State @@ -119,7 +119,7 @@ titleToMarkdown opts lst = do authorsToMarkdown :: [String] -> State WriterState Doc authorsToMarkdown [] = return empty authorsToMarkdown lst = return $ - text "% " <> text (joinWithSep ", " (map escapeString lst)) + text "% " <> text (intercalate ", " (map escapeString lst)) dateToMarkdown :: String -> State WriterState Doc dateToMarkdown [] = return empty diff --git a/Text/Pandoc/Writers/OpenDocument.hs b/Text/Pandoc/Writers/OpenDocument.hs index 5ba92368e..a49bed49f 100644 --- a/Text/Pandoc/Writers/OpenDocument.hs +++ b/Text/Pandoc/Writers/OpenDocument.hs @@ -39,6 +39,7 @@ import Control.Applicative ( (<$>) ) import Control.Arrow ( (***), (>>>) ) import Control.Monad.State hiding ( when ) import Data.Char (chr) +import Data.List (intercalate) -- | Auxiliary function to convert Plain block to Para. plainToPara :: Block -> Block @@ -171,7 +172,7 @@ authorToOpenDocument name = (firstname, lastname) = case lengthname of 0 -> ("","") 1 -> ("", name) - n -> (joinWithSep " " (take (n-1) namewords), last namewords) + n -> (intercalate " " (take (n-1) namewords), last namewords) in inParagraphTagsWithStyle "Author" $ (text $ escapeStringForXML firstname) <+> (text $ escapeStringForXML lastname) diff --git a/Text/Pandoc/Writers/RTF.hs b/Text/Pandoc/Writers/RTF.hs index 002ef7edc..fc6cd1bf0 100644 --- a/Text/Pandoc/Writers/RTF.hs +++ b/Text/Pandoc/Writers/RTF.hs @@ -31,7 +31,7 @@ module Text.Pandoc.Writers.RTF ( writeRTF ) where import Text.Pandoc.Definition import Text.Pandoc.Shared import Text.Pandoc.Readers.TeXMath -import Data.List ( isSuffixOf ) +import Data.List ( isSuffixOf, intercalate ) import Data.Char ( ord, isDigit ) -- | Convert Pandoc to a string in rich text format. @@ -82,7 +82,7 @@ stringToRTF = handleUnicode . escapeSpecial -- | Escape things as needed for code block in RTF. codeStringToRTF :: String -> String -codeStringToRTF str = joinWithSep "\\line\n" $ lines (stringToRTF str) +codeStringToRTF str = intercalate "\\line\n" $ lines (stringToRTF str) -- | Make a paragraph with first-line indent, block indent, and space after. rtfParSpaced :: Int -- ^ space after (in twips) @@ -150,7 +150,7 @@ rtfHeader headerText (Meta title authors date) = "\\b \\fs36 " ++ inlineListToRTF title authorstext = if null authors then "" - else rtfPar 0 0 AlignCenter (" " ++ (joinWithSep "\\" $ + else rtfPar 0 0 AlignCenter (" " ++ (intercalate "\\" $ map stringToRTF authors)) datetext = if date == "" then "" diff --git a/Text/Pandoc/Writers/S5.hs b/Text/Pandoc/Writers/S5.hs index 59e1a40ab..6f528503a 100644 --- a/Text/Pandoc/Writers/S5.hs +++ b/Text/Pandoc/Writers/S5.hs @@ -40,12 +40,13 @@ module Text.Pandoc.Writers.S5 ( writeS5String, insertS5Structure ) where -import Text.Pandoc.Shared ( joinWithSep, WriterOptions ) +import Text.Pandoc.Shared ( WriterOptions ) import Text.Pandoc.TH ( contentsOf ) import Text.Pandoc.Writers.HTML ( writeHtml, writeHtmlString ) import Text.Pandoc.Definition import Text.XHtml.Strict import System.FilePath ( (</>) ) +import Data.List ( intercalate ) s5Meta :: String s5Meta = "<!-- configuration parameters -->\n<meta name=\"defaultView\" content=\"slideshow\" />\n<meta name=\"controlVis\" content=\"hidden\" />\n" @@ -148,7 +149,7 @@ insertS5Structure (Pandoc (Meta title' authors date) blocks) = let slides = insertSlides True blocks firstSlide = if not (null title') then [slideStart, (Header 1 title'), - (Header 3 [Str (joinWithSep ", " authors)]), + (Header 3 [Str (intercalate ", " authors)]), (Header 4 [Str date]), slideEnd] else [] newBlocks = (layoutDiv title' date) ++ presentationStart:firstSlide ++ |