Permalink
Browse files

Added OPML template, tests.

Minor fixes to OPML writer.
Improved OPML reader tests.
  • Loading branch information...
1 parent a63c208 commit 5b4d239b852a3f8fd9dc4fef025faad6b575ec59 John MacFarlane committed Mar 20, 2013
Showing with 188 additions and 104 deletions.
  1. +1 −1 data/templates
  2. +16 −7 pandoc.cabal
  3. +13 −4 src/Text/Pandoc/Writers/OPML.hs
  4. +3 −1 tests/Tests/Old.hs
  5. +1 −1 tests/opml-reader.native
  6. +82 −90 tests/opml-reader.opml
  7. +72 −0 tests/writer.opml
Submodule templates updated 1 files
+11 −0 default.opml
View
@@ -38,22 +38,30 @@ Description: Pandoc is a Haskell library for converting from one markup
only adding a reader or writer.
Data-Files:
-- templates
- data/templates/default.html, data/templates/default.html5,
- data/templates/default.docbook, data/templates/default.beamer,
+ data/templates/default.html,
+ data/templates/default.html5,
+ data/templates/default.docbook,
+ data/templates/default.beamer,
data/templates/default.opendocument,
+ data/templates/default.opml,
data/templates/default.latex,
data/templates/default.context,
data/templates/default.texinfo,
data/templates/default.man,
data/templates/default.markdown,
- data/templates/default.rst, data/templates/default.plain,
- data/templates/default.mediawiki, data/templates/default.rtf,
- data/templates/default.s5, data/templates/default.slidy,
+ data/templates/default.rst,
+ data/templates/default.plain,
+ data/templates/default.mediawiki,
+ data/templates/default.rtf,
+ data/templates/default.s5,
+ data/templates/default.slidy,
data/templates/default.slideous,
data/templates/default.dzslides,
data/templates/default.asciidoc,
- data/templates/default.textile, data/templates/default.org,
- data/templates/default.epub, data/templates/default.epub3,
+ data/templates/default.textile,
+ data/templates/default.org,
+ data/templates/default.epub,
+ data/templates/default.epub3,
-- data for ODT writer
data/reference.odt,
-- data for docx writer
@@ -172,6 +180,7 @@ Extra-Source-Files:
tests/writer.rtf,
tests/writer.texinfo,
tests/writer.fb2,
+ tests/writer.opml,
tests/lhs-test.native,
tests/lhs-test-markdown.native,
tests/lhs-test.markdown,
@@ -37,19 +37,20 @@ 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)
-- | 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 = trim $ writeHtmlInlines dat
+ date = convertDate dat
elements = hierarchicalize blocks
colwidth = if writerWrapText opts
then Just $ writerColumns opts
else Nothing
- render' = render colwidth
- main = render' $ vcat (map (elementToOPML opts) elements)
+ main = render colwidth $ vcat (map (elementToOPML opts) elements)
context = writerVariables opts ++
[ ("body", main)
, ("title", title)
@@ -63,6 +64,14 @@ writeHtmlInlines :: [Inline] -> String
writeHtmlInlines ils = trim $ writeHtmlString def
$ Pandoc (Meta [] [] []) [Plain ils]
+-- date format: RFC 822: Thu, 14 Jul 2005 23:41:05 GMT
+showDateTimeRFC822 :: UTCTime -> String
+showDateTimeRFC822 = formatTime defaultTimeLocale "%a, %d %b %Y %X %Z"
+
+convertDate :: [Inline] -> String
+convertDate ils = maybe "" showDateTimeRFC822
+ $ parseTime defaultTimeLocale "%F" =<< (normalizeDate $ stringify ils)
+
-- | Convert an Element to OPML.
elementToOPML :: WriterOptions -> Element -> Doc
elementToOPML _ (Blk _) = empty
@@ -73,7 +82,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 opts (Pandoc (Meta [] [] [])
+ [("_note", writeMarkdown def (Pandoc (Meta [] [] [])
(map fromBlk blocks)))
| not (null blocks)]
in inTags True "outline" attrs $
View
@@ -125,7 +125,9 @@ tests = [ testGroup "markdown"
"mediawiki-reader.wiki" "mediawiki-reader.native"
]
, testGroup "opml"
- [ test "reader" ["-r", "opml", "-w", "native", "-s"]
+ [ test "basic" ["-r", "native", "-w", "opml", "--columns=78", "-s"]
+ "testsuite.native" "writer.opml"
+ , test "reader" ["-r", "opml", "-w", "native", "-s"]
"opml-reader.opml" "opml-reader.native"
]
, testGroup "other writers" $ map (\f -> testGroup f $ writerTests f)
View
@@ -1,4 +1,4 @@
-Pandoc (Meta {docTitle = [Str "states.opml"], docAuthors = [[Str "Dave",Space,Str "Winer"]], docDate = [Str "Thu,",Space,Str "14",Space,Str "Jul",Space,Str "2005",Space,Str "23:41:05",Space,Str "GMT"]})
+Pandoc (Meta {docTitle = [Str "States"], docAuthors = [[Str "Dave",Space,Str "Winer"]], docDate = [Str "Thu,",Space,Str "14",Space,Str "Jul",Space,Str "2005",Space,Str "23:41:05",Space,Str "GMT"]})
[Header 1 ("",[],[]) [Str "United",Space,Str "States"]
,Header 2 ("",[],[]) [Str "Far",Space,Str "West"]
,Header 3 ("",[],[]) [Str "Alaska"]
View
@@ -1,91 +1,83 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
<opml version="2.0">
- <head>
- <title>states.opml</title>
- <dateCreated>Tue, 15 Mar 2005 16:35:45 GMT</dateCreated>
- <dateModified>Thu, 14 Jul 2005 23:41:05 GMT</dateModified>
- <ownerName>Dave Winer</ownerName>
- <ownerEmail>dave@scripting.com</ownerEmail>
- <expansionState>1, 6, 13, 16, 18, 20</expansionState>
- <vertScrollState>1</vertScrollState>
- <windowTop>106</windowTop>
- <windowLeft>106</windowLeft>
- <windowBottom>558</windowBottom>
- <windowRight>479</windowRight>
- </head>
- <body>
- <outline text="United States">
- <outline text="Far West">
- <outline text="Alaska"/>
- <outline text="California"/>
- <outline text="Hawaii"/>
- <outline text="&lt;strong&gt;Nevada&lt;/strong&gt;" _note="I lived here *once*.&#10;&#10;Loved it.">
- <outline text="Reno" created="Tue, 12 Jul 2005 23:56:35 GMT" type="link" url="http://www.reno.gov"/>
- <outline text="Las Vegas" created="Tue, 12 Jul 2005 23:56:37 GMT"/>
- <outline text="Ely" created="Tue, 12 Jul 2005 23:56:39 GMT"/>
- <outline text="Gerlach" created="Tue, 12 Jul 2005 23:56:47 GMT"/>
- </outline>
- <outline text="Oregon"/>
- <outline text="Washington"/>
- </outline>
- <outline text="Great Plains">
- <outline text="Kansas"/>
- <outline text="Nebraska"/>
- <outline text="North Dakota"/>
- <outline text="Oklahoma"/>
- <outline text="South Dakota"/>
- </outline>
- <outline text="Mid-Atlantic">
- <outline text="Delaware"/>
- <outline text="Maryland"/>
- <outline text="New Jersey"/>
- <outline text="New York"/>
- <outline text="Pennsylvania"/>
- </outline>
- <outline text="Midwest">
- <outline text="Illinois"/>
- <outline text="Indiana"/>
- <outline text="Iowa"/>
- <outline text="Kentucky"/>
- <outline text="Michigan"/>
- <outline text="Minnesota"/>
- <outline text="Missouri"/>
- <outline text="Ohio"/>
- <outline text="West Virginia"/>
- <outline text="Wisconsin"/>
- </outline>
- <outline text="Mountains">
- <outline text="Colorado"/>
- <outline text="Idaho"/>
- <outline text="Montana"/>
- <outline text="Utah"/>
- <outline text="Wyoming"/>
- </outline>
- <outline text="New England">
- <outline text="Connecticut"/>
- <outline text="Maine"/>
- <outline text="Massachusetts"/>
- <outline text="New Hampshire"/>
- <outline text="Rhode Island"/>
- <outline text="Vermont"/>
- </outline>
- <outline text="South">
- <outline text="Alabama"/>
- <outline text="Arkansas"/>
- <outline text="Florida"/>
- <outline text="Georgia"/>
- <outline text="Louisiana"/>
- <outline text="Mississippi"/>
- <outline text="North Carolina"/>
- <outline text="South Carolina"/>
- <outline text="Tennessee"/>
- <outline text="Virginia"/>
- </outline>
- <outline text="Southwest">
- <outline text="Arizona"/>
- <outline text="New Mexico"/>
- <outline text="Texas"/>
- </outline>
- </outline>
- </body>
- </opml>
+ <head>
+ <title>States</title>
+ <dateModified>Thu, 14 Jul 2005 23:41:05 GMT</dateModified>
+ <ownerName>Dave Winer</ownerName>
+ </head>
+ <body>
+ <outline text="United States">
+ <outline text="Far West">
+ <outline text="Alaska"/>
+ <outline text="California"/>
+ <outline text="Hawaii"/>
+ <outline text="&lt;strong&gt;Nevada&lt;/strong&gt;" _note="I lived here *once*.&#10;&#10;Loved it.">
+ <outline text="Reno" created="Tue, 12 Jul 2005 23:56:35 GMT" type="link" url="http://www.reno.gov"/>
+ <outline text="Las Vegas" created="Tue, 12 Jul 2005 23:56:37 GMT"/>
+ <outline text="Ely" created="Tue, 12 Jul 2005 23:56:39 GMT"/>
+ <outline text="Gerlach" created="Tue, 12 Jul 2005 23:56:47 GMT"/>
+ </outline>
+ <outline text="Oregon"/>
+ <outline text="Washington"/>
+ </outline>
+ <outline text="Great Plains">
+ <outline text="Kansas"/>
+ <outline text="Nebraska"/>
+ <outline text="North Dakota"/>
+ <outline text="Oklahoma"/>
+ <outline text="South Dakota"/>
+ </outline>
+ <outline text="Mid-Atlantic">
+ <outline text="Delaware"/>
+ <outline text="Maryland"/>
+ <outline text="New Jersey"/>
+ <outline text="New York"/>
+ <outline text="Pennsylvania"/>
+ </outline>
+ <outline text="Midwest">
+ <outline text="Illinois"/>
+ <outline text="Indiana"/>
+ <outline text="Iowa"/>
+ <outline text="Kentucky"/>
+ <outline text="Michigan"/>
+ <outline text="Minnesota"/>
+ <outline text="Missouri"/>
+ <outline text="Ohio"/>
+ <outline text="West Virginia"/>
+ <outline text="Wisconsin"/>
+ </outline>
+ <outline text="Mountains">
+ <outline text="Colorado"/>
+ <outline text="Idaho"/>
+ <outline text="Montana"/>
+ <outline text="Utah"/>
+ <outline text="Wyoming"/>
+ </outline>
+ <outline text="New England">
+ <outline text="Connecticut"/>
+ <outline text="Maine"/>
+ <outline text="Massachusetts"/>
+ <outline text="New Hampshire"/>
+ <outline text="Rhode Island"/>
+ <outline text="Vermont"/>
+ </outline>
+ <outline text="South">
+ <outline text="Alabama"/>
+ <outline text="Arkansas"/>
+ <outline text="Florida"/>
+ <outline text="Georgia"/>
+ <outline text="Louisiana"/>
+ <outline text="Mississippi"/>
+ <outline text="North Carolina"/>
+ <outline text="South Carolina"/>
+ <outline text="Tennessee"/>
+ <outline text="Virginia"/>
+ </outline>
+ <outline text="Southwest">
+ <outline text="Arizona"/>
+ <outline text="New Mexico"/>
+ <outline text="Texas"/>
+ </outline>
+ </outline>
+ </body>
+</opml>
Oops, something went wrong.

0 comments on commit 5b4d239

Please sign in to comment.