aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-12-02 22:42:29 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-12-02 22:42:29 +0000
commit430e55c0f1ca94fdb20b99061862af2ceabe4469 (patch)
treedc9e433e918496ab02cef9a6769b57c054b917ab
parent48410d1df03a79d0c9b9a26c761d80f13e51aead (diff)
downloadpandoc-430e55c0f1ca94fdb20b99061862af2ceabe4469.tar.gz
Handle --lhs-out option in HTML, LaTeX, and Markdown writers.
Documented lhs options in man page and README. Note: HTML output with --lhs-out is not strictly literate haskell, but it is designed so that the result of copying and pasting the page in the browser will be a literate haskell file. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1501 788f1e2b-df1e-0410-8736-df70ead52e1b
-rw-r--r--README14
-rw-r--r--Text/Pandoc/Writers/HTML.hs4
-rw-r--r--Text/Pandoc/Writers/LaTeX.hs12
-rw-r--r--Text/Pandoc/Writers/Markdown.hs3
-rw-r--r--man/man1/pandoc.1.md14
5 files changed, 42 insertions, 5 deletions
diff --git a/README b/README
index 230ad9c5b..f86c850ab 100644
--- a/README
+++ b/README
@@ -371,6 +371,20 @@ For further documentation, see the `pandoc(1)` man page.
are omitted. URIs in links and images are also checked against a
whitelist of URI schemes.
+`--lhs-in`
+: treat input as literate Haskell. In markdown input, "bird track"
+ sections will be treated as Haskell source code. In LaTeX input,
+ `code` environments will be treated as Haskell source code.
+
+`--lhs-out`
+: write output as literate Haskell. In markdown output, Haskell
+ source code will be printed with "bird tracks." In LaTeX output,
+ it will be put in `code` environments. In HTML output, it will
+ be put inside `<pre>` tags, with "bird tracks."
+
+`--lhs`
+: equivalent to `--lhs-in --lhs-out`.
+
`--dump-args`
: is intended to make it easier to create wrapper scripts that use
Pandoc. It causes Pandoc to dump information about the arguments
diff --git a/Text/Pandoc/Writers/HTML.hs b/Text/Pandoc/Writers/HTML.hs
index 8dafd2440..087fff623 100644
--- a/Text/Pandoc/Writers/HTML.hs
+++ b/Text/Pandoc/Writers/HTML.hs
@@ -297,6 +297,10 @@ blockToHtml opts (Plain lst) = inlineListToHtml opts lst
blockToHtml opts (Para lst) = inlineListToHtml opts lst >>= (return . paragraph)
blockToHtml _ (RawHtml str) = return $ primHtml str
blockToHtml _ (HorizontalRule) = return $ hr
+blockToHtml opts (CodeBlock (_,classes,_) rawCode) | "haskell" `elem` classes &&
+ writerLiterateHaskell opts =
+ let classes' = map (\c -> if c == "haskell" then "literatehaskell" else c) classes
+ in blockToHtml opts $ CodeBlock ("",classes',[]) $ intercalate "\n" $ map ("> " ++) $ lines rawCode
blockToHtml _ (CodeBlock attr@(_,classes,_) rawCode) = do
case highlightHtml attr rawCode of
Left _ -> -- change leading newlines into <br /> tags, because some
diff --git a/Text/Pandoc/Writers/LaTeX.hs b/Text/Pandoc/Writers/LaTeX.hs
index dd0e23981..f3cbf1acb 100644
--- a/Text/Pandoc/Writers/LaTeX.hs
+++ b/Text/Pandoc/Writers/LaTeX.hs
@@ -147,12 +147,14 @@ blockToLaTeX (Para lst) = do
blockToLaTeX (BlockQuote lst) = do
contents <- blockListToLaTeX lst
return $ text "\\begin{quote}" $$ contents $$ text "\\end{quote}"
-blockToLaTeX (CodeBlock _ str) = do
+blockToLaTeX (CodeBlock (_,classes,_) str) = do
st <- get
- env <- if stInNote st
- then do addToHeader "\\usepackage{fancyvrb}"
- return "Verbatim"
- else return "verbatim"
+ env <- if writerLiterateHaskell (stOptions st) && "haskell" `elem` classes
+ then return "code"
+ else if stInNote st
+ then do addToHeader "\\usepackage{fancyvrb}"
+ return "Verbatim"
+ else return "verbatim"
return $ text ("\\begin{" ++ env ++ "}\n") <> text str <>
text ("\n\\end{" ++ env ++ "}")
blockToLaTeX (RawHtml _) = return empty
diff --git a/Text/Pandoc/Writers/Markdown.hs b/Text/Pandoc/Writers/Markdown.hs
index 32ebcf758..4b365773f 100644
--- a/Text/Pandoc/Writers/Markdown.hs
+++ b/Text/Pandoc/Writers/Markdown.hs
@@ -185,6 +185,9 @@ blockToMarkdown _ HorizontalRule = return $ text "\n* * * * *\n"
blockToMarkdown opts (Header level inlines) = do
contents <- inlineListToMarkdown opts inlines
return $ text ((replicate level '#') ++ " ") <> contents <> text "\n"
+blockToMarkdown opts (CodeBlock (_,classes,_) str) | "haskell" `elem` classes &&
+ writerLiterateHaskell opts =
+ return $ (vcat $ map (text "> " <>) $ map text (lines str)) <> text "\n"
blockToMarkdown opts (CodeBlock _ str) = return $
(nest (writerTabStop opts) $ vcat $ map text (lines str)) <> text "\n"
blockToMarkdown opts (BlockQuote blocks) = do
diff --git a/man/man1/pandoc.1.md b/man/man1/pandoc.1.md
index bbd4e725e..bdd317c78 100644
--- a/man/man1/pandoc.1.md
+++ b/man/man1/pandoc.1.md
@@ -142,6 +142,20 @@ to Pandoc. Or use `html2markdown`(1), a wrapper around `pandoc`.
are omitted. URIs in links and images are also checked against a
whitelist of URI schemes.
+\--lhs-in
+: Treat input as literate Haskell. In markdown input, "bird track"
+ sections will be treated as Haskell source code. In LaTeX input,
+ `code` environments will be treated as Haskell source code.
+
+\--lhs-out
+: Write output as literate Haskell. In markdown output, Haskell
+ source code will be printed with "bird tracks." In LaTeX output,
+ it will be put in `code` environments. In HTML output, it will
+ be put inside `<pre>` tags, with "bird tracks."
+
+\--lhs
+: Equivalent to `--lhs-in --lhs-out`.
+
\--toc, \--table-of-contents
: Include an automatically generated table of contents (HTML, markdown,
RTF) or an instruction to create one (LaTeX, reStructuredText).