{-
Copyright (C) 2006-2010 John MacFarlane <jgm@berkeley.edu>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-}{- |
Module : Text.Pandoc.Writers.Native
Copyright : Copyright (C) 2006-2010 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : John MacFarlane <jgm@berkeley.edu>
Stability : alpha
Portability : portable
Utility functions and definitions used by the various Pandoc modules.
-}moduleText.Pandoc.Writers.Native(writeNative)whereimportText.Pandoc.Shared(WriterOptions)importData.List(intercalate)importText.Pandoc.Definition-- | Indent string as a block.indentBy::Int-- ^ Number of spaces to indent the block ->Int-- ^ Number of spaces (rel to block) to indent first line->String-- ^ Contents of block to indent->StringindentBy__[]=""indentBynumfirststr=let(firstLine:restLines)=linesstrfirstLineIndent=num+firstin(replicatefirstLineIndent' ')++firstLine++"\n"++(intercalate"\n"$map((replicatenum' ')++)restLines)-- | Prettyprint list of Pandoc blocks elements.prettyBlockList::Int-- ^ Number of spaces to indent list of blocks->[Block]-- ^ List of blocks->StringprettyBlockListindent[]=indentByindent0"[]"prettyBlockListindentblocks=indentByindent(-2)$"[ "++(intercalate"\n, "(mapprettyBlockblocks))++" ]"-- | Prettyprint Pandoc block element.prettyBlock::Block->StringprettyBlock(BlockQuoteblocks)="BlockQuote\n "++(prettyBlockList2blocks)prettyBlock(OrderedListattribsblockLists)="OrderedList "++showattribs++"\n"++indentBy20("[ "++(intercalate", "$map(\blocks->prettyBlockList2blocks)blockLists))++" ]"prettyBlock(BulletListblockLists)="BulletList\n"++indentBy20("[ "++(intercalate", "(map(\blocks->prettyBlockList2blocks)blockLists)))++" ]"prettyBlock(DefinitionListitems)="DefinitionList\n"++indentBy20("[ "++(intercalate"\n, "(map(\(term,defs)->"("++showterm++",\n"++indentBy30("[ "++(intercalate", "(map(\blocks->prettyBlockList2blocks)defs))++"]")++")")items)))++" ]"prettyBlock(Tablecaptionalignswidthsheaderrows)="Table "++showcaption++" "++showaligns++" "++showwidths++"\n"++prettyRowheader++" [\n"++(intercalate",\n"(mapprettyRowrows))++" ]"whereprettyRowcols=indentBy20("[ "++(intercalate", "(map(\blocks->prettyBlockList2blocks)cols)))++" ]"prettyBlockblock=showblock-- | Prettyprint Pandoc document.writeNative::WriterOptions->Pandoc->StringwriteNative_(Pandocmetablocks)="Pandoc "++"("++showmeta++")\n"++(prettyBlockList0blocks)++"\n"