git.iko.soy/typeable/pandoc
on master help sign in
Textile writer: moved into PandocMonad.

Warnings for omitted raw content.

commitd8a322861742355663a0ffea4550200cddcbd002 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 30 Mar 2017, 21:37 (10 years ago) parentb278366
1 file changed+48−31
src/Text/Pandoc/Writers/Textile.hs+48−31
src/Text/Pandoc/Writers/Textile.hs+48−31
@@ -33,7 +33,8 @@ module Text.Pandoc.Writers.Textile ( writeTextile ) where
3333import Control.Monad.State
3434import Data.Char (isSpace)
3535import Data.List (intercalate)
36−import Text.Pandoc.Class (PandocMonad)
36+import Text.Pandoc.Class (PandocMonad, report)
37+import Text.Pandoc.Logging
3738import Text.Pandoc.Definition
3839import Text.Pandoc.ImageSize
3940import Text.Pandoc.Options
@@ -50,15 +51,20 @@ data WriterState = WriterState {
5051 , stUseTags :: Bool -- True if we should use HTML tags because we're in a complex list
5152 }
5253
54+type TW = StateT WriterState
55+
5356-- | Convert Pandoc to Textile.
5457writeTextile :: PandocMonad m => WriterOptions -> Pandoc -> m String
55−writeTextile opts document = return $
56− evalState (pandocToTextile opts document)
57− WriterState { stNotes = [], stListLevel = [], stStartNum = Nothing,
58+writeTextile opts document =
59+ evalStateT (pandocToTextile opts document)
60+ WriterState { stNotes = [],
61+ stListLevel = [],
62+ stStartNum = Nothing,
5863 stUseTags = False }
5964
6065-- | Return Textile representation of document.
61−pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
66+pandocToTextile :: PandocMonad m
67+ => WriterOptions -> Pandoc -> TW m String
6268pandocToTextile opts (Pandoc meta blocks) = do
6369 metadata <- metaToJSON opts (blockListToTextile opts)
6470 (inlineListToTextile opts) meta
@@ -70,7 +76,7 @@ pandocToTextile opts (Pandoc meta blocks) = do
7076 Nothing -> return main
7177 Just tpl -> return $ renderTemplate' tpl context
7278
73−withUseTags :: State WriterState a -> State WriterState a
79+withUseTags :: PandocMonad m => TW m a -> TW m a
7480withUseTags action = do
7581 oldUseTags <- gets stUseTags
7682 modify $ \s -> s { stUseTags = True }
@@ -102,9 +108,10 @@ escapeStringForTextile :: String -> String
102108escapeStringForTextile = concatMap escapeCharForTextile
103109
104110-- | Convert Pandoc block element to Textile.
105−blockToTextile :: WriterOptions -- ^ Options
106− -> Block -- ^ Block element
107− -> State WriterState String
111+blockToTextile :: PandocMonad m
112+ => WriterOptions -- ^ Options
113+ -> Block -- ^ Block element
114+ -> TW m String
108115
109116blockToTextile _ Null = return ""
110117
@@ -134,9 +141,11 @@ blockToTextile opts (Para inlines) = do
134141blockToTextile opts (LineBlock lns) =
135142 blockToTextile opts $ linesToPara lns
136143
137−blockToTextile _ (RawBlock f str)
144+blockToTextile _ b@(RawBlock f str)
138145 | f == Format "html" || f == Format "textile" = return str
139− | otherwise = return ""
146+ | otherwise = do
147+ report $ BlockNotRendered b
148+ return ""
140149
141150blockToTextile _ HorizontalRule = return "<hr />\n"
142151
@@ -262,7 +271,8 @@ listAttribsToString (startnum, numstyle, _) =
262271 else "")
263272
264273-- | Convert bullet or ordered list item (list of blocks) to Textile.
265−listItemToTextile :: WriterOptions -> [Block] -> State WriterState String
274+listItemToTextile :: PandocMonad m
275+ => WriterOptions -> [Block] -> TW m String
266276listItemToTextile opts items = do
267277 contents <- blockListToTextile opts items
268278 useTags <- gets stUseTags
@@ -278,9 +288,10 @@ listItemToTextile opts items = do
278288 Nothing -> return $ marker ++ " " ++ contents
279289
280290-- | Convert definition list item (label, list of blocks) to Textile.
281−definitionListItemToTextile :: WriterOptions
291+definitionListItemToTextile :: PandocMonad m
292+ => WriterOptions
282293 -> ([Inline],[[Block]])
283− -> State WriterState String
294+ -> TW m String
284295definitionListItemToTextile opts (label, items) = do
285296 labelText <- inlineListToTextile opts label
286297 contents <- mapM (blockListToTextile opts) items
@@ -326,11 +337,12 @@ vcat = intercalate "\n"
326337-- Auxiliary functions for tables. (TODO: these are common to HTML, MediaWiki,
327338-- and Textile writers, and should be abstracted out.)
328339
329−tableRowToTextile :: WriterOptions
330− -> [String]
331− -> Int
332− -> [[Block]]
333− -> State WriterState String
340+tableRowToTextile :: PandocMonad m
341+ => WriterOptions
342+ -> [String]
343+ -> Int
344+ -> [[Block]]
345+ -> TW m String
334346tableRowToTextile opts alignStrings rownum cols' = do
335347 let celltype = if rownum == 0 then "th" else "td"
336348 let rowclass = case rownum of
@@ -349,11 +361,12 @@ alignmentToString alignment = case alignment of
349361 AlignCenter -> "center"
350362 AlignDefault -> "left"
351363
352−tableItemToTextile :: WriterOptions
353− -> String
354− -> String
355− -> [Block]
356− -> State WriterState String
364+tableItemToTextile :: PandocMonad m
365+ => WriterOptions
366+ -> String
367+ -> String
368+ -> [Block]
369+ -> TW m String
357370tableItemToTextile opts celltype align' item = do
358371 let mkcell x = "<" ++ celltype ++ " align=\"" ++ align' ++ "\">" ++
359372 x ++ "</" ++ celltype ++ ">"
@@ -361,19 +374,21 @@ tableItemToTextile opts celltype align' item = do
361374 return $ mkcell contents
362375
363376-- | Convert list of Pandoc block elements to Textile.
364−blockListToTextile :: WriterOptions -- ^ Options
365− -> [Block] -- ^ List of block elements
366− -> State WriterState String
377+blockListToTextile :: PandocMonad m
378+ => WriterOptions -- ^ Options
379+ -> [Block] -- ^ List of block elements
380+ -> TW m String
367381blockListToTextile opts blocks =
368382 mapM (blockToTextile opts) blocks >>= return . vcat
369383
370384-- | Convert list of Pandoc inline elements to Textile.
371−inlineListToTextile :: WriterOptions -> [Inline] -> State WriterState String
385+inlineListToTextile :: PandocMonad m
386+ => WriterOptions -> [Inline] -> TW m String
372387inlineListToTextile opts lst =
373388 mapM (inlineToTextile opts) lst >>= return . concat
374389
375390-- | Convert Pandoc inline element to Textile.
376−inlineToTextile :: WriterOptions -> Inline -> State WriterState String
391+inlineToTextile :: PandocMonad m => WriterOptions -> Inline -> TW m String
377392
378393inlineToTextile opts (Span _ lst) =
379394 inlineListToTextile opts lst
@@ -430,11 +445,13 @@ inlineToTextile _ (Str str) = return $ escapeStringForTextile str
430445inlineToTextile _ (Math _ str) =
431446 return $ "<span class=\"math\">" ++ escapeStringForXML str ++ "</math>"
432447
433−inlineToTextile opts (RawInline f str)
448+inlineToTextile opts il@(RawInline f str)
434449 | f == Format "html" || f == Format "textile" = return str
435450 | (f == Format "latex" || f == Format "tex") &&
436451 isEnabled Ext_raw_tex opts = return str
437− | otherwise = return ""
452+ | otherwise = do
453+ report $ InlineNotRendered il
454+ return ""
438455
439456inlineToTextile _ LineBreak = return "\n"
440457