Merge pull request #3072 from tarleb/lineblock
Read and write LineBlock elements
This commit is contained in:
commit
4eff607678
35 changed files with 157 additions and 61 deletions
10
pandoc.cabal
10
pandoc.cabal
|
@ -205,8 +205,8 @@ Extra-Source-Files:
|
||||||
tests/lhs-test.html+lhs
|
tests/lhs-test.html+lhs
|
||||||
tests/lhs-test.fragment.html+lhs
|
tests/lhs-test.fragment.html+lhs
|
||||||
tests/pipe-tables.txt
|
tests/pipe-tables.txt
|
||||||
tests/dokuwiki_external_images.dokuwiki
|
tests/dokuwiki_external_images.dokuwiki
|
||||||
tests/dokuwiki_external_images.native
|
tests/dokuwiki_external_images.native
|
||||||
tests/dokuwiki_multiblock_table.dokuwiki
|
tests/dokuwiki_multiblock_table.dokuwiki
|
||||||
tests/dokuwiki_multiblock_table.native
|
tests/dokuwiki_multiblock_table.native
|
||||||
tests/fb2/*.markdown
|
tests/fb2/*.markdown
|
||||||
|
@ -267,7 +267,7 @@ Library
|
||||||
xml >= 1.3.12 && < 1.4,
|
xml >= 1.3.12 && < 1.4,
|
||||||
random >= 1 && < 1.2,
|
random >= 1 && < 1.2,
|
||||||
extensible-exceptions >= 0.1 && < 0.2,
|
extensible-exceptions >= 0.1 && < 0.2,
|
||||||
pandoc-types >= 1.16 && < 1.17,
|
pandoc-types >= 1.17 && < 1.18,
|
||||||
aeson >= 0.7 && < 1.1,
|
aeson >= 0.7 && < 1.1,
|
||||||
tagsoup >= 0.13.7 && < 0.15,
|
tagsoup >= 0.13.7 && < 0.15,
|
||||||
base64-bytestring >= 0.1 && < 1.1,
|
base64-bytestring >= 0.1 && < 1.1,
|
||||||
|
@ -422,7 +422,7 @@ Library
|
||||||
|
|
||||||
Executable pandoc
|
Executable pandoc
|
||||||
Build-Depends: pandoc,
|
Build-Depends: pandoc,
|
||||||
pandoc-types >= 1.16 && < 1.17,
|
pandoc-types >= 1.17 && < 1.18,
|
||||||
base >= 4.2 && <5,
|
base >= 4.2 && <5,
|
||||||
directory >= 1.2 && < 1.3,
|
directory >= 1.2 && < 1.3,
|
||||||
filepath >= 1.1 && < 1.5,
|
filepath >= 1.1 && < 1.5,
|
||||||
|
@ -479,7 +479,7 @@ Test-Suite test-pandoc
|
||||||
Build-Depends: base >= 4.2 && < 5,
|
Build-Depends: base >= 4.2 && < 5,
|
||||||
syb >= 0.1 && < 0.7,
|
syb >= 0.1 && < 0.7,
|
||||||
pandoc,
|
pandoc,
|
||||||
pandoc-types >= 1.16 && < 1.17,
|
pandoc-types >= 1.17 && < 1.18,
|
||||||
bytestring >= 0.9 && < 0.11,
|
bytestring >= 0.9 && < 0.11,
|
||||||
text >= 0.11 && < 1.3,
|
text >= 0.11 && < 1.3,
|
||||||
directory >= 1 && < 1.3,
|
directory >= 1 && < 1.3,
|
||||||
|
|
|
@ -718,11 +718,14 @@ lineBlockLine = try $ do
|
||||||
continuations <- many (try $ char ' ' >> anyLine)
|
continuations <- many (try $ char ' ' >> anyLine)
|
||||||
return $ white ++ unwords (line : continuations)
|
return $ white ++ unwords (line : continuations)
|
||||||
|
|
||||||
|
blankLineBlockLine :: Stream [Char] m Char => ParserT [Char] st m Char
|
||||||
|
blankLineBlockLine = try (char '|' >> blankline)
|
||||||
|
|
||||||
-- | Parses an RST-style line block and returns a list of strings.
|
-- | Parses an RST-style line block and returns a list of strings.
|
||||||
lineBlockLines :: Stream [Char] m Char => ParserT [Char] st m [String]
|
lineBlockLines :: Stream [Char] m Char => ParserT [Char] st m [String]
|
||||||
lineBlockLines = try $ do
|
lineBlockLines = try $ do
|
||||||
lines' <- many1 lineBlockLine
|
lines' <- many1 (lineBlockLine <|> ((:[]) <$> blankLineBlockLine))
|
||||||
skipMany1 $ blankline <|> try (char '|' >> blankline)
|
skipMany1 $ blankline <|> blankLineBlockLine
|
||||||
return lines'
|
return lines'
|
||||||
|
|
||||||
-- | Parse a table using 'headerParser', 'rowParser',
|
-- | Parse a table using 'headerParser', 'rowParser',
|
||||||
|
|
|
@ -592,8 +592,6 @@ checkInMeta p = do
|
||||||
when accepts p
|
when accepts p
|
||||||
return mempty
|
return mempty
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
addMeta :: ToMetaValue a => String -> a -> DB ()
|
addMeta :: ToMetaValue a => String -> a -> DB ()
|
||||||
addMeta field val = modify (setMeta field val)
|
addMeta field val = modify (setMeta field val)
|
||||||
|
|
||||||
|
@ -612,7 +610,7 @@ isBlockElement (Elem e) = qName (elName e) `elem` blocktags
|
||||||
"important","caution","note","tip","warning","qandadiv",
|
"important","caution","note","tip","warning","qandadiv",
|
||||||
"question","answer","abstract","itemizedlist","orderedlist",
|
"question","answer","abstract","itemizedlist","orderedlist",
|
||||||
"variablelist","article","book","table","informaltable",
|
"variablelist","article","book","table","informaltable",
|
||||||
"informalexample",
|
"informalexample", "linegroup",
|
||||||
"screen","programlisting","example","calloutlist"]
|
"screen","programlisting","example","calloutlist"]
|
||||||
isBlockElement _ = False
|
isBlockElement _ = False
|
||||||
|
|
||||||
|
@ -779,6 +777,7 @@ parseBlock (Elem e) =
|
||||||
"informaltable" -> parseTable
|
"informaltable" -> parseTable
|
||||||
"informalexample" -> divWith ("", ["informalexample"], []) <$>
|
"informalexample" -> divWith ("", ["informalexample"], []) <$>
|
||||||
getBlocks e
|
getBlocks e
|
||||||
|
"linegroup" -> lineBlock <$> lineItems
|
||||||
"literallayout" -> codeBlockWithLang
|
"literallayout" -> codeBlockWithLang
|
||||||
"screen" -> codeBlockWithLang
|
"screen" -> codeBlockWithLang
|
||||||
"programlisting" -> codeBlockWithLang
|
"programlisting" -> codeBlockWithLang
|
||||||
|
@ -900,6 +899,7 @@ parseBlock (Elem e) =
|
||||||
let ident = attrValue "id" e
|
let ident = attrValue "id" e
|
||||||
modify $ \st -> st{ dbSectionLevel = n - 1 }
|
modify $ \st -> st{ dbSectionLevel = n - 1 }
|
||||||
return $ headerWith (ident,[],[]) n' headerText <> b
|
return $ headerWith (ident,[],[]) n' headerText <> b
|
||||||
|
lineItems = mapM getInlines $ filterChildren (named "line") e
|
||||||
metaBlock = acceptingMetadata (getBlocks e) >> return mempty
|
metaBlock = acceptingMetadata (getBlocks e) >> return mempty
|
||||||
|
|
||||||
getInlines :: Element -> DB Inlines
|
getInlines :: Element -> DB Inlines
|
||||||
|
|
|
@ -32,7 +32,7 @@ Conversion of markdown-formatted plain text to 'Pandoc' document.
|
||||||
module Text.Pandoc.Readers.Markdown ( readMarkdown,
|
module Text.Pandoc.Readers.Markdown ( readMarkdown,
|
||||||
readMarkdownWithWarnings ) where
|
readMarkdownWithWarnings ) where
|
||||||
|
|
||||||
import Data.List ( transpose, sortBy, findIndex, intersperse, intercalate )
|
import Data.List ( transpose, sortBy, findIndex, intercalate )
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import Data.Scientific (coefficient, base10Exponent)
|
import Data.Scientific (coefficient, base10Exponent)
|
||||||
import Data.Ord ( comparing )
|
import Data.Ord ( comparing )
|
||||||
|
@ -1106,7 +1106,7 @@ lineBlock = try $ do
|
||||||
guardEnabled Ext_line_blocks
|
guardEnabled Ext_line_blocks
|
||||||
lines' <- lineBlockLines >>=
|
lines' <- lineBlockLines >>=
|
||||||
mapM (parseFromString (trimInlinesF . mconcat <$> many inline))
|
mapM (parseFromString (trimInlinesF . mconcat <$> many inline))
|
||||||
return $ B.para <$> (mconcat $ intersperse (return B.linebreak) lines')
|
return $ B.lineBlock <$> sequence lines'
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Tables
|
-- Tables
|
||||||
|
|
|
@ -50,7 +50,7 @@ import Text.Pandoc.Shared ( compactify', compactify'DL )
|
||||||
|
|
||||||
import Control.Monad ( foldM, guard, mzero, void )
|
import Control.Monad ( foldM, guard, mzero, void )
|
||||||
import Data.Char ( isSpace, toLower, toUpper)
|
import Data.Char ( isSpace, toLower, toUpper)
|
||||||
import Data.List ( foldl', intersperse, isPrefixOf )
|
import Data.List ( foldl', isPrefixOf )
|
||||||
import Data.Maybe ( fromMaybe, isNothing )
|
import Data.Maybe ( fromMaybe, isNothing )
|
||||||
import Data.Monoid ((<>))
|
import Data.Monoid ((<>))
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ verseBlock :: String -> OrgParser (F Blocks)
|
||||||
verseBlock blockType = try $ do
|
verseBlock blockType = try $ do
|
||||||
ignHeaders
|
ignHeaders
|
||||||
content <- rawBlockContent blockType
|
content <- rawBlockContent blockType
|
||||||
fmap B.para . mconcat . intersperse (pure B.linebreak)
|
fmap B.lineBlock . sequence
|
||||||
<$> mapM parseVerseLine (lines content)
|
<$> mapM parseVerseLine (lines content)
|
||||||
where
|
where
|
||||||
-- replace initial spaces with nonbreaking spaces to preserve
|
-- replace initial spaces with nonbreaking spaces to preserve
|
||||||
|
|
|
@ -39,7 +39,7 @@ import Text.Pandoc.Shared
|
||||||
import Text.Pandoc.Parsing
|
import Text.Pandoc.Parsing
|
||||||
import Text.Pandoc.Options
|
import Text.Pandoc.Options
|
||||||
import Control.Monad ( when, liftM, guard, mzero )
|
import Control.Monad ( when, liftM, guard, mzero )
|
||||||
import Data.List ( findIndex, intersperse, intercalate,
|
import Data.List ( findIndex, intercalate,
|
||||||
transpose, sort, deleteFirstsBy, isSuffixOf , nub, union)
|
transpose, sort, deleteFirstsBy, isSuffixOf , nub, union)
|
||||||
import Data.Maybe (fromMaybe)
|
import Data.Maybe (fromMaybe)
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
@ -228,7 +228,7 @@ lineBlock :: RSTParser Blocks
|
||||||
lineBlock = try $ do
|
lineBlock = try $ do
|
||||||
lines' <- lineBlockLines
|
lines' <- lineBlockLines
|
||||||
lines'' <- mapM parseInlineFromString lines'
|
lines'' <- mapM parseInlineFromString lines'
|
||||||
return $ B.para (mconcat $ intersperse B.linebreak lines'')
|
return $ B.lineBlock lines''
|
||||||
|
|
||||||
--
|
--
|
||||||
-- paragraph block
|
-- paragraph block
|
||||||
|
|
|
@ -64,6 +64,7 @@ module Text.Pandoc.Shared (
|
||||||
compactify,
|
compactify,
|
||||||
compactify',
|
compactify',
|
||||||
compactify'DL,
|
compactify'DL,
|
||||||
|
linesToPara,
|
||||||
Element (..),
|
Element (..),
|
||||||
hierarchicalize,
|
hierarchicalize,
|
||||||
uniqueIdent,
|
uniqueIdent,
|
||||||
|
@ -630,6 +631,15 @@ compactify'DL items =
|
||||||
| otherwise -> items
|
| otherwise -> items
|
||||||
_ -> items
|
_ -> items
|
||||||
|
|
||||||
|
-- | Combine a list of lines by adding hard linebreaks.
|
||||||
|
combineLines :: [[Inline]] -> [Inline]
|
||||||
|
combineLines = intercalate [LineBreak]
|
||||||
|
|
||||||
|
-- | Convert a list of lines into a paragraph with hard line breaks. This is
|
||||||
|
-- useful e.g. for rudimentary support of LineBlock elements in writers.
|
||||||
|
linesToPara :: [[Inline]] -> Block
|
||||||
|
linesToPara = Para . combineLines
|
||||||
|
|
||||||
isPara :: Block -> Bool
|
isPara :: Block -> Bool
|
||||||
isPara (Para _) = True
|
isPara (Para _) = True
|
||||||
isPara _ = False
|
isPara _ = False
|
||||||
|
@ -1035,6 +1045,7 @@ collapseFilePath = Posix.joinPath . reverse . foldl go [] . splitDirectories
|
||||||
blockToInlines :: Block -> [Inline]
|
blockToInlines :: Block -> [Inline]
|
||||||
blockToInlines (Plain ils) = ils
|
blockToInlines (Plain ils) = ils
|
||||||
blockToInlines (Para ils) = ils
|
blockToInlines (Para ils) = ils
|
||||||
|
blockToInlines (LineBlock lns) = combineLines lns
|
||||||
blockToInlines (CodeBlock attr str) = [Code attr str]
|
blockToInlines (CodeBlock attr str) = [Code attr str]
|
||||||
blockToInlines (RawBlock fmt str) = [RawInline fmt str]
|
blockToInlines (RawBlock fmt str) = [RawInline fmt str]
|
||||||
blockToInlines (BlockQuote blks) = blocksToInlines blks
|
blockToInlines (BlockQuote blks) = blocksToInlines blks
|
||||||
|
|
|
@ -137,6 +137,13 @@ blockToAsciiDoc opts (Para inlines) = do
|
||||||
then text "\\"
|
then text "\\"
|
||||||
else empty
|
else empty
|
||||||
return $ esc <> contents <> blankline
|
return $ esc <> contents <> blankline
|
||||||
|
blockToAsciiDoc opts (LineBlock lns) = do
|
||||||
|
let docify line = if null line
|
||||||
|
then return blankline
|
||||||
|
else inlineListToAsciiDoc opts line
|
||||||
|
let joinWithLinefeeds = nowrap . mconcat . intersperse cr
|
||||||
|
contents <- joinWithLinefeeds <$> mapM docify lns
|
||||||
|
return $ "[verse]" $$ text "--" $$ contents $$ text "--" $$ blankline
|
||||||
blockToAsciiDoc _ (RawBlock f s)
|
blockToAsciiDoc _ (RawBlock f s)
|
||||||
| f == "asciidoc" = return $ text s
|
| f == "asciidoc" = return $ text s
|
||||||
| otherwise = return empty
|
| otherwise = return empty
|
||||||
|
@ -459,4 +466,3 @@ inlineToAsciiDoc opts (Span (ident,_,_) ils) = do
|
||||||
let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
|
let identifier = if (null ident) then empty else ("[[" <> text ident <> "]]")
|
||||||
contents <- inlineListToAsciiDoc opts ils
|
contents <- inlineListToAsciiDoc opts ils
|
||||||
return $ identifier <> contents
|
return $ identifier <> contents
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ module Text.Pandoc.Writers.CommonMark (writeCommonMark) where
|
||||||
|
|
||||||
import Text.Pandoc.Writers.HTML (writeHtmlString)
|
import Text.Pandoc.Writers.HTML (writeHtmlString)
|
||||||
import Text.Pandoc.Definition
|
import Text.Pandoc.Definition
|
||||||
import Text.Pandoc.Shared (isTightList)
|
import Text.Pandoc.Shared (isTightList, linesToPara)
|
||||||
import Text.Pandoc.Templates (renderTemplate')
|
import Text.Pandoc.Templates (renderTemplate')
|
||||||
import Text.Pandoc.Writers.Shared
|
import Text.Pandoc.Writers.Shared
|
||||||
import Text.Pandoc.Options
|
import Text.Pandoc.Options
|
||||||
|
@ -94,6 +94,7 @@ blocksToNodes = foldr blockToNodes []
|
||||||
blockToNodes :: Block -> [Node] -> [Node]
|
blockToNodes :: Block -> [Node] -> [Node]
|
||||||
blockToNodes (Plain xs) = (node PARAGRAPH (inlinesToNodes xs) :)
|
blockToNodes (Plain xs) = (node PARAGRAPH (inlinesToNodes xs) :)
|
||||||
blockToNodes (Para xs) = (node PARAGRAPH (inlinesToNodes xs) :)
|
blockToNodes (Para xs) = (node PARAGRAPH (inlinesToNodes xs) :)
|
||||||
|
blockToNodes (LineBlock lns) = blockToNodes $ linesToPara lns
|
||||||
blockToNodes (CodeBlock (_,classes,_) xs) =
|
blockToNodes (CodeBlock (_,classes,_) xs) =
|
||||||
(node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] :)
|
(node (CODE_BLOCK (T.pack (unwords classes)) (T.pack xs)) [] :)
|
||||||
blockToNodes (RawBlock fmt xs)
|
blockToNodes (RawBlock fmt xs)
|
||||||
|
|
|
@ -163,6 +163,9 @@ blockToConTeXt (Para [Image attr txt (src,'f':'i':'g':':':_)]) = do
|
||||||
blockToConTeXt (Para lst) = do
|
blockToConTeXt (Para lst) = do
|
||||||
contents <- inlineListToConTeXt lst
|
contents <- inlineListToConTeXt lst
|
||||||
return $ contents <> blankline
|
return $ contents <> blankline
|
||||||
|
blockToConTeXt (LineBlock lns) = do
|
||||||
|
doclines <- nowrap . vcat <$> mapM inlineListToConTeXt lns
|
||||||
|
return $ "\\startlines" $$ doclines $$ "\\stoplines" <> blankline
|
||||||
blockToConTeXt (BlockQuote lst) = do
|
blockToConTeXt (BlockQuote lst) = do
|
||||||
contents <- blockListToConTeXt lst
|
contents <- blockListToConTeXt lst
|
||||||
return $ "\\startblockquote" $$ nest 0 contents $$ "\\stopblockquote" <> blankline
|
return $ "\\startblockquote" $$ nest 0 contents $$ "\\stopblockquote" <> blankline
|
||||||
|
@ -467,4 +470,3 @@ fromBcp47 x = fromIso $ head x
|
||||||
fromIso "vi" = "vn"
|
fromIso "vi" = "vn"
|
||||||
fromIso "zh" = "cn"
|
fromIso "zh" = "cn"
|
||||||
fromIso l = l
|
fromIso l = l
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,8 @@ blockToCustom lua (Para [Image attr txt (src,tit)]) =
|
||||||
|
|
||||||
blockToCustom lua (Para inlines) = callfunc lua "Para" inlines
|
blockToCustom lua (Para inlines) = callfunc lua "Para" inlines
|
||||||
|
|
||||||
|
blockToCustom lua (LineBlock linesList) = callfunc lua "LineBlock" linesList
|
||||||
|
|
||||||
blockToCustom lua (RawBlock format str) =
|
blockToCustom lua (RawBlock format str) =
|
||||||
callfunc lua "RawBlock" format str
|
callfunc lua "RawBlock" format str
|
||||||
|
|
||||||
|
|
|
@ -198,6 +198,8 @@ blockToDocbook opts (Para [Image attr txt (src,'f':'i':'g':':':_)]) =
|
||||||
blockToDocbook opts (Para lst)
|
blockToDocbook opts (Para lst)
|
||||||
| hasLineBreaks lst = flush $ nowrap $ inTagsSimple "literallayout" $ inlinesToDocbook opts lst
|
| hasLineBreaks lst = flush $ nowrap $ inTagsSimple "literallayout" $ inlinesToDocbook opts lst
|
||||||
| otherwise = inTagsIndented "para" $ inlinesToDocbook opts lst
|
| otherwise = inTagsIndented "para" $ inlinesToDocbook opts lst
|
||||||
|
blockToDocbook opts (LineBlock lns) =
|
||||||
|
blockToDocbook opts $ linesToPara lns
|
||||||
blockToDocbook opts (BlockQuote blocks) =
|
blockToDocbook opts (BlockQuote blocks) =
|
||||||
inTagsIndented "blockquote" $ blocksToDocbook opts blocks
|
inTagsIndented "blockquote" $ blocksToDocbook opts blocks
|
||||||
blockToDocbook _ (CodeBlock (_,classes,_) str) =
|
blockToDocbook _ (CodeBlock (_,classes,_) str) =
|
||||||
|
@ -385,4 +387,3 @@ idAndRole (id',cls,_) = ident ++ role
|
||||||
role = if null cls
|
role = if null cls
|
||||||
then []
|
then []
|
||||||
else [("role", unwords cls)]
|
else [("role", unwords cls)]
|
||||||
|
|
||||||
|
|
|
@ -275,7 +275,7 @@ writeDocx opts doc@(Pandoc meta _) = do
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
((contents, footnotes), st) <- runStateT
|
((contents, footnotes), st) <- runStateT
|
||||||
(runReaderT
|
(runReaderT
|
||||||
(writeOpenXML opts{writerWrapText = WrapNone} doc')
|
(writeOpenXML opts{writerWrapText = WrapNone} doc')
|
||||||
env)
|
env)
|
||||||
|
@ -446,7 +446,7 @@ writeDocx opts doc@(Pandoc meta _) = do
|
||||||
|
|
||||||
let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
|
let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
|
||||||
map newTextPropToOpenXml newDynamicTextProps ++
|
map newTextPropToOpenXml newDynamicTextProps ++
|
||||||
(styleToOpenXml styleMaps $ writerHighlightStyle opts)
|
(styleToOpenXml styleMaps $ writerHighlightStyle opts)
|
||||||
let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
|
let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
|
||||||
where
|
where
|
||||||
modifyContent
|
modifyContent
|
||||||
|
@ -859,6 +859,7 @@ blockToOpenXML' opts (Para lst) = do
|
||||||
modify $ \s -> s { stFirstPara = False }
|
modify $ \s -> s { stFirstPara = False }
|
||||||
contents <- inlinesToOpenXML opts lst
|
contents <- inlinesToOpenXML opts lst
|
||||||
return [mknode "w:p" [] (paraProps' ++ contents)]
|
return [mknode "w:p" [] (paraProps' ++ contents)]
|
||||||
|
blockToOpenXML' opts (LineBlock lns) = blockToOpenXML opts $ linesToPara lns
|
||||||
blockToOpenXML' _ (RawBlock format str)
|
blockToOpenXML' _ (RawBlock format str)
|
||||||
| format == Format "openxml" = return [ x | Elem x <- parseXML str ]
|
| format == Format "openxml" = return [ x | Elem x <- parseXML str ]
|
||||||
| otherwise = return []
|
| otherwise = return []
|
||||||
|
@ -1032,7 +1033,7 @@ setFirstPara = modify $ \s -> s { stFirstPara = True }
|
||||||
|
|
||||||
-- | Convert an inline element to OpenXML.
|
-- | Convert an inline element to OpenXML.
|
||||||
inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
|
inlineToOpenXML :: WriterOptions -> Inline -> WS [Element]
|
||||||
inlineToOpenXML opts il = withDirection $ inlineToOpenXML' opts il
|
inlineToOpenXML opts il = withDirection $ inlineToOpenXML' opts il
|
||||||
|
|
||||||
inlineToOpenXML' :: WriterOptions -> Inline -> WS [Element]
|
inlineToOpenXML' :: WriterOptions -> Inline -> WS [Element]
|
||||||
inlineToOpenXML' _ (Str str) = formattedString str
|
inlineToOpenXML' _ (Str str) = formattedString str
|
||||||
|
@ -1286,7 +1287,7 @@ withDirection x = do
|
||||||
textProps <- asks envTextProperties
|
textProps <- asks envTextProperties
|
||||||
-- We want to clean all bidirection (bidi) and right-to-left (rtl)
|
-- We want to clean all bidirection (bidi) and right-to-left (rtl)
|
||||||
-- properties from the props first. This is because we don't want
|
-- properties from the props first. This is because we don't want
|
||||||
-- them to stack up.
|
-- them to stack up.
|
||||||
let paraProps' = filter (\e -> (qName . elName) e /= "bidi") paraProps
|
let paraProps' = filter (\e -> (qName . elName) e /= "bidi") paraProps
|
||||||
textProps' = filter (\e -> (qName . elName) e /= "rtl") textProps
|
textProps' = filter (\e -> (qName . elName) e /= "rtl") textProps
|
||||||
if isRTL
|
if isRTL
|
||||||
|
@ -1298,5 +1299,3 @@ withDirection x = do
|
||||||
else flip local x $ \env -> env { envParaProperties = paraProps'
|
else flip local x $ \env -> env { envParaProperties = paraProps'
|
||||||
, envTextProperties = textProps'
|
, envTextProperties = textProps'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ import Text.Pandoc.Options ( WriterOptions(
|
||||||
, writerStandalone
|
, writerStandalone
|
||||||
, writerTemplate
|
, writerTemplate
|
||||||
, writerWrapText), WrapOption(..) )
|
, writerWrapText), WrapOption(..) )
|
||||||
import Text.Pandoc.Shared ( escapeURI, removeFormatting, camelCaseToHyphenated
|
import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting
|
||||||
, trimr, normalize, substitute )
|
, camelCaseToHyphenated, trimr, normalize, substitute )
|
||||||
import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
|
import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
|
||||||
import Text.Pandoc.ImageSize
|
import Text.Pandoc.ImageSize
|
||||||
import Text.Pandoc.Templates ( renderTemplate' )
|
import Text.Pandoc.Templates ( renderTemplate' )
|
||||||
|
@ -147,6 +147,9 @@ blockToDokuWiki opts (Para inlines) = do
|
||||||
then "<HTML><p></HTML>" ++ contents ++ "<HTML></p></HTML>"
|
then "<HTML><p></HTML>" ++ contents ++ "<HTML></p></HTML>"
|
||||||
else contents ++ if null indent then "\n" else ""
|
else contents ++ if null indent then "\n" else ""
|
||||||
|
|
||||||
|
blockToDokuWiki opts (LineBlock lns) =
|
||||||
|
blockToDokuWiki opts $ linesToPara lns
|
||||||
|
|
||||||
blockToDokuWiki _ (RawBlock f str)
|
blockToDokuWiki _ (RawBlock f str)
|
||||||
| f == Format "dokuwiki" = return str
|
| f == Format "dokuwiki" = return str
|
||||||
-- See https://www.dokuwiki.org/wiki:syntax
|
-- See https://www.dokuwiki.org/wiki:syntax
|
||||||
|
|
|
@ -46,7 +46,8 @@ import qualified Text.XML.Light.Cursor as XC
|
||||||
|
|
||||||
import Text.Pandoc.Definition
|
import Text.Pandoc.Definition
|
||||||
import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
|
import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..), def)
|
||||||
import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize)
|
import Text.Pandoc.Shared (orderedListMarkers, isHeaderBlock, capitalize,
|
||||||
|
linesToPara)
|
||||||
|
|
||||||
-- | Data to be written at the end of the document:
|
-- | Data to be written at the end of the document:
|
||||||
-- (foot)notes, URLs, references, images.
|
-- (foot)notes, URLs, references, images.
|
||||||
|
@ -323,6 +324,7 @@ blockToXml (RawBlock _ s) = return . spaceBeforeAfter .
|
||||||
map (el "p" . el "code") . lines $ s
|
map (el "p" . el "code") . lines $ s
|
||||||
blockToXml (Div _ bs) = cMapM blockToXml bs
|
blockToXml (Div _ bs) = cMapM blockToXml bs
|
||||||
blockToXml (BlockQuote bs) = liftM (list . el "cite") $ cMapM blockToXml bs
|
blockToXml (BlockQuote bs) = liftM (list . el "cite") $ cMapM blockToXml bs
|
||||||
|
blockToXml (LineBlock lns) = blockToXml $ linesToPara lns
|
||||||
blockToXml (OrderedList a bss) = do
|
blockToXml (OrderedList a bss) = do
|
||||||
state <- get
|
state <- get
|
||||||
let pmrk = parentListMarker state
|
let pmrk = parentListMarker state
|
||||||
|
|
|
@ -463,6 +463,13 @@ blockToHtml opts (Para [Image attr txt (s,'f':'i':'g':':':tit)]) = do
|
||||||
blockToHtml opts (Para lst) = do
|
blockToHtml opts (Para lst) = do
|
||||||
contents <- inlineListToHtml opts lst
|
contents <- inlineListToHtml opts lst
|
||||||
return $ H.p contents
|
return $ H.p contents
|
||||||
|
blockToHtml opts (LineBlock lns) =
|
||||||
|
if writerWrapText opts == WrapNone
|
||||||
|
then blockToHtml opts $ linesToPara lns
|
||||||
|
else do
|
||||||
|
let lf = preEscapedString "\n"
|
||||||
|
htmlLines <- mconcat . intersperse lf <$> mapM (inlineListToHtml opts) lns
|
||||||
|
return $ H.div ! A.style "white-space: pre-line;" $ htmlLines
|
||||||
blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
|
blockToHtml opts (Div attr@(ident, classes, kvs) bs) = do
|
||||||
let speakerNotes = "notes" `elem` classes
|
let speakerNotes = "notes" `elem` classes
|
||||||
-- we don't want incremental output inside speaker notes, see #1394
|
-- we don't want incremental output inside speaker notes, see #1394
|
||||||
|
@ -807,7 +814,7 @@ inlineToHtml opts inline =
|
||||||
let brtag = if writerHtml5 opts then H5.br else H.br
|
let brtag = if writerHtml5 opts then H5.br else H.br
|
||||||
return $ case t of
|
return $ case t of
|
||||||
InlineMath -> m
|
InlineMath -> m
|
||||||
DisplayMath -> brtag >> m >> brtag
|
DisplayMath -> brtag >> m >> brtag
|
||||||
(RawInline f str)
|
(RawInline f str)
|
||||||
| f == Format "html" -> return $ preEscapedString str
|
| f == Format "html" -> return $ preEscapedString str
|
||||||
| otherwise -> return mempty
|
| otherwise -> return mempty
|
||||||
|
|
|
@ -108,6 +108,8 @@ blockToHaddock opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
|
||||||
blockToHaddock opts (Para inlines) =
|
blockToHaddock opts (Para inlines) =
|
||||||
-- TODO: if it contains linebreaks, we need to use a @...@ block
|
-- TODO: if it contains linebreaks, we need to use a @...@ block
|
||||||
(<> blankline) `fmap` blockToHaddock opts (Plain inlines)
|
(<> blankline) `fmap` blockToHaddock opts (Plain inlines)
|
||||||
|
blockToHaddock opts (LineBlock lns) =
|
||||||
|
blockToHaddock opts $ linesToPara lns
|
||||||
blockToHaddock _ (RawBlock f str)
|
blockToHaddock _ (RawBlock f str)
|
||||||
| f == "haddock" = do
|
| f == "haddock" = do
|
||||||
return $ text str <> text "\n"
|
return $ text str <> text "\n"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
{- |
|
{- |
|
||||||
Module : Text.Pandoc.Writers.ICML
|
Module : Text.Pandoc.Writers.ICML
|
||||||
Copyright : Copyright (C) 2013 github.com/mb21
|
Copyright : Copyright (C) 2013-2016 github.com/mb21
|
||||||
License : GNU GPL, version 2 or above
|
License : GNU GPL, version 2 or above
|
||||||
|
|
||||||
Stability : alpha
|
Stability : alpha
|
||||||
|
@ -18,7 +18,7 @@ import Text.Pandoc.Definition
|
||||||
import Text.Pandoc.XML
|
import Text.Pandoc.XML
|
||||||
import Text.Pandoc.Readers.TeXMath (texMathToInlines)
|
import Text.Pandoc.Readers.TeXMath (texMathToInlines)
|
||||||
import Text.Pandoc.Writers.Shared
|
import Text.Pandoc.Writers.Shared
|
||||||
import Text.Pandoc.Shared (splitBy, fetchItem, warn)
|
import Text.Pandoc.Shared (linesToPara, splitBy, fetchItem, warn)
|
||||||
import Text.Pandoc.Options
|
import Text.Pandoc.Options
|
||||||
import Text.Pandoc.Templates (renderTemplate')
|
import Text.Pandoc.Templates (renderTemplate')
|
||||||
import Text.Pandoc.Pretty
|
import Text.Pandoc.Pretty
|
||||||
|
@ -297,6 +297,8 @@ blockToICML opts style (Para img@[Image _ txt (_,'f':'i':'g':':':_)]) = do
|
||||||
caption <- parStyle opts (imgCaptionName:style) txt
|
caption <- parStyle opts (imgCaptionName:style) txt
|
||||||
return $ intersperseBrs [figure, caption]
|
return $ intersperseBrs [figure, caption]
|
||||||
blockToICML opts style (Para lst) = parStyle opts (paragraphName:style) lst
|
blockToICML opts style (Para lst) = parStyle opts (paragraphName:style) lst
|
||||||
|
blockToICML opts style (LineBlock lns) =
|
||||||
|
blockToICML opts style $ linesToPara lns
|
||||||
blockToICML opts style (CodeBlock _ str) = parStyle opts (codeBlockName:style) $ [Str str]
|
blockToICML opts style (CodeBlock _ str) = parStyle opts (codeBlockName:style) $ [Str str]
|
||||||
blockToICML _ _ (RawBlock f str)
|
blockToICML _ _ (RawBlock f str)
|
||||||
| f == Format "icml" = return $ text str
|
| f == Format "icml" = return $ text str
|
||||||
|
|
|
@ -437,6 +437,8 @@ blockToLaTeX (Para [Str ".",Space,Str ".",Space,Str "."]) = do
|
||||||
else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
|
else inlineListToLaTeX [Str ".",Space,Str ".",Space,Str "."]
|
||||||
blockToLaTeX (Para lst) =
|
blockToLaTeX (Para lst) =
|
||||||
inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
|
inlineListToLaTeX $ dropWhile isLineBreakOrSpace lst
|
||||||
|
blockToLaTeX (LineBlock lns) = do
|
||||||
|
blockToLaTeX $ linesToPara lns
|
||||||
blockToLaTeX (BlockQuote lst) = do
|
blockToLaTeX (BlockQuote lst) = do
|
||||||
beamer <- writerBeamer `fmap` gets stOptions
|
beamer <- writerBeamer `fmap` gets stOptions
|
||||||
case lst of
|
case lst of
|
||||||
|
|
|
@ -171,6 +171,8 @@ blockToMan opts (Para inlines) = do
|
||||||
contents <- liftM vcat $ mapM (inlineListToMan opts) $
|
contents <- liftM vcat $ mapM (inlineListToMan opts) $
|
||||||
splitSentences inlines
|
splitSentences inlines
|
||||||
return $ text ".PP" $$ contents
|
return $ text ".PP" $$ contents
|
||||||
|
blockToMan opts (LineBlock lns) =
|
||||||
|
blockToMan opts $ linesToPara lns
|
||||||
blockToMan _ (RawBlock f str)
|
blockToMan _ (RawBlock f str)
|
||||||
| f == Format "man" = return $ text str
|
| f == Format "man" = return $ text str
|
||||||
| otherwise = return empty
|
| otherwise = return empty
|
||||||
|
@ -367,4 +369,3 @@ inlineToMan _ (Note contents) = do
|
||||||
notes <- liftM stNotes get
|
notes <- liftM stNotes get
|
||||||
let ref = show $ (length notes)
|
let ref = show $ (length notes)
|
||||||
return $ char '[' <> text ref <> char ']'
|
return $ char '[' <> text ref <> char ']'
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ instance Default WriterEnv
|
||||||
, envRefShortcutable = True
|
, envRefShortcutable = True
|
||||||
, envBlockLevel = 0
|
, envBlockLevel = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
data WriterState = WriterState { stNotes :: Notes
|
data WriterState = WriterState { stNotes :: Notes
|
||||||
, stRefs :: Refs
|
, stRefs :: Refs
|
||||||
, stIds :: Set.Set String
|
, stIds :: Set.Set String
|
||||||
|
@ -390,6 +390,12 @@ blockToMarkdown' opts (Para [Image attr alt (src,'f':'i':'g':':':tit)]) =
|
||||||
blockToMarkdown opts (Para [Image attr alt (src,tit)])
|
blockToMarkdown opts (Para [Image attr alt (src,tit)])
|
||||||
blockToMarkdown' opts (Para inlines) =
|
blockToMarkdown' opts (Para inlines) =
|
||||||
(<> blankline) `fmap` blockToMarkdown opts (Plain inlines)
|
(<> blankline) `fmap` blockToMarkdown opts (Plain inlines)
|
||||||
|
blockToMarkdown' opts (LineBlock lns) =
|
||||||
|
if isEnabled Ext_line_blocks opts
|
||||||
|
then do
|
||||||
|
mdLines <- mapM (inlineListToMarkdown opts) lns
|
||||||
|
return $ (vcat $ map (hang 2 (text "| ")) mdLines) <> blankline
|
||||||
|
else blockToMarkdown opts $ linesToPara lns
|
||||||
blockToMarkdown' opts (RawBlock f str)
|
blockToMarkdown' opts (RawBlock f str)
|
||||||
| f == "markdown" = return $ text str <> text "\n"
|
| f == "markdown" = return $ text str <> text "\n"
|
||||||
| f == "html" && isEnabled Ext_raw_html opts = do
|
| f == "html" && isEnabled Ext_raw_html opts = do
|
||||||
|
|
|
@ -120,6 +120,9 @@ blockToMediaWiki (Para inlines) = do
|
||||||
then "<p>" ++ contents ++ "</p>"
|
then "<p>" ++ contents ++ "</p>"
|
||||||
else contents ++ if null lev then "\n" else ""
|
else contents ++ if null lev then "\n" else ""
|
||||||
|
|
||||||
|
blockToMediaWiki (LineBlock lns) =
|
||||||
|
blockToMediaWiki $ linesToPara lns
|
||||||
|
|
||||||
blockToMediaWiki (RawBlock f str)
|
blockToMediaWiki (RawBlock f str)
|
||||||
| f == Format "mediawiki" = return str
|
| f == Format "mediawiki" = return str
|
||||||
| f == Format "html" = return str
|
| f == Format "html" = return str
|
||||||
|
|
|
@ -45,6 +45,8 @@ prettyList ds =
|
||||||
|
|
||||||
-- | Prettyprint Pandoc block element.
|
-- | Prettyprint Pandoc block element.
|
||||||
prettyBlock :: Block -> Doc
|
prettyBlock :: Block -> Doc
|
||||||
|
prettyBlock (LineBlock lines') =
|
||||||
|
"LineBlock" $$ prettyList (map (text . show) lines')
|
||||||
prettyBlock (BlockQuote blocks) =
|
prettyBlock (BlockQuote blocks) =
|
||||||
"BlockQuote" $$ prettyList (map prettyBlock blocks)
|
"BlockQuote" $$ prettyList (map prettyBlock blocks)
|
||||||
prettyBlock (OrderedList attribs blockLists) =
|
prettyBlock (OrderedList attribs blockLists) =
|
||||||
|
|
|
@ -33,6 +33,7 @@ module Text.Pandoc.Writers.OpenDocument ( writeOpenDocument ) where
|
||||||
import Text.Pandoc.Definition
|
import Text.Pandoc.Definition
|
||||||
import Text.Pandoc.Options
|
import Text.Pandoc.Options
|
||||||
import Text.Pandoc.XML
|
import Text.Pandoc.XML
|
||||||
|
import Text.Pandoc.Shared (linesToPara)
|
||||||
import Text.Pandoc.Templates (renderTemplate')
|
import Text.Pandoc.Templates (renderTemplate')
|
||||||
import Text.Pandoc.Readers.TeXMath
|
import Text.Pandoc.Readers.TeXMath
|
||||||
import Text.Pandoc.Pretty
|
import Text.Pandoc.Pretty
|
||||||
|
@ -291,6 +292,7 @@ blockToOpenDocument o bs
|
||||||
| Para b <- bs = if null b
|
| Para b <- bs = if null b
|
||||||
then return empty
|
then return empty
|
||||||
else inParagraphTags =<< inlinesToOpenDocument o b
|
else inParagraphTags =<< inlinesToOpenDocument o b
|
||||||
|
| LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
|
||||||
| Div _ xs <- bs = blocksToOpenDocument o xs
|
| Div _ xs <- bs = blocksToOpenDocument o xs
|
||||||
| Header i _ b <- bs = setFirstPara >>
|
| Header i _ b <- bs = setFirstPara >>
|
||||||
(inHeaderTags i =<< inlinesToOpenDocument o b)
|
(inHeaderTags i =<< inlinesToOpenDocument o b)
|
||||||
|
|
|
@ -164,6 +164,17 @@ blockToOrg (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
|
||||||
blockToOrg (Para inlines) = do
|
blockToOrg (Para inlines) = do
|
||||||
contents <- inlineListToOrg inlines
|
contents <- inlineListToOrg inlines
|
||||||
return $ contents <> blankline
|
return $ contents <> blankline
|
||||||
|
blockToOrg (LineBlock lns) = do
|
||||||
|
let splitStanza [] = []
|
||||||
|
splitStanza xs = case break (== mempty) xs of
|
||||||
|
(l, []) -> l : []
|
||||||
|
(l, _:r) -> l : splitStanza r
|
||||||
|
let joinWithLinefeeds = nowrap . mconcat . intersperse cr
|
||||||
|
let joinWithBlankLines = mconcat . intersperse blankline
|
||||||
|
let prettyfyStanza ls = joinWithLinefeeds <$> mapM inlineListToOrg ls
|
||||||
|
contents <- joinWithBlankLines <$> mapM prettyfyStanza (splitStanza lns)
|
||||||
|
return $ blankline $$ "#+BEGIN_VERSE" $$
|
||||||
|
nest 2 contents $$ "#+END_VERSE" <> blankline
|
||||||
blockToOrg (RawBlock "html" str) =
|
blockToOrg (RawBlock "html" str) =
|
||||||
return $ blankline $$ "#+BEGIN_HTML" $$
|
return $ blankline $$ "#+BEGIN_HTML" $$
|
||||||
nest 2 (text str) $$ "#+END_HTML" $$ blankline
|
nest 2 (text str) $$ "#+END_HTML" $$ blankline
|
||||||
|
|
|
@ -201,11 +201,12 @@ blockToRST (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
|
||||||
return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
|
return $ hang 3 ".. " (fig $$ alt $$ classes $$ dims $+$ capt) $$ blankline
|
||||||
blockToRST (Para inlines)
|
blockToRST (Para inlines)
|
||||||
| LineBreak `elem` inlines = do -- use line block if LineBreaks
|
| LineBreak `elem` inlines = do -- use line block if LineBreaks
|
||||||
lns <- mapM inlineListToRST $ splitBy (==LineBreak) inlines
|
linesToLineBlock $ splitBy (==LineBreak) inlines
|
||||||
return $ (vcat $ map (hang 2 (text "| ")) lns) <> blankline
|
|
||||||
| otherwise = do
|
| otherwise = do
|
||||||
contents <- inlineListToRST inlines
|
contents <- inlineListToRST inlines
|
||||||
return $ contents <> blankline
|
return $ contents <> blankline
|
||||||
|
blockToRST (LineBlock lns) =
|
||||||
|
linesToLineBlock lns
|
||||||
blockToRST (RawBlock f@(Format f') str)
|
blockToRST (RawBlock f@(Format f') str)
|
||||||
| f == "rst" = return $ text str
|
| f == "rst" = return $ text str
|
||||||
| otherwise = return $ blankline <> ".. raw:: " <>
|
| otherwise = return $ blankline <> ".. raw:: " <>
|
||||||
|
@ -328,6 +329,12 @@ definitionListItemToRST (label, defs) = do
|
||||||
tabstop <- get >>= (return . writerTabStop . stOptions)
|
tabstop <- get >>= (return . writerTabStop . stOptions)
|
||||||
return $ label' $$ nest tabstop (nestle contents <> cr)
|
return $ label' $$ nest tabstop (nestle contents <> cr)
|
||||||
|
|
||||||
|
-- | Format a list of lines as line block.
|
||||||
|
linesToLineBlock :: [[Inline]] -> State WriterState Doc
|
||||||
|
linesToLineBlock inlineLines = do
|
||||||
|
lns <- mapM inlineListToRST inlineLines
|
||||||
|
return $ (vcat $ map (hang 2 (text "| ")) lns) <> blankline
|
||||||
|
|
||||||
-- | Convert list of Pandoc block elements to RST.
|
-- | Convert list of Pandoc block elements to RST.
|
||||||
blockListToRST' :: Bool
|
blockListToRST' :: Bool
|
||||||
-> [Block] -- ^ List of block elements
|
-> [Block] -- ^ List of block elements
|
||||||
|
|
|
@ -233,6 +233,8 @@ blockToRTF indent alignment (Plain lst) =
|
||||||
rtfCompact indent 0 alignment $ inlineListToRTF lst
|
rtfCompact indent 0 alignment $ inlineListToRTF lst
|
||||||
blockToRTF indent alignment (Para lst) =
|
blockToRTF indent alignment (Para lst) =
|
||||||
rtfPar indent 0 alignment $ inlineListToRTF lst
|
rtfPar indent 0 alignment $ inlineListToRTF lst
|
||||||
|
blockToRTF indent alignment (LineBlock lns) =
|
||||||
|
blockToRTF indent alignment $ linesToPara lns
|
||||||
blockToRTF indent alignment (BlockQuote lst) =
|
blockToRTF indent alignment (BlockQuote lst) =
|
||||||
concatMap (blockToRTF (indent + indentIncrement) alignment) lst
|
concatMap (blockToRTF (indent + indentIncrement) alignment) lst
|
||||||
blockToRTF indent _ (CodeBlock _ str) =
|
blockToRTF indent _ (CodeBlock _ str) =
|
||||||
|
|
|
@ -108,7 +108,7 @@ plainToPara :: Block -> Block
|
||||||
plainToPara (Plain x) = Para x
|
plainToPara (Plain x) = Para x
|
||||||
plainToPara x = x
|
plainToPara x = x
|
||||||
|
|
||||||
-- | Convert a list of pairs of terms and definitions into a TEI
|
-- | Convert a list of pairs of terms and definitions into a TEI
|
||||||
-- list with labels and items.
|
-- list with labels and items.
|
||||||
deflistItemsToTEI :: WriterOptions -> [([Inline],[[Block]])] -> Doc
|
deflistItemsToTEI :: WriterOptions -> [([Inline],[[Block]])] -> Doc
|
||||||
deflistItemsToTEI opts items =
|
deflistItemsToTEI opts items =
|
||||||
|
@ -167,6 +167,8 @@ blockToTEI opts (Plain lst) = blockToTEI opts $ Para lst
|
||||||
-- inTagsSimple "textobject" (inTagsSimple "phrase" alt))
|
-- inTagsSimple "textobject" (inTagsSimple "phrase" alt))
|
||||||
blockToTEI opts (Para lst) =
|
blockToTEI opts (Para lst) =
|
||||||
inTags False "p" [] $ inlinesToTEI opts lst
|
inTags False "p" [] $ inlinesToTEI opts lst
|
||||||
|
blockToTEI opts (LineBlock lns) =
|
||||||
|
blockToTEI opts $ linesToPara lns
|
||||||
blockToTEI opts (BlockQuote blocks) =
|
blockToTEI opts (BlockQuote blocks) =
|
||||||
inTagsIndented "quote" $ blocksToTEI opts blocks
|
inTagsIndented "quote" $ blocksToTEI opts blocks
|
||||||
blockToTEI _ (CodeBlock (_,classes,_) str) =
|
blockToTEI _ (CodeBlock (_,classes,_) str) =
|
||||||
|
@ -174,7 +176,7 @@ blockToTEI _ (CodeBlock (_,classes,_) str) =
|
||||||
flush (text (escapeStringForXML str) <> cr <> text "</ab>")
|
flush (text (escapeStringForXML str) <> cr <> text "</ab>")
|
||||||
where lang = if null langs
|
where lang = if null langs
|
||||||
then ""
|
then ""
|
||||||
else escapeStringForXML (head langs)
|
else escapeStringForXML (head langs)
|
||||||
isLang l = map toLower l `elem` map (map toLower) languages
|
isLang l = map toLower l `elem` map (map toLower) languages
|
||||||
langsFrom s = if isLang s
|
langsFrom s = if isLang s
|
||||||
then [s]
|
then [s]
|
||||||
|
@ -210,7 +212,7 @@ blockToTEI _ HorizontalRule =
|
||||||
selfClosingTag "milestone" [("unit","undefined"), ("type","separator"),("rendition","line")]
|
selfClosingTag "milestone" [("unit","undefined"), ("type","separator"),("rendition","line")]
|
||||||
|
|
||||||
-- | TEI Tables
|
-- | TEI Tables
|
||||||
-- TEI Simple's tables are composed of cells and rows; other
|
-- TEI Simple's tables are composed of cells and rows; other
|
||||||
-- table info in the AST is here lossily discard.
|
-- table info in the AST is here lossily discard.
|
||||||
blockToTEI opts (Table _ _ _ headers rows) =
|
blockToTEI opts (Table _ _ _ headers rows) =
|
||||||
let
|
let
|
||||||
|
@ -219,8 +221,8 @@ blockToTEI opts (Table _ _ _ headers rows) =
|
||||||
-- then return empty
|
-- then return empty
|
||||||
-- else tableRowToTEI opts headers
|
-- else tableRowToTEI opts headers
|
||||||
in
|
in
|
||||||
inTags True "table" [] $
|
inTags True "table" [] $
|
||||||
vcat $ [headers'] <> map (tableRowToTEI opts) rows
|
vcat $ [headers'] <> map (tableRowToTEI opts) rows
|
||||||
|
|
||||||
tableRowToTEI :: WriterOptions
|
tableRowToTEI :: WriterOptions
|
||||||
-> [[Block]]
|
-> [[Block]]
|
||||||
|
@ -276,7 +278,7 @@ inlineToTEI _ (Math t str) =
|
||||||
text (str)
|
text (str)
|
||||||
DisplayMath -> inTags True "figure" [("type","math")] $
|
DisplayMath -> inTags True "figure" [("type","math")] $
|
||||||
inTags False "formula" [("notation","TeX")] $ text (str)
|
inTags False "formula" [("notation","TeX")] $ text (str)
|
||||||
|
|
||||||
inlineToTEI _ (RawInline f x) | f == "tei" = text x
|
inlineToTEI _ (RawInline f x) | f == "tei" = text x
|
||||||
| otherwise = empty
|
| otherwise = empty
|
||||||
inlineToTEI _ LineBreak = selfClosingTag "lb" []
|
inlineToTEI _ LineBreak = selfClosingTag "lb" []
|
||||||
|
@ -317,4 +319,3 @@ idAndRole (id',cls,_) = ident ++ role
|
||||||
role = if null cls
|
role = if null cls
|
||||||
then []
|
then []
|
||||||
else [("role", unwords cls)]
|
else [("role", unwords cls)]
|
||||||
|
|
||||||
|
|
|
@ -145,6 +145,9 @@ blockToTexinfo (Para [Image attr txt (src,'f':'i':'g':':':tit)]) = do
|
||||||
blockToTexinfo (Para lst) =
|
blockToTexinfo (Para lst) =
|
||||||
inlineListToTexinfo lst -- this is handled differently from Plain in blockListToTexinfo
|
inlineListToTexinfo lst -- this is handled differently from Plain in blockListToTexinfo
|
||||||
|
|
||||||
|
blockToTexinfo (LineBlock lns) =
|
||||||
|
blockToTexinfo $ linesToPara lns
|
||||||
|
|
||||||
blockToTexinfo (BlockQuote lst) = do
|
blockToTexinfo (BlockQuote lst) = do
|
||||||
contents <- blockListToTexinfo lst
|
contents <- blockListToTexinfo lst
|
||||||
return $ text "@quotation" $$
|
return $ text "@quotation" $$
|
||||||
|
|
|
@ -130,6 +130,9 @@ blockToTextile opts (Para inlines) = do
|
||||||
then "<p>" ++ contents ++ "</p>"
|
then "<p>" ++ contents ++ "</p>"
|
||||||
else contents ++ if null listLevel then "\n" else ""
|
else contents ++ if null listLevel then "\n" else ""
|
||||||
|
|
||||||
|
blockToTextile opts (LineBlock lns) =
|
||||||
|
blockToTextile opts $ linesToPara lns
|
||||||
|
|
||||||
blockToTextile _ (RawBlock f str)
|
blockToTextile _ (RawBlock f str)
|
||||||
| f == Format "html" || f == Format "textile" = return str
|
| f == Format "html" || f == Format "textile" = return str
|
||||||
| otherwise = return ""
|
| otherwise = return ""
|
||||||
|
|
|
@ -33,7 +33,8 @@ http://zim-wiki.org/manual/Help/Wiki_Syntax.html
|
||||||
module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
|
module Text.Pandoc.Writers.ZimWiki ( writeZimWiki ) where
|
||||||
import Text.Pandoc.Definition
|
import Text.Pandoc.Definition
|
||||||
import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerStandalone, writerTemplate, writerWrapText), WrapOption(..) )
|
import Text.Pandoc.Options ( WriterOptions(writerTableOfContents, writerStandalone, writerTemplate, writerWrapText), WrapOption(..) )
|
||||||
import Text.Pandoc.Shared ( escapeURI, removeFormatting, trimr, substitute )
|
import Text.Pandoc.Shared ( escapeURI, linesToPara, removeFormatting, trimr
|
||||||
|
, substitute )
|
||||||
import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
|
import Text.Pandoc.Writers.Shared ( defField, metaToJSON )
|
||||||
import Text.Pandoc.ImageSize
|
import Text.Pandoc.ImageSize
|
||||||
import Text.Pandoc.Templates ( renderTemplate' )
|
import Text.Pandoc.Templates ( renderTemplate' )
|
||||||
|
@ -111,6 +112,9 @@ blockToZimWiki opts (Para inlines) = do
|
||||||
contents <- inlineListToZimWiki opts inlines
|
contents <- inlineListToZimWiki opts inlines
|
||||||
return $ contents ++ if null indent then "\n" else ""
|
return $ contents ++ if null indent then "\n" else ""
|
||||||
|
|
||||||
|
blockToZimWiki opts (LineBlock lns) = do
|
||||||
|
blockToZimWiki opts $ linesToPara lns
|
||||||
|
|
||||||
blockToZimWiki opts (RawBlock f str)
|
blockToZimWiki opts (RawBlock f str)
|
||||||
| f == Format "zimwiki" = return str
|
| f == Format "zimwiki" = return str
|
||||||
| f == Format "html" = do cont <- indentFromHTML opts str; return cont
|
| f == Format "html" = do cont <- indentFromHTML opts str; return cont
|
||||||
|
|
|
@ -1490,14 +1490,11 @@ tests =
|
||||||
mconcat
|
mconcat
|
||||||
[ para $ spcSep [ "The", "first", "lines", "of"
|
[ para $ spcSep [ "The", "first", "lines", "of"
|
||||||
, "Goethe's", emph "Faust" <> ":"]
|
, "Goethe's", emph "Faust" <> ":"]
|
||||||
, para $ mconcat
|
, lineBlock
|
||||||
[ spcSep [ "Habe", "nun,", "ach!", "Philosophie," ]
|
[ "Habe nun, ach! Philosophie,"
|
||||||
, linebreak
|
, "Juristerei und Medizin,"
|
||||||
, spcSep [ "Juristerei", "und", "Medizin," ]
|
, "Und leider auch Theologie!"
|
||||||
, linebreak
|
, "Durchaus studiert, mit heißem Bemühn."
|
||||||
, spcSep [ "Und", "leider", "auch", "Theologie!" ]
|
|
||||||
, linebreak
|
|
||||||
, spcSep [ "Durchaus", "studiert,", "mit", "heißem", "Bemühn." ]
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -1508,7 +1505,7 @@ tests =
|
||||||
, "bar"
|
, "bar"
|
||||||
, "#+END_VERSE"
|
, "#+END_VERSE"
|
||||||
] =?>
|
] =?>
|
||||||
para ("foo" <> linebreak <> linebreak <> "bar")
|
lineBlock [ "foo", mempty, "bar" ]
|
||||||
|
|
||||||
, "Verse block with varying indentation" =:
|
, "Verse block with varying indentation" =:
|
||||||
unlines [ "#+BEGIN_VERSE"
|
unlines [ "#+BEGIN_VERSE"
|
||||||
|
@ -1516,7 +1513,7 @@ tests =
|
||||||
, "my old friend"
|
, "my old friend"
|
||||||
, "#+END_VERSE"
|
, "#+END_VERSE"
|
||||||
] =?>
|
] =?>
|
||||||
para ("\160\160hello darkness" <> linebreak <> "my old friend")
|
lineBlock [ "\160\160hello darkness", "my old friend" ]
|
||||||
|
|
||||||
, "Raw block LaTeX" =:
|
, "Raw block LaTeX" =:
|
||||||
unlines [ "#+BEGIN_LaTeX"
|
unlines [ "#+BEGIN_LaTeX"
|
||||||
|
|
|
@ -19,8 +19,7 @@ infix 4 =:
|
||||||
|
|
||||||
tests :: [Test]
|
tests :: [Test]
|
||||||
tests = [ "line block with blank line" =:
|
tests = [ "line block with blank line" =:
|
||||||
"| a\n|\n| b" =?> para (str "a") <>
|
"| a\n|\n| b" =?> lineBlock [ "a", mempty, "\160b" ]
|
||||||
para (str "\160b")
|
|
||||||
, testGroup "field list"
|
, testGroup "field list"
|
||||||
[ "general" =: unlines
|
[ "general" =: unlines
|
||||||
[ "para"
|
[ "para"
|
||||||
|
@ -135,7 +134,7 @@ tests = [ "line block with blank line" =:
|
||||||
codeBlock "block quotes\n\ncan go on for many lines" <>
|
codeBlock "block quotes\n\ncan go on for many lines" <>
|
||||||
para "but must stop here")
|
para "but must stop here")
|
||||||
, "line block with 3 lines" =: "| a\n| b\n| c"
|
, "line block with 3 lines" =: "| a\n| b\n| c"
|
||||||
=?> para ("a" <> linebreak <> "b" <> linebreak <> "c")
|
=?> lineBlock ["a", "b", "c"]
|
||||||
, "quoted literal block using >" =: "::\n\n> quoted\n> block\n\nOrdinary paragraph"
|
, "quoted literal block using >" =: "::\n\n> quoted\n> block\n\nOrdinary paragraph"
|
||||||
=?> codeBlock "> quoted\n> block" <> para "Ordinary paragraph"
|
=?> codeBlock "> quoted\n> block" <> para "Ordinary paragraph"
|
||||||
, "quoted literal block using | (not a line block)" =: "::\n\n| quoted\n| block\n\nOrdinary paragraph"
|
, "quoted literal block using | (not a line block)" =: "::\n\n| quoted\n| block\n\nOrdinary paragraph"
|
||||||
|
|
|
@ -84,8 +84,14 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "Author",S
|
||||||
,BlockQuote
|
,BlockQuote
|
||||||
[Header 2 ("foobar",["baz"],[("key","val")]) [Str "Header",Space,Str "attributes",Space,Str "inside",Space,Str "block",Space,Str "quote"]]
|
[Header 2 ("foobar",["baz"],[("key","val")]) [Str "Header",Space,Str "attributes",Space,Str "inside",Space,Str "block",Space,Str "quote"]]
|
||||||
,Header 2 ("line-blocks",[],[]) [Str "Line",Space,Str "blocks"]
|
,Header 2 ("line-blocks",[],[]) [Str "Line",Space,Str "blocks"]
|
||||||
,Para [Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be",LineBreak,Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
|
,LineBlock
|
||||||
,Para [Str "Continuation",Space,Str "line",LineBreak,Str "\160\160and",Space,Str "another"]
|
[[Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be"]
|
||||||
|
,[Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,"]
|
||||||
|
,[Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,"]
|
||||||
|
,[Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
|
||||||
|
,[]
|
||||||
|
,[Str "Continuation",Space,Str "line"]
|
||||||
|
,[Str "\160\160and",Space,Str "another"]]
|
||||||
,Header 2 ("grid-tables",[],[]) [Str "Grid",Space,Str "Tables"]
|
,Header 2 ("grid-tables",[],[]) [Str "Grid",Space,Str "Tables"]
|
||||||
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.2638888888888889,0.16666666666666666,0.18055555555555555]
|
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.2638888888888889,0.16666666666666666,0.18055555555555555]
|
||||||
[[Plain [Str "col",Space,Str "1"]]
|
[[Plain [Str "col",Space,Str "1"]]
|
||||||
|
|
|
@ -230,8 +230,14 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
|
||||||
,Para [Str "Another",Space,Str "paragraph"]
|
,Para [Str "Another",Space,Str "paragraph"]
|
||||||
,Para [Str "A",Space,Str "third",Space,Str "paragraph"]
|
,Para [Str "A",Space,Str "third",Space,Str "paragraph"]
|
||||||
,Header 1 ("line-blocks",[],[]) [Str "Line",Space,Str "blocks"]
|
,Header 1 ("line-blocks",[],[]) [Str "Line",Space,Str "blocks"]
|
||||||
,Para [Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be",LineBreak,Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,",LineBreak,Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
|
,LineBlock
|
||||||
,Para [Str "Continuation",Space,Str "line",LineBreak,Str "\160\160and",Space,Str "another"]
|
[[Str "But",Space,Str "can",Space,Str "a",Space,Str "bee",Space,Str "be",Space,Str "said",Space,Str "to",Space,Str "be"]
|
||||||
|
,[Str "\160\160\160\160or",Space,Str "not",Space,Str "to",Space,Str "be",Space,Str "an",Space,Str "entire",Space,Str "bee,"]
|
||||||
|
,[Str "\160\160\160\160\160\160\160\160when",Space,Str "half",Space,Str "the",Space,Str "bee",Space,Str "is",Space,Str "not",Space,Str "a",Space,Str "bee,"]
|
||||||
|
,[Str "\160\160\160\160\160\160\160\160\160\160\160\160due",Space,Str "to",Space,Str "some",Space,Str "ancient",Space,Str "injury?"]
|
||||||
|
,[]
|
||||||
|
,[Str "Continuation",Space,Str "line"]
|
||||||
|
,[Str "\160\160and",Space,Str "another"]]
|
||||||
,Header 1 ("simple-tables",[],[]) [Str "Simple",Space,Str "Tables"]
|
,Header 1 ("simple-tables",[],[]) [Str "Simple",Space,Str "Tables"]
|
||||||
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
|
,Table [] [AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0]
|
||||||
[[Plain [Str "col",Space,Str "1"]]
|
[[Plain [Str "col",Space,Str "1"]]
|
||||||
|
|
Loading…
Add table
Reference in a new issue