summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Writers/MediaWiki.hs30
-rw-r--r--templates/mediawiki.template81
-rw-r--r--tests/writer.mediawiki1
3 files changed, 23 insertions, 89 deletions
diff --git a/src/Text/Pandoc/Writers/MediaWiki.hs b/src/Text/Pandoc/Writers/MediaWiki.hs
index f3e0c58fa..572308820 100644
--- a/src/Text/Pandoc/Writers/MediaWiki.hs
+++ b/src/Text/Pandoc/Writers/MediaWiki.hs
@@ -32,6 +32,7 @@ MediaWiki: <http://www.mediawiki.org/wiki/MediaWiki>
module Text.Pandoc.Writers.MediaWiki ( writeMediaWiki ) where
import Text.Pandoc.Definition
import Text.Pandoc.Shared
+import Text.Pandoc.Templates (renderTemplate)
import Text.Pandoc.XML ( escapeStringForXML )
import Data.List ( intersect, intercalate )
import Network.URI ( isURI )
@@ -52,21 +53,20 @@ writeMediaWiki opts document =
-- | Return MediaWiki representation of document.
pandocToMediaWiki :: WriterOptions -> Pandoc -> State WriterState String
pandocToMediaWiki opts (Pandoc _ blocks) = do
- return "" -- TODO
--- let before = writerIncludeBefore opts
--- let after = writerIncludeAfter opts
--- let head' = if writerStandalone opts
--- then writerHeader opts
--- else ""
--- let toc = if writerTableOfContents opts
--- then "__TOC__\n"
--- else ""
--- body <- blockListToMediaWiki opts blocks
--- notesExist <- get >>= return . stNotes
--- let notes = if notesExist
--- then "\n== Notes ==\n<references />"
--- else ""
--- return $ head' ++ before ++ toc ++ body ++ after ++ notes
+ let before = writerIncludeBefore opts
+ let after = writerIncludeAfter opts
+ body <- blockListToMediaWiki opts blocks
+ notesExist <- get >>= return . stNotes
+ let notes = if notesExist
+ then "\n== Notes ==\n<references />"
+ else ""
+ let main = before ++ body ++ after ++ notes
+ let context = writerVariables opts ++
+ [ ("body", main) ] ++
+ [ ("toc", "yes") | writerTableOfContents opts ]
+ if writerStandalone opts
+ then return $ renderTemplate context $ writerTemplate opts
+ else return main
-- | Escape special characters for MediaWiki.
escapeString :: String -> String
diff --git a/templates/mediawiki.template b/templates/mediawiki.template
index 993115ab9..b32808d65 100644
--- a/templates/mediawiki.template
+++ b/templates/mediawiki.template
@@ -1,75 +1,8 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml"
-><head
- ><title
- >title</title
- ><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
- /><meta name="generator" content="pandoc"
- /><meta name="author" content="$authors$"
- /><meta name="date" content="$date$"
- />$header-includes$
-</head
- ><body
- >
-<h1 class="title"
- ><span class="math"
- ><em
- >title</em
- ></span
- ></h1
- ><div id="TOC"
- ><ul
- ><li
- ><a href="#section-oen"
- >section oen</a
- ></li
- ></ul
- ></div
- ><div id="section-oen"
- ><h1
- ><a href="#TOC"
- >section oen</a
- ></h1
- ><ol style="list-style-type: decimal;"
- ><li
- >one<ol style="list-style-type: lower-alpha;"
- ><li
- >two<ol start="3" style="list-style-type: lower-roman;"
- ><li
- >three</li
- ></ol
- ></li
- ></ol
- ></li
- ></ol
- ><pre class="haskell"
- ><code
- >hi
-</code
- ></pre
- ><p
- >footnote<a href="#fn1" class="footnoteRef" id="fnref1"
- ><sup
- >1</sup
- ></a
- ></p
- ></div
- ><div class="footnotes"
- ><hr
- /><ol
- ><li id="fn1"
- ><p
- >with code</p
- ><pre
- ><code
- >code
-</code
- ></pre
- > <a href="#fnref1" class="footnoteBackLink" title="Jump back to footnote 1">&#8617;</a></li
- ></ol
- ></div
- >
-</body
- ></html
->
+$if(legacy-header)$
+$legacy-header$
+$endif$
+$if(toc)$
+__TOC__
+$endif$
+$body$
diff --git a/tests/writer.mediawiki b/tests/writer.mediawiki
index 4dd69708b..fe5ab5035 100644
--- a/tests/writer.mediawiki
+++ b/tests/writer.mediawiki
@@ -661,3 +661,4 @@ This paragraph should not be part of the note, as it is not indented.
== Notes ==
<references />
+