@@ -37,21 +37,18 @@ import Text.Pandoc.Templates (renderTemplate)
3737import Text.Pandoc.Shared
3838import Text.Pandoc.Parsing hiding (blankline)
3939import Text.ParserCombinators.Parsec ( runParser, GenParser )
40−import Data.List ( group, intersperse, transpose )
40+import Data.List ( intersperse, transpose )
4141import Text.Pandoc.Pretty
4242import Control.Monad.State
4343
44−type Notes = [[Block]]
4544type Refs = [([Inline], Target)]
46−data WriterState = WriterState { stNotes :: Notes
47− , stRefs :: Refs
45+data WriterState = WriterState { stRefs :: Refs
4846 , stPlain :: Bool }
4947
5048-- | Convert Pandoc to PseudoPod.
5149writePseudoPod :: WriterOptions -> Pandoc -> String
5250writePseudoPod opts document =
53− evalState (pandocToPseudoPod opts document) WriterState{ stNotes = []
54− , stRefs = []
51+ evalState (pandocToPseudoPod opts document) WriterState{stRefs = []
5552 , stPlain = False }
5653
5754-- | Return PseudoPod representation of document.
@@ -66,15 +63,12 @@ pandocToPseudoPod opts (Pandoc (Meta title authors date) blocks) = do
6663 then tableOfContents opts headerBlocks
6764 else empty
6865 body <- blockListToPseudoPod opts blocks
69− st <- get
70− notes' <- notesToPseudoPod opts (reverse $ stNotes st)
7166 st' <- get -- note that the notes may contain refs
7267 refs' <- refsToPseudoPod opts (reverse $ stRefs st')
7368 let colwidth = if writerWrapText opts
7469 then Just $ writerColumns opts
7570 else Nothing
7671 let main = render colwidth $ body <>
77− (if isEmpty notes' then empty else blankline <> notes') <>
7872 (if isEmpty refs' then empty else blankline <> refs')
7973 let context = writerVariables opts ++
8074 [ ("toc", render colwidth toc)
@@ -104,36 +98,21 @@ keyToPseudoPod opts (label, (src, tit)) = do
10498 return $ nest 2 $ hang 2
10599 ("[" <> label' <> "]:" <> space) (text src <> tit')
106100
107−-- | Return PseudoPod representation of notes.
108−notesToPseudoPod :: WriterOptions -> [[Block]] -> State WriterState Doc
109−notesToPseudoPod opts notes =
110− mapM (\(num, note) -> noteToPseudoPod opts num note) (zip [1..] notes) >>=
111− return . vsep
112−
113−-- | Return PseudoPod representation of a note.
114−noteToPseudoPod :: WriterOptions -> Int -> [Block] -> State WriterState Doc
115−noteToPseudoPod opts num blocks = do
116− contents <- blockListToPseudoPod opts blocks
117− let num' = text $ show num
118− let marker = text "[^" <> num' <> text "]:"
119− let markerSize = 4 + offset num'
120− let spacer = case writerTabStop opts - markerSize of
121− n | n > 0 -> text $ replicate n ' '
122− _ -> text " "
123− return $ hang (writerTabStop opts) (marker <> spacer) contents
124−
125101-- | Escape special characters for PseudoPod.
126102escapeString :: String -> String
127103escapeString = escapeStringUsing pseudopodEscapes
128− where pseudopodEscapes = backslashEscapes "\\`*_>#~^"
104+ where pseudopodEscapes = entityEscapes
105+
106+-- | pod-ish entity escapes, E<>
107+entityEscapes :: [(Char,String)]
108+entityEscapes = [('>', "E<gt>")]
129109
130110-- | Construct table of contents from list of header blocks.
131111tableOfContents :: WriterOptions -> [Block] -> Doc
132112tableOfContents opts headers =
133113 let opts' = opts { writerIgnoreNotes = True }
134114 contents = BulletList $ map elementToListItem $ hierarchicalize headers
135− in evalState (blockToPseudoPod opts' contents) WriterState{ stNotes = []
136− , stRefs = []
115+ in evalState (blockToPseudoPod opts' contents) WriterState{ stRefs = []
137116 , stPlain = False }
138117
139118-- | Converts an Element to a list item for a table of contents,
@@ -184,6 +163,8 @@ blockToPseudoPod _ Null = return empty
184163blockToPseudoPod opts (Plain inlines) = do
185164 contents <- inlineListToPseudoPod opts inlines
186165 return $ contents <> cr
166+
167+
187168blockToPseudoPod opts (Para inlines) = do
188169 contents <- inlineListToPseudoPod opts inlines
189170 -- escape if para starts with ordered list marker
@@ -201,8 +182,10 @@ blockToPseudoPod _ (RawBlock f str)
201182 then return empty
202183 else return $ text str <> text "\n"
203184blockToPseudoPod _ (RawBlock _ _) = return empty
185+
186+-- | No horizontal rules, leave a space
204187blockToPseudoPod _ HorizontalRule =
205− return $ blankline <> text "* * * * *" <> blankline
188+ return $ blankline <> blankline <> blankline
206189
207190-- | =headN <content> - DONE
208191blockToPseudoPod opts (Header level inlines) = do
@@ -283,9 +266,14 @@ blockToPseudoPod opts (Table caption aligns widths headers rows) = do
283266 else border
284267 return $ nest 2 $ head'' $$ underline $$ body $$
285268 bottom $$ blankline $$ caption'' $$ blankline
269+
270+-- | =over / =item * / =back
286271blockToPseudoPod opts (BulletList items) = do
287272 contents <- mapM (bulletListItemToPseudoPod opts) items
288− return $ cat contents <> blankline
273+ return $ "=over" <> blankline <> cat contents <> blankline <> "=back" <> blankline
274+
275+
276+-- | =over / =item N. / =back
289277blockToPseudoPod opts (OrderedList attribs items) = do
290278 let markers = orderedListMarkers attribs
291279 let markers' = map (\m -> if length m < 3
@@ -293,18 +281,18 @@ blockToPseudoPod opts (OrderedList attribs items) = do
293281 else m) markers
294282 contents <- mapM (\(item, num) -> orderedListItemToPseudoPod opts item num) $
295283 zip markers' items
296− return $ cat contents <> blankline
284+ return $ "=over" <> blankline <> cat contents <> blankline <> "=back" <> blankline
285+-- return $ cat contents <> blankline
286+
297287blockToPseudoPod opts (DefinitionList items) = do
298288 contents <- mapM (definitionListItemToPseudoPod opts) items
299− return $ cat contents <> blankline
289+ return $ "=over" <> blankline <> cat contents <> blankline <> "=back" <> blankline
300290
301−-- | Convert bullet list item (list of blocks) to PseudoPod.
291+-- | bullet list -> =item *
302292bulletListItemToPseudoPod :: WriterOptions -> [Block] -> State WriterState Doc
303293bulletListItemToPseudoPod opts items = do
304294 contents <- blockListToPseudoPod opts items
305− let sps = replicate (writerTabStop opts - 2) ' '
306− let start = text ('-' : ' ' : sps)
307− return $ hang (writerTabStop opts) start $ contents <> cr
295+ return $ "=item *" <> blankline <> contents <> blankline
308296
309297-- | Convert ordered list item (a list of blocks) to PseudoPod.
310298orderedListItemToPseudoPod :: WriterOptions -- ^ options
@@ -313,13 +301,17 @@ orderedListItemToPseudoPod :: WriterOptions -- ^ options
313301 -> State WriterState Doc
314302orderedListItemToPseudoPod opts marker items = do
315303 contents <- blockListToPseudoPod opts items
304+ return $ "=item " <> (text marker) <> blankline <> contents <> blankline
305+
306+{-
316307 let sps = case length marker - writerTabStop opts of
317308 n | n > 0 -> text $ replicate n ' '
318309 _ -> text " "
319310 let start = text marker <> sps
320311 return $ hang (writerTabStop opts) start $ contents <> cr
312+-}
321313
322−-- | Convert definition list item (label, list of blocks) to PseudoPod.
314+-- | Convert definition list item (label, list of blocks) to markdown.
323315definitionListItemToPseudoPod :: WriterOptions
324316 -> ([Inline],[[Block]])
325317 -> State WriterState Doc
@@ -335,6 +327,24 @@ definitionListItemToPseudoPod opts (label, defs) = do
335327 let contents = vcat $ map (\d -> hang tabStop (leader <> sps) $ vcat d <> cr) defs'
336328 return $ labelText <> cr <> contents <> cr
337329
330+{-
331+-- | Convert definition list item (label, list of blocks) to PseudoPod.
332+-- | =over / =item FOO / para / =back
333+definitionListItemToPseudoPod :: WriterOptions
334+ -> ([Inline],[[Block]])
335+ -> State WriterState Doc
336+definitionListItemToPseudoPod opts (label, defs) = do
337+ labelText <- inlineListToPseudoPod opts label
338+ -- each call to definitonListItemToPseudoPod is one label, which can have multiple defintions. (Each definition is a [Block].)
339+
340+ defs' <- mapM (mapM (blockToPseudoPod opts)) defs
341+-- let contents = vcat $ map (\d -> "=item") $ vcat d <> cr) defs'
342+ return $ "=item" <> labelText <> blankline <> vcat (vcat defs') <> blankline
343+
344+definitionListSubItemToPseudoPod :: WriterOptions -> ([Inline], [Block])
345+definitionListSubItemToPseudoPod opts (label, def) = do
346+-}
347+
338348-- | Convert list of Pandoc block elements to PseudoPod.
339349blockListToPseudoPod :: WriterOptions -- ^ Options
340350 -> [Block] -- ^ List of block elements
@@ -384,41 +394,46 @@ inlineToPseudoPod opts (Strikeout lst) = do
384394 return $ "~~" <> contents <> "~~"
385395-}
386396
397+-- | G<>
387398inlineToPseudoPod opts (Superscript lst) = do
388399 let lst' = bottomUp escapeSpaces lst
389400 contents <- inlineListToPseudoPod opts lst'
390− return $ "^" <> contents <> "^"
401+ return $ "G<" <> contents <> ">"
402+
403+-- | H<>
391404inlineToPseudoPod opts (Subscript lst) = do
392405 let lst' = bottomUp escapeSpaces lst
393406 contents <- inlineListToPseudoPod opts lst'
394− return $ "~" <> contents <> "~"
407+ return $ "H<" <> contents <> ">"
408+
409+-- | FIXME - doesnt exist
395410inlineToPseudoPod opts (SmallCaps lst) = inlineListToPseudoPod opts lst
411+
396412inlineToPseudoPod opts (Quoted SingleQuote lst) = do
397413 contents <- inlineListToPseudoPod opts lst
398414 return $ "‘" <> contents <> "’"
399415inlineToPseudoPod opts (Quoted DoubleQuote lst) = do
400416 contents <- inlineListToPseudoPod opts lst
401417 return $ "“" <> contents <> "”"
418+
419+-- | C<>
402420inlineToPseudoPod opts (Code attr str) =
403− let tickGroups = filter (\s -> '`' `elem` s) $ group str
404− longest = if null tickGroups
405− then 0
406− else maximum $ map length tickGroups
407− marker = replicate (longest + 1) '`'
408− spacer = if (longest == 0) then "" else " "
409− attrs = if writerStrictMarkdown opts || attr == nullAttr
410− then empty
411− else attrsToPseudoPod attr
412− in return $ text (marker ++ spacer ++ str ++ spacer ++ marker) <> attrs
421+ return $ "C<< " <> text (escapeString str) <> " >>"
422+
413423inlineToPseudoPod _ (Str str) = do
414424 st <- get
415425 if stPlain st
416426 then return $ text str
417427 else return $ text $ escapeString str
428+
429+-- | No Math
430+-- inlineToPseudoPod opts (Math _ str) = inlineToPseudoPod opts Inline str
431+
418432inlineToPseudoPod _ (Math InlineMath str) =
419433 return $ "$" <> text str <> "$"
420434inlineToPseudoPod _ (Math DisplayMath str) =
421435 return $ "$$" <> text str <> "$$"
436+
422437inlineToPseudoPod _ (RawInline f str)
423438 | f == "html" || f == "latex" || f == "tex" || f == "PseudoPod" =
424439 return $ text str
@@ -469,8 +484,8 @@ inlineToPseudoPod opts (Image alternate (source, tit)) = do
469484 else alternate
470485 linkPart <- inlineToPseudoPod opts (Link txt (source, tit))
471486 return $ "!" <> linkPart
472−inlineToPseudoPod _ (Note contents) = do
473− modify (\st -> st{ stNotes = contents : stNotes st })
474− st <- get
475− let ref = show $ (length $ stNotes st)
476− return $ "[^" <> text ref <> "]"
487+
488+-- | N<>
489+inlineToPseudoPod opts (Note blocks) = do
490+ contents <- blockListToPseudoPod opts blocks
491+ return $ "N<" <> contents <> ">"