diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-05-10 22:53:35 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-06-24 20:29:41 -0700 |
commit | f869f7e08dad315945d52be3fcacf6ff0c05c5c1 (patch) | |
tree | 4c426ebf5a30b51499859f9d41a890534b6a18a6 /src/Text/Pandoc/Writers/OPML.hs | |
parent | e32a8f5981969bb6d0a11bd945188c35817e4d96 (diff) |
Use new flexible metadata type.
* Depend on pandoc 1.12.
* Added yaml dependency.
* `Text.Pandoc.XML`: Removed `stripTags`. (API change.)
* `Text.Pandoc.Shared`: Added `metaToJSON`.
This will be used in writers to create a JSON object for use
in the templates from the pandoc metadata.
* Revised readers and writers to use the new Meta type.
* `Text.Pandoc.Options`: Added `Ext_yaml_title_block`.
* Markdown reader: Added support for YAML metadata block.
Note that it must come at the beginning of the document.
* `Text.Pandoc.Parsing.ParserState`: Replace `stateTitle`,
`stateAuthors`, `stateDate` with `stateMeta`.
* RST reader: Improved metadata.
Treat initial field list as metadata when standalone specified.
Previously ALL fields "title", "author", "date" in field lists
were treated as metadata, even if not at the beginning.
Use `subtitle` metadata field for subtitle.
* `Text.Pandoc.Templates`: Export `renderTemplate'` that takes a string
instead of a compiled template..
* OPML template: Use 'for' loop for authors.
* Org template: '#+TITLE:' is inserted before the title.
Previously the writer did this.
Diffstat (limited to 'src/Text/Pandoc/Writers/OPML.hs')
-rw-r--r-- | src/Text/Pandoc/Writers/OPML.hs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/Text/Pandoc/Writers/OPML.hs b/src/Text/Pandoc/Writers/OPML.hs index f7eb9289a..b71c7cf6e 100644 --- a/src/Text/Pandoc/Writers/OPML.hs +++ b/src/Text/Pandoc/Writers/OPML.hs @@ -32,37 +32,38 @@ import Text.Pandoc.Definition import Text.Pandoc.XML import Text.Pandoc.Shared import Text.Pandoc.Options -import Text.Pandoc.Templates (renderTemplate) +import Text.Pandoc.Templates (renderTemplate') import Text.Pandoc.Writers.HTML (writeHtmlString) import Text.Pandoc.Writers.Markdown (writeMarkdown) -import Data.List ( intercalate ) import Text.Pandoc.Pretty import Data.Time import System.Locale (defaultTimeLocale) +import qualified Text.Pandoc.Builder as B -- | Convert Pandoc document to string in OPML format. writeOPML :: WriterOptions -> Pandoc -> String -writeOPML opts (Pandoc (Meta tit auths dat) blocks) = - let title = writeHtmlInlines tit - author = writeHtmlInlines $ intercalate [Space,Str ";",Space] auths - date = convertDate dat - elements = hierarchicalize blocks +writeOPML opts (Pandoc meta blocks) = + let elements = hierarchicalize blocks colwidth = if writerWrapText opts then Just $ writerColumns opts else Nothing + meta' = B.setMeta "date" (B.str $ convertDate $ docDate meta) meta + Just metadata = metaToJSON + (Just . writeMarkdown def . Pandoc nullMeta) + (Just . trimr . writeMarkdown def . Pandoc nullMeta . + (\ils -> [Plain ils])) + meta' main = render colwidth $ vcat (map (elementToOPML opts) elements) - context = writerVariables opts ++ - [ ("body", main) - , ("title", title) - , ("date", date) - , ("author", author) ] + context = setField "body" main + $ foldl (\acc (x,y) -> setField x y acc) + metadata (writerVariables opts) in if writerStandalone opts - then renderTemplate context $ writerTemplate opts + then renderTemplate' (writerTemplate opts) context else main writeHtmlInlines :: [Inline] -> String writeHtmlInlines ils = trim $ writeHtmlString def - $ Pandoc (Meta [] [] []) [Plain ils] + $ Pandoc nullMeta [Plain ils] -- date format: RFC 822: Thu, 14 Jul 2005 23:41:05 GMT showDateTimeRFC822 :: UTCTime -> String @@ -82,7 +83,7 @@ elementToOPML opts (Sec _ _num _ title elements) = fromBlk _ = error "fromBlk called on non-block" (blocks, rest) = span isBlk elements attrs = [("text", writeHtmlInlines title)] ++ - [("_note", writeMarkdown def (Pandoc (Meta [] [] []) + [("_note", writeMarkdown def (Pandoc nullMeta (map fromBlk blocks))) | not (null blocks)] in inTags True "outline" attrs $ |