diff --git a/INSTALL.md b/INSTALL.md
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -7,7 +7,7 @@
   - For PDF output, you'll also need to install LaTeX.
     We recommend [MiKTeX](http://miktex.org/).
 
-  - If you'd prefer, you can extract the pandoc and pandoc-citeproc
+  - If you'd prefer, you can extract the `pandoc` and `pandoc-citeproc`
     executables from the MSI and copy them directly to any directory,
     without running the installer.  Here is an example showing how to
     extract the executables from the pandoc-1.19.1 installer and copy
@@ -21,6 +21,9 @@
 
 ## macOS
 
+  - You can install pandoc using
+    [homebrew](http://brew.sh): `brew install pandoc`.
+
   - There is a package installer at pandoc's [download page].
     If you later want to uninstall the package, you can do so
     by downloading [this script][uninstaller]
@@ -36,9 +39,6 @@
         cat pandoc.pkg/Payload | gunzip -dc | cpio -i
         # executables are now in ./usr/bin/, man pages in ./usr/share/man
 
-  - You can also install pandoc using
-    [homebrew](http://brew.sh): `brew install pandoc`.
-
   - For PDF output, you'll also need LaTeX.  Because a full [MacTeX]
     installation takes more than a gigabyte of disk space, we recommend
     installing [BasicTeX](http://www.tug.org/mactex/morepackages.html)
@@ -56,37 +56,36 @@
     old.
 
   - We provide a binary package for amd64 architecture on
-    the [download page].  This provides both pandoc and
-    pandoc-citeproc. The executables are statically linked and
-    have no dynamic dependencies.  Both a tarball and a deb
-    installer are provided.
+    the [download page].  This provides both `pandoc` and
+    `pandoc-citeproc`. The executables are statically linked and
+    have no dynamic dependencies or dependencies on external
+    data files.  Note:  because of the static
+    linking, the pandoc binary from this package cannot use lua
+    filters that require external lua modules written in C.
 
-        sudo dpkg -i $DEB
+    Both a tarball and a deb installer are provided.  To install the deb:
 
-    where `$DEB` is the path to the downloaded deb, will
-    install the `pandoc` and `pandoc-citeproc` executables
-    and man pages.
+        sudo dpkg -i $DEB
 
-    Note:  because it is statically linked, the pandoc
-    binary from this package cannot use lua filters that
-    require external lua modules written in C.
+    where `$DEB` is the path to the downloaded deb.  This will
+    install the `pandoc` and `pandoc-citeproc` executables and
+    man pages.
 
-  - If you use an RPM-based distro, you may be
-    able to install the deb from our download page
-    using `alien`. Or try
+    If you use an RPM-based distro, you may be able to install
+    the deb from our download page using `alien`.
 
-        ar p $DEB data.tar.gz | sudo tar xvz --strip-components 2 -C /usr/local
+    On any distro, you may install from the tarball into `$DEST`
+    (say, `/usr/local/` or `$HOME/.local`) by doing
 
-  - If you'd rather install pandoc in your home directory, say
-    in `$HOME/.local`, then you can unzip the tarball or
-    extract the files manually from the deb:
+        tar xvzf $TGZ --strip-components 1 -C $DEST
 
-        ar p $DEB data.tar.gz | tar xvz --strip-components 2 -C $HOME/.local/
+    where `$TGZ` is the path to the downloaded zipped tarball.
+    For Pandoc versions before 2.0, which don't provide
+    a tarball, try instead
 
-    where, again, `$DEB` is the path to the downloaded deb.
+        ar p $DEB data.tar.gz | tar xvz --strip-components 2 -C $DEST
 
-  - If the version in your repository is too old and you cannot
-    use the deb we provide, you can install from source, using the
+  - You can also install from source, using the
     instructions below under [Compiling from source].
     Note that most distros have the Haskell platform in their
     package repositories.  For example, on Debian/Ubuntu,
diff --git a/MANUAL.txt b/MANUAL.txt
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -1,6 +1,6 @@
 % Pandoc User's Guide
 % John MacFarlane
-% November 4, 2017
+% November 11, 2017
 
 Synopsis
 ========
@@ -279,7 +279,7 @@
     `org` (Emacs Org mode), `mediawiki` (MediaWiki markup), `twiki` (TWiki
     markup), `tikiwiki` (TikiWiki markup), `creole` (Creole 1.0),
     `haddock` (Haddock markup), or `latex` (LaTeX).
-    (`markdown_github` provides deprecated and less accurate suppport
+    (`markdown_github` provides deprecated and less accurate support
     for Github-Flavored Markdown; please use `gfm` instead, unless you
     need to use extensions other than `smart`.)
     If `+lhs` is appended to `markdown`, `rst`, `latex`, or
@@ -321,7 +321,7 @@
     `revealjs` (reveal.js HTML5 + JavaScript slide show), `s5`
     (S5 HTML and JavaScript slide show), or the path of a custom
     lua writer (see [Custom writers], below). (`markdown_github`
-    provides deprecated and less accurate suppport for
+    provides deprecated and less accurate support for
     Github-Flavored Markdown; please use `gfm` instead, unless
     you use extensions that do not work with `gfm`.) Note that `odt`,
     `epub`, and `epub3` output will not be directed to *stdout*;
@@ -1075,53 +1075,37 @@
 Math rendering in HTML
 ----------------------
 
-`-m` [*URL*], `--latexmathml`[`=`*URL*]
-
-:   Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
-    To insert a link to a local copy of the `LaTeXMathML.js` script,
-    provide a *URL*. If no *URL* is provided, the contents of the
-    script will be inserted directly into the HTML header, preserving
-    portability at the price of efficiency. If you plan to use math on
-    several pages, it is much better to link to a copy of the script,
-    so it can be cached.
-
-`--mathml`
-
-:   Convert TeX math to [MathML] (in `docbook4`, `docbook5`, `jats`,
-    `html4` and `html5`).  This is the default in `odt` output.
-
-`--jsmath`[`=`*URL*]
-
-:   Use [jsMath] to display embedded TeX math in HTML output.
-    The *URL* should point to the jsMath load script (e.g.
-    `jsMath/easy/load.js`); if provided, it will be linked to in
-    the header of standalone HTML documents. If a *URL* is not provided,
-    no link to the jsMath load script will be inserted; it is then
-    up to the author to provide such a link in the HTML template.
+The default is to render TeX math as far as possible using Unicode characters.
+Formulas are put inside a `span` with `class="math"`, so that they may be styled
+differently from the surrounding text if needed. However, this gives acceptable
+results only for basic math, usually you will want to use `--mathjax` or another
+of the following options.
 
 `--mathjax`[`=`*URL*]
 
 :   Use [MathJax] to display embedded TeX math in HTML output.
+    TeX math will be put between `\(...\)` (for inline math)
+    or `\[...\]` (for display math) and wrapped in `<span>` tags
+    with class `math`. Then the MathJax JavaScript will render it.
     The *URL* should point to the `MathJax.js` load script.
-    If a *URL* is not provided, a link to the MathJax CDN will
+    If a *URL* is not provided, a link to the Cloudflare CDN will
     be inserted.
-
-`--gladtex`
-
-:   Enclose TeX math in `<eq>` tags in HTML output.  These can then
-    be processed by [gladTeX] to produce links to images of the typeset
-    formulas.
-
-`--mimetex`[`=`*URL*]
+ 
+`--mathml`
 
-:   Render TeX math using the [mimeTeX] CGI script.  If *URL* is not
-    specified, it is assumed that the script is at `/cgi-bin/mimetex.cgi`.
+:   Convert TeX math to [MathML] (in `epub3`, `docbook4`, `docbook5`, `jats`,
+    `html4` and `html5`).  This is the default in `odt` output. Note that
+    currently only Firefox and Safari (and select e-book readers) natively
+    support MathML.
 
 `--webtex`[`=`*URL*]
 
-:   Render TeX formulas using an external script that converts TeX
-    formulas to images. The formula will be concatenated with the URL
-    provided. If *URL* is not specified, the CodeCogs will be used.
+:   Convert TeX formulas to `<img>` tags that link to an external script
+    that converts formulas to images. The formula will be URL-encoded
+    and concatenated with the URL provided. For SVG images you can for
+    example use `--webtex https://latex.codecogs.com/svg.latex?`.
+    If no URL is specified, the CodeCogs URL generating PNGs
+    will be used (`https://latex.codecogs.com/png.latex?`).
     Note:  the `--webtex` option will affect Markdown output
     as well as HTML, which is useful if you're targeting a
     version of Markdown without native math support.
@@ -1131,7 +1115,6 @@
 :   Use [KaTeX] to display embedded TeX math in HTML output.
     The *URL* is the base URL for the KaTeX library. If a *URL* is
     not provided, a link to the KaTeX CDN will be inserted.
-    Note: [KaTeX] seems to work best with `html5` output.
 
 `--katex-stylesheet=`*URL*
 
@@ -1139,6 +1122,48 @@
     not specified, a link to the KaTeX CDN will be inserted. Note that this
     option does not imply `--katex`.
 
+`-m` [*URL*], `--latexmathml`[`=`*URL*]
+
+:   *Deprecated.*
+    Use the [LaTeXMathML] script to display embedded TeX math in HTML output.
+    TeX math will be displayed between `$` or `$$` characters and put in
+    `<span>` tags with class `LaTeX`. The LaTeXMathML JavaScript will then
+    change it to MathML. Note that currently only Firefox and Safari
+    (and select e-book readers) natively support MathML.
+    To insert a link the `LaTeXMathML.js` script, provide a *URL*.
+
+`--jsmath`[`=`*URL*]
+
+:   *Deprecated.*
+    Use [jsMath] (the predecessor of MathJax) to display embedded TeX
+    math in HTML output. TeX math will be put inside `<span>` tags
+    (for inline math) or `<div>` tags (for display math) with class
+    `math` and rendered by the jsMath script. The *URL* should point to
+    the script (e.g. `jsMath/easy/load.js`); if provided, it will be linked
+    to in the header of standalone HTML documents. If a *URL* is not provided,
+    no link to the jsMath load script will be inserted; it is then
+    up to the author to provide such a link in the HTML template.
+
+`--gladtex`
+
+:   *Deprecated.*
+    Enclose TeX math in `<eq>` tags in HTML output.  The resulting HTML
+    can then be processed by [gladTeX] to produce images of the typeset
+    formulas and an HTML file with links to these images.
+    So, the procedure is:
+
+        pandoc -s --gladtex input.md -o myfile.htex
+        gladtex -d myfile-images myfile.htex
+        # produces myfile.html and images in myfile-images
+
+`--mimetex`[`=`*URL*]
+
+:   *Deprecated.*
+    Render TeX math using the [mimeTeX] CGI script, which generates an
+    image for each TeX formula. This should work in all browsers. If
+    *URL* is not specified, it is assumed that the script is at
+    `/cgi-bin/mimetex.cgi`.
+
 [MathML]: http://www.w3.org/Math/
 [LaTeXMathML]: http://math.etsu.edu/LaTeXMathML/
 [jsMath]: http://www.math.union.edu/~dpvc/jsmath/
@@ -2970,53 +2995,8 @@
 
 HTML, Slidy, DZSlides, S5, EPUB
   ~ The way math is rendered in HTML will depend on the
-    command-line options selected:
-
-    1.  The default is to render TeX math as far as possible using Unicode
-        characters, as with RTF, DocBook, and OpenDocument output. Formulas
-        are put inside a `span` with `class="math"`, so that they may be
-        styled differently from the surrounding text if needed.
-
-    2.  If the `--latexmathml` option is used, TeX math will be displayed
-        between `$` or `$$` characters and put in `<span>` tags with class `LaTeX`.
-        The [LaTeXMathML] script will be used to render it as formulas.
-        (This trick does not work in all browsers, but it works in Firefox.
-        In browsers that do not support LaTeXMathML, TeX math will appear
-        verbatim between `$` characters.)
-
-    3.  If the `--jsmath` option is used, TeX math will be put inside
-        `<span>` tags (for inline math) or `<div>` tags (for display math)
-        with class `math`.  The [jsMath] script will be used to render
-        it.
-
-    4.  If the `--mimetex` option is used, the [mimeTeX] CGI script will
-        be called to generate images for each TeX formula. This should
-        work in all browsers. The `--mimetex` option takes an optional URL
-        as argument. If no URL is specified, it will be assumed that the
-        mimeTeX CGI script is at `/cgi-bin/mimetex.cgi`.
-
-    5.  If the `--gladtex` option is used, TeX formulas will be enclosed
-        in `<eq>` tags in the HTML output.  The resulting `htex` file may then
-        be processed by [gladTeX], which will produce image files for each
-        formula and an HTML file with links to these images.  So, the
-        procedure is:
-
-            pandoc -s --gladtex myfile.txt -o myfile.htex
-            gladtex -d myfile-images myfile.htex
-            # produces myfile.html and images in myfile-images
-
-    6.  If the `--webtex` option is used, TeX formulas will be converted
-        to `<img>` tags that link to an external script that converts
-        formulas to images. The formula will be URL-encoded and concatenated
-        with the URL provided. For SVG images you can for example use
-        `--webtex https://latex.codecogs.com/svg.latex?`.
-        If no URL is specified, the CodeCogs URL generating PNGs
-        will be used (`https://latex.codecogs.com/png.latex?`).
-
-    7.  If the `--mathjax` option is used, TeX math will be displayed
-        between `\(...\)` (for inline math) or `\[...\]` (for display
-        math) and put in `<span>` tags with class `math`.
-        The [MathJax] script will be used to render it as formulas.
+    command-line options selected. Therefore see [Math rendering in HTML]
+    above.
 
 [interpreted text role `:math:`]: http://docutils.sourceforge.net/docs/ref/rst/roles.html#math
 
@@ -3717,7 +3697,7 @@
 than `ignore_line_breaks` for texts that include a mix of East
 Asian wide characters and other characters.
 
-##### Extension: `emoji` ####
+#### Extension: `emoji` ####
 
 Parses textual emojis like `:smile:` as Unicode emoticons.
 
diff --git a/changelog b/changelog
--- a/changelog
+++ b/changelog
@@ -1,3 +1,65 @@
+pandoc (2.0.2)
+
+  * Deprecated ancient HTML math methods: `--latexmathml`, `--gladtex`,
+    `--mimetex`, `--jsmath`.
+
+  * Fixed URIs in `data/jats.csl`.  They were being rendered twice,
+    leading to invalid XML in default JATS output with pandoc-citeproc.
+
+  * `lua-filters.md`: use real-world man page filter as example.
+
+  * Add lua filter functions `walk_inline` and `walk_block`
+    in the pandoc module, to apply filters inside particular
+    inline and block elements.
+
+  * Refactored some code from `Text.Pandoc.Lua.PandocModule`
+    into new internal module `Text.Pandoc.Lua.Filter`.
+
+  * Markdown reader:
+
+    + Allow fenced code blocks to be indented 1-3 spaces (#4011).
+      This brings our handling of them into alignment with CommonMark's.
+    + Fix YAML metadata with "chomp" (`|-`).  Previously if a
+      YAML block under `|-` contained a blank line, pandoc would
+      not parse it as metadata.
+
+  * Removed `etc.` from abbreviations file.  Often `etc.` ends a
+    sentence, and we want the period to be treated as a
+    sentence-ending period.
+
+  * Fix regression with `--metadata` (#4054).  Values specified with
+    `--metadata` should replace a metadata value set in the document
+    itself, rather than creating a list including a new value.
+
+  * EPUB writer:
+
+    + Fix EPUB OCF structure.  #3720 had been improperly implemented.
+    + Fix modified paths for raw HTML tags (src, poster, etc.)
+      (#4050, #4055). This had not been updated for the new EPUB
+      container layout, with a separate text/ subdirectory.
+    + Fix image paths with empty `--epub-subdirectory`.
+
+  * Miscellaneous code cleanup (Alexander Krotov).
+
+  * Use pandoc-types 1.17.3, which adds `Walkable` instances
+    for `[Block] Block` and `[Inline] Inline`.
+
+  * Remove obsolete `stack.full.yaml` (#4052).
+
+  * Change to using pandoc-citeproc 0.12.1 in binary packages.
+
+  * Consolidate math output method documentation (#4049, Mauro Bieg).
+
+  * `MANUAL.txt`: fix header level of "Extension: emoji" (Albert Krewinkel).
+
+  * Use lua filter to generate man page from `MANUAL.txt`, replacing old
+    Haskell filters.  This is easier and faster.
+
+  * Improved `INSTALL.md`.
+
+  * Update commands to extract deb archive on Linux (#4043, Salim B).
+
+
 pandoc (2.0.1.1)
 
   * Improved fix to #3989 (parsing of HTML tags containing
diff --git a/data/abbreviations b/data/abbreviations
--- a/data/abbreviations
+++ b/data/abbreviations
@@ -12,7 +12,6 @@
 Dr.
 e.g.
 esp.
-etc.
 Feb.
 Gen.
 Gov.
diff --git a/data/jats.csl b/data/jats.csl
--- a/data/jats.csl
+++ b/data/jats.csl
@@ -98,10 +98,7 @@
     </choose>
     <choose>
       <if variable="URL" match="any">
-        <group prefix="{{jats}}&lt;ext-link ext-link-type=&quot;uri&quot; {{/jats}}" suffix="{{jats}}&lt;/ext-link&gt;{{/jats}}">
-          <text variable="URL" prefix="{{jats}}xlink:href=&quot;{{/jats}}" suffix="{{jats}}&quot; xlink:type=&quot;simple&quot;&gt;{{/jats}}"/>
-          <text variable="URL"/>
-        </group>
+        <text variable="URL" />
       </if>
     </choose>
   </macro>
diff --git a/man/capitalizeHeaders.hs b/man/capitalizeHeaders.hs
deleted file mode 100644
--- a/man/capitalizeHeaders.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-import Text.Pandoc.JSON
-import Text.Pandoc.Walk
-import Data.Char (toUpper)
-
-main :: IO ()
-main = toJSONFilter capitalizeHeaders
-
-capitalizeHeaders :: Block -> Block
-capitalizeHeaders (Header 1 attr xs) = Header 1 attr $ walk capitalize xs
-capitalizeHeaders x = x
-
-capitalize :: Inline -> Inline
-capitalize (Str xs) = Str $ map toUpper xs
-capitalize x = x
-
-{-
-capitalizeHeaderLinks :: Inline -> Inline
-capitalizeHeaderLinks (Link xs t@('#':_,_)) = Link (walk capitalize xs) t
-capitalizeHeaderLinks x = x
--}
diff --git a/man/manfilter.lua b/man/manfilter.lua
new file mode 100644
--- /dev/null
+++ b/man/manfilter.lua
@@ -0,0 +1,19 @@
+-- filters to create the pandoc man page from MANUAL.txt
+
+-- capitalize headers
+function Header(el)
+    if el.level == 1 then
+      return pandoc.walk_block(el, {
+        Str = function(el)
+            return pandoc.Str(el.text:upper())
+        end })
+    end
+end
+
+function Link(el)
+    return el.content
+end
+
+function Note(el)
+    return {}
+end
diff --git a/man/pandoc.1 b/man/pandoc.1
--- a/man/pandoc.1
+++ b/man/pandoc.1
@@ -1,10 +1,10 @@
 .\"t
-.TH PANDOC 1 "November 4, 2017" "pandoc 2.0.1.1"
+.TH PANDOC 1 "November 11, 2017" "pandoc 2.0.1.1"
 .SH NAME
 pandoc - general markup converter
 .SH SYNOPSIS
 .PP
-\f[C]pandoc\f[] [\f[I]options\f[]] [\f[I]input\-file\f[]]\&...
+\f[C]pandoc\f[] [\f[I]options\f[]] [\f[I]input\-file\f[]]...
 .SH DESCRIPTION
 .PP
 Pandoc is a Haskell library for converting from one markup format to
@@ -25,13 +25,13 @@
 \f[C]pdfroff\f[], \f[C]wkhtmltopdf\f[], \f[C]prince\f[], or
 \f[C]weasyprint\f[] is installed.
 .PP
-Pandoc's enhanced version of Markdown includes syntax for footnotes,
+Pandoc\[aq]s enhanced version of Markdown includes syntax for footnotes,
 tables, flexible ordered lists, definition lists, fenced code blocks,
 superscripts and subscripts, strikeout, metadata blocks, automatic
 tables of contents, embedded LaTeX math, citations, and Markdown inside
 HTML block elements.
-(These enhancements, described further under Pandoc's Markdown, can be
-disabled using the \f[C]markdown_strict\f[] input or output format.)
+(These enhancements, described further under Pandoc\[aq]s Markdown, can
+be disabled using the \f[C]markdown_strict\f[] input or output format.)
 .PP
 In contrast to most existing tools for converting Markdown to HTML,
 which use regex substitutions, pandoc has a modular design: it consists
@@ -41,16 +41,16 @@
 Thus, adding an input or output format requires only adding a reader or
 writer.
 .PP
-Because pandoc's intermediate representation of a document is less
+Because pandoc\[aq]s intermediate representation of a document is less
 expressive than many of the formats it converts between, one should not
 expect perfect conversions between every format and every other.
 Pandoc attempts to preserve the structural elements of a document, but
 not formatting details such as margin size.
 And some document elements, such as complex tables, may not fit into
-pandoc's simple document model.
-While conversions from pandoc's Markdown to all formats aspire to be
-perfect, conversions from formats more expressive than pandoc's Markdown
-can be expected to be lossy.
+pandoc\[aq]s simple document model.
+While conversions from pandoc\[aq]s Markdown to all formats aspire to be
+perfect, conversions from formats more expressive than pandoc\[aq]s
+Markdown can be expected to be lossy.
 .SS Using \f[C]pandoc\f[]
 .PP
 If no \f[I]input\-file\f[] is specified, input is read from
@@ -150,11 +150,11 @@
 .PP
 will convert \f[C]hello.txt\f[] from Markdown to LaTeX.
 If no output file is specified (so that output goes to \f[I]stdout\f[]),
-or if the output file's extension is unknown, the output format will
+or if the output file\[aq]s extension is unknown, the output format will
 default to HTML.
 If no input file is specified (so that input comes from \f[I]stdin\f[]),
-or if the input files' extensions are unknown, the input format will be
-assumed to be Markdown unless explicitly specified.
+or if the input files\[aq] extensions are unknown, the input format will
+be assumed to be Markdown unless explicitly specified.
 .PP
 Pandoc uses the UTF\-8 character encoding for both input and output.
 If your local character encoding is not UTF\-8, you should pipe input
@@ -228,7 +228,7 @@
 .B \f[C]\-f\f[] \f[I]FORMAT\f[], \f[C]\-r\f[] \f[I]FORMAT\f[], \f[C]\-\-from=\f[]\f[I]FORMAT\f[], \f[C]\-\-read=\f[]\f[I]FORMAT\f[]
 Specify input format.
 \f[I]FORMAT\f[] can be \f[C]native\f[] (native Haskell), \f[C]json\f[]
-(JSON version of native AST), \f[C]markdown\f[] (pandoc's extended
+(JSON version of native AST), \f[C]markdown\f[] (pandoc\[aq]s extended
 Markdown), \f[C]markdown_strict\f[] (original unextended Markdown),
 \f[C]markdown_phpextra\f[] (PHP Markdown Extra), \f[C]markdown_mmd\f[]
 (MultiMarkdown), \f[C]gfm\f[] (GitHub\-Flavored Markdown),
@@ -239,7 +239,7 @@
 Org mode), \f[C]mediawiki\f[] (MediaWiki markup), \f[C]twiki\f[] (TWiki
 markup), \f[C]tikiwiki\f[] (TikiWiki markup), \f[C]creole\f[] (Creole
 1.0), \f[C]haddock\f[] (Haddock markup), or \f[C]latex\f[] (LaTeX).
-(\f[C]markdown_github\f[] provides deprecated and less accurate suppport
+(\f[C]markdown_github\f[] provides deprecated and less accurate support
 for Github\-Flavored Markdown; please use \f[C]gfm\f[] instead, unless
 you need to use extensions other than \f[C]smart\f[].) If \f[C]+lhs\f[]
 is appended to \f[C]markdown\f[], \f[C]rst\f[], \f[C]latex\f[], or
@@ -250,9 +250,10 @@
 name.
 So, for example, \f[C]markdown_strict+footnotes+definition_lists\f[] is
 strict Markdown with footnotes and definition lists enabled, and
-\f[C]markdown\-pipe_tables+hard_line_breaks\f[] is pandoc's Markdown
+\f[C]markdown\-pipe_tables+hard_line_breaks\f[] is pandoc\[aq]s Markdown
 without pipe tables and with hard line breaks.
-See Pandoc's Markdown, below, for a list of extensions and their names.
+See Pandoc\[aq]s Markdown, below, for a list of extensions and their
+names.
 See \f[C]\-\-list\-input\-formats\f[] and \f[C]\-\-list\-extensions\f[],
 below.
 .RS
@@ -262,16 +263,17 @@
 Specify output format.
 \f[I]FORMAT\f[] can be \f[C]native\f[] (native Haskell), \f[C]json\f[]
 (JSON version of native AST), \f[C]plain\f[] (plain text),
-\f[C]markdown\f[] (pandoc's extended Markdown), \f[C]markdown_strict\f[]
-(original unextended Markdown), \f[C]markdown_phpextra\f[] (PHP Markdown
-Extra), \f[C]markdown_mmd\f[] (MultiMarkdown), \f[C]gfm\f[]
-(GitHub\-Flavored Markdown), \f[C]commonmark\f[] (CommonMark Markdown),
-\f[C]rst\f[] (reStructuredText), \f[C]html4\f[] (XHTML 1.0
-Transitional), \f[C]html\f[] or \f[C]html5\f[] (HTML5/XHTML polyglot
-markup), \f[C]latex\f[] (LaTeX), \f[C]beamer\f[] (LaTeX beamer slide
-show), \f[C]context\f[] (ConTeXt), \f[C]man\f[] (groff man),
-\f[C]mediawiki\f[] (MediaWiki markup), \f[C]dokuwiki\f[] (DokuWiki
-markup), \f[C]zimwiki\f[] (ZimWiki markup), \f[C]textile\f[] (Textile),
+\f[C]markdown\f[] (pandoc\[aq]s extended Markdown),
+\f[C]markdown_strict\f[] (original unextended Markdown),
+\f[C]markdown_phpextra\f[] (PHP Markdown Extra), \f[C]markdown_mmd\f[]
+(MultiMarkdown), \f[C]gfm\f[] (GitHub\-Flavored Markdown),
+\f[C]commonmark\f[] (CommonMark Markdown), \f[C]rst\f[]
+(reStructuredText), \f[C]html4\f[] (XHTML 1.0 Transitional),
+\f[C]html\f[] or \f[C]html5\f[] (HTML5/XHTML polyglot markup),
+\f[C]latex\f[] (LaTeX), \f[C]beamer\f[] (LaTeX beamer slide show),
+\f[C]context\f[] (ConTeXt), \f[C]man\f[] (groff man), \f[C]mediawiki\f[]
+(MediaWiki markup), \f[C]dokuwiki\f[] (DokuWiki markup),
+\f[C]zimwiki\f[] (ZimWiki markup), \f[C]textile\f[] (Textile),
 \f[C]org\f[] (Emacs Org mode), \f[C]texinfo\f[] (GNU Texinfo),
 \f[C]opml\f[] (OPML), \f[C]docbook\f[] or \f[C]docbook4\f[] (DocBook 4),
 \f[C]docbook5\f[] (DocBook 5), \f[C]jats\f[] (JATS XML),
@@ -286,7 +288,7 @@
 \f[C]revealjs\f[] (reveal.js HTML5 + JavaScript slide show), \f[C]s5\f[]
 (S5 HTML and JavaScript slide show), or the path of a custom lua writer
 (see Custom writers, below).
-(\f[C]markdown_github\f[] provides deprecated and less accurate suppport
+(\f[C]markdown_github\f[] provides deprecated and less accurate support
 for Github\-Flavored Markdown; please use \f[C]gfm\f[] instead, unless
 you use extensions that do not work with \f[C]gfm\f[].) Note that
 \f[C]odt\f[], \f[C]epub\f[], and \f[C]epub3\f[] output will not be
@@ -345,7 +347,7 @@
 at the output of \f[C]pandoc\ \-\-version\f[].
 A \f[C]reference.odt\f[], \f[C]reference.docx\f[], \f[C]epub.css\f[],
 \f[C]templates\f[], \f[C]slidy\f[], \f[C]slideous\f[], or \f[C]s5\f[]
-directory placed in this directory will override pandoc's normal
+directory placed in this directory will override pandoc\[aq]s normal
 defaults.
 .RE
 .TP
@@ -398,7 +400,7 @@
 .B \f[C]\-\-list\-extensions\f[]
 List supported Markdown extensions, one per line, followed by a
 \f[C]+\f[] or \f[C]\-\f[] indicating whether it is enabled by default in
-pandoc's Markdown.
+pandoc\[aq]s Markdown.
 .RS
 .RE
 .TP
@@ -430,7 +432,7 @@
 .RE
 .TP
 .B \f[C]\-\-indented\-code\-classes=\f[]\f[I]CLASSES\f[]
-Specify classes to use for indented code blocks\[en]for example,
+Specify classes to use for indented code blocks\-\-for example,
 \f[C]perl,numberLines\f[] or \f[C]haskell\f[].
 Multiple classes may be separated by spaces or commas.
 .RS
@@ -458,7 +460,7 @@
 Specify an executable to be used as a filter transforming the pandoc AST
 after the input is parsed and before the output is written.
 The executable should read JSON from stdin and write JSON to stdout.
-The JSON must be formatted like pandoc's own JSON input and output.
+The JSON must be formatted like pandoc\[aq]s own JSON input and output.
 The name of the output format will be passed to the filter as the first
 argument.
 Hence,
@@ -501,7 +503,8 @@
 .TP
 .B \f[C]\-\-lua\-filter=\f[]\f[I]SCRIPT\f[]
 Transform the document in a similar fashion as JSON filters (see
-\f[C]\-\-filter\f[]), but use pandoc's build\-in lua filtering system.
+\f[C]\-\-filter\f[]), but use pandoc\[aq]s build\-in lua filtering
+system.
 The given lua script is expected to return a list of lua filters which
 will be applied in order.
 Each lua filter must contain element\-transforming functions indexed by
@@ -511,7 +514,7 @@
 .PP
 The \f[C]pandoc\f[] lua module provides helper functions for element
 creation.
-It is always loaded into the script's lua environment.
+It is always loaded into the script\[aq]s lua environment.
 .PP
 The following is an example lua script for macro\-expansion:
 .IP
@@ -558,7 +561,7 @@
 .TP
 .B \f[C]\-\-track\-changes=accept\f[]|\f[C]reject\f[]|\f[C]all\f[]
 Specifies what to do with insertions, deletions, and comments produced
-by the MS Word \[lq]Track Changes\[rq] feature.
+by the MS Word "Track Changes" feature.
 \f[C]accept\f[] (the default), inserts all insertions, and ignores all
 deletions.
 \f[C]reject\f[] inserts all deletions and ignores insertions.
@@ -603,8 +606,8 @@
 .SS General writer options
 .TP
 .B \f[C]\-s\f[], \f[C]\-\-standalone\f[]
-Produce output with an appropriate header and footer (e.g.\ a standalone
-HTML, LaTeX, TEI, or RTF file, not a fragment).
+Produce output with an appropriate header and footer (e.g.
+a standalone HTML, LaTeX, TEI, or RTF file, not a fragment).
 This option is set automatically for \f[C]pdf\f[], \f[C]epub\f[],
 \f[C]epub3\f[], \f[C]fb2\f[], \f[C]docx\f[], and \f[C]odt\f[] output.
 .RS
@@ -760,8 +763,9 @@
 .TP
 .B \f[C]\-B\f[] \f[I]FILE\f[], \f[C]\-\-include\-before\-body=\f[]\f[I]FILE\f[]
 Include contents of \f[I]FILE\f[], verbatim, at the beginning of the
-document body (e.g.\ after the \f[C]<body>\f[] tag in HTML, or the
-\f[C]\\begin{document}\f[] command in LaTeX).
+document body (e.g.
+after the \f[C]<body>\f[] tag in HTML, or the \f[C]\\begin{document}\f[]
+command in LaTeX).
 This can be used to include navigation bars or banners in HTML
 documents.
 This option can be used repeatedly to include multiple files.
@@ -805,9 +809,9 @@
 Produce a standalone HTML file with no external dependencies, using
 \f[C]data:\f[] URIs to incorporate the contents of linked scripts,
 stylesheets, images, and videos.
-The resulting file should be \[lq]self\-contained,\[rq] in the sense
-that it needs no external files and no net access to be displayed
-properly by a browser.
+The resulting file should be "self\-contained," in the sense that it
+needs no external files and no net access to be displayed properly by a
+browser.
 This option works only with HTML output formats, including
 \f[C]html4\f[], \f[C]html5\f[], \f[C]html+lhs\f[], \f[C]html5+lhs\f[],
 \f[C]s5\f[], \f[C]slidy\f[], \f[C]slideous\f[], \f[C]dzslides\f[], and
@@ -821,9 +825,9 @@
 document.
 Limitation: resources that are loaded dynamically through JavaScript
 cannot be incorporated; as a result, \f[C]\-\-self\-contained\f[] does
-not work with \f[C]\-\-mathjax\f[], and some advanced features
-(e.g.\ zoom or speaker notes) may not work in an offline
-\[lq]self\-contained\[rq] \f[C]reveal.js\f[] slide show.
+not work with \f[C]\-\-mathjax\f[], and some advanced features (e.g.
+zoom or speaker notes) may not work in an offline "self\-contained"
+\f[C]reveal.js\f[] slide show.
 .RS
 .RE
 .TP
@@ -890,16 +894,15 @@
 .RS
 .RE
 .TP
-.B \f[C]\-\-number\-offset=\f[]\f[I]NUMBER\f[][\f[C],\f[]\f[I]NUMBER\f[]\f[C],\f[]\f[I]\&...\f[]]
+.B \f[C]\-\-number\-offset=\f[]\f[I]NUMBER\f[][\f[C],\f[]\f[I]NUMBER\f[]\f[C],\f[]\f[I]...\f[]]
 Offset for section headings in HTML output (ignored in other output
 formats).
 The first number is added to the section number for top\-level headers,
 the second for second\-level headers, and so on.
 So, for example, if you want the first top\-level header in your
-document to be numbered \[lq]6\[rq], specify
-\f[C]\-\-number\-offset=5\f[].
+document to be numbered "6", specify \f[C]\-\-number\-offset=5\f[].
 If your document starts with a level\-2 header which you want to be
-numbered \[lq]1.5\[rq], specify \f[C]\-\-number\-offset=1,4\f[].
+numbered "1.5", specify \f[C]\-\-number\-offset=1,4\f[].
 Offsets are 0 by default.
 Implies \f[C]\-\-number\-sections\f[].
 .RS
@@ -1111,7 +1114,7 @@
 .TP
 .B \f[C]\-\-epub\-chapter\-level=\f[]\f[I]NUMBER\f[]
 Specify the header level at which to split the EPUB into separate
-\[lq]chapter\[rq] files.
+"chapter" files.
 The default is to split into chapters at level 1 headers.
 This option only affects the internal composition of the EPUB, not the
 way chapters and sections are displayed to users.
@@ -1148,7 +1151,7 @@
 .SS Citation rendering
 .TP
 .B \f[C]\-\-bibliography=\f[]\f[I]FILE\f[]
-Set the \f[C]bibliography\f[] field in the document's metadata to
+Set the \f[C]bibliography\f[] field in the document\[aq]s metadata to
 \f[I]FILE\f[], overriding any value set in the metadata, and process
 citations using \f[C]pandoc\-citeproc\f[].
 (This is equivalent to
@@ -1162,15 +1165,15 @@
 .RE
 .TP
 .B \f[C]\-\-csl=\f[]\f[I]FILE\f[]
-Set the \f[C]csl\f[] field in the document's metadata to \f[I]FILE\f[],
-overriding any value set in the metadata.
+Set the \f[C]csl\f[] field in the document\[aq]s metadata to
+\f[I]FILE\f[], overriding any value set in the metadata.
 (This is equivalent to \f[C]\-\-metadata\ csl=FILE\f[].) This option is
 only relevant with \f[C]pandoc\-citeproc\f[].
 .RS
 .RE
 .TP
 .B \f[C]\-\-citation\-abbreviations=\f[]\f[I]FILE\f[]
-Set the \f[C]citation\-abbreviations\f[] field in the document's
+Set the \f[C]citation\-abbreviations\f[] field in the document\[aq]s
 metadata to \f[I]FILE\f[], overriding any value set in the metadata.
 (This is equivalent to
 \f[C]\-\-metadata\ citation\-abbreviations=FILE\f[].) This option is
@@ -1196,66 +1199,46 @@
 .RS
 .RE
 .SS Math rendering in HTML
-.TP
-.B \f[C]\-m\f[] [\f[I]URL\f[]], \f[C]\-\-latexmathml\f[][\f[C]=\f[]\f[I]URL\f[]]
-Use the LaTeXMathML script to display embedded TeX math in HTML output.
-To insert a link to a local copy of the \f[C]LaTeXMathML.js\f[] script,
-provide a \f[I]URL\f[].
-If no \f[I]URL\f[] is provided, the contents of the script will be
-inserted directly into the HTML header, preserving portability at the
-price of efficiency.
-If you plan to use math on several pages, it is much better to link to a
-copy of the script, so it can be cached.
-.RS
-.RE
-.TP
-.B \f[C]\-\-mathml\f[]
-Convert TeX math to MathML (in \f[C]docbook4\f[], \f[C]docbook5\f[],
-\f[C]jats\f[], \f[C]html4\f[] and \f[C]html5\f[]).
-This is the default in \f[C]odt\f[] output.
-.RS
-.RE
-.TP
-.B \f[C]\-\-jsmath\f[][\f[C]=\f[]\f[I]URL\f[]]
-Use jsMath to display embedded TeX math in HTML output.
-The \f[I]URL\f[] should point to the jsMath load script (e.g.
-\f[C]jsMath/easy/load.js\f[]); if provided, it will be linked to in the
-header of standalone HTML documents.
-If a \f[I]URL\f[] is not provided, no link to the jsMath load script
-will be inserted; it is then up to the author to provide such a link in
-the HTML template.
-.RS
-.RE
+.PP
+The default is to render TeX math as far as possible using Unicode
+characters.
+Formulas are put inside a \f[C]span\f[] with \f[C]class="math"\f[], so
+that they may be styled differently from the surrounding text if needed.
+However, this gives acceptable results only for basic math, usually you
+will want to use \f[C]\-\-mathjax\f[] or another of the following
+options.
 .TP
 .B \f[C]\-\-mathjax\f[][\f[C]=\f[]\f[I]URL\f[]]
 Use MathJax to display embedded TeX math in HTML output.
+TeX math will be put between \f[C]\\(...\\)\f[] (for inline math) or
+\f[C]\\[...\\]\f[] (for display math) and wrapped in \f[C]<span>\f[]
+tags with class \f[C]math\f[].
+Then the MathJax JavaScript will render it.
 The \f[I]URL\f[] should point to the \f[C]MathJax.js\f[] load script.
-If a \f[I]URL\f[] is not provided, a link to the MathJax CDN will be
+If a \f[I]URL\f[] is not provided, a link to the Cloudflare CDN will be
 inserted.
 .RS
 .RE
 .TP
-.B \f[C]\-\-gladtex\f[]
-Enclose TeX math in \f[C]<eq>\f[] tags in HTML output.
-These can then be processed by gladTeX to produce links to images of the
-typeset formulas.
-.RS
-.RE
-.TP
-.B \f[C]\-\-mimetex\f[][\f[C]=\f[]\f[I]URL\f[]]
-Render TeX math using the mimeTeX CGI script.
-If \f[I]URL\f[] is not specified, it is assumed that the script is at
-\f[C]/cgi\-bin/mimetex.cgi\f[].
+.B \f[C]\-\-mathml\f[]
+Convert TeX math to MathML (in \f[C]epub3\f[], \f[C]docbook4\f[],
+\f[C]docbook5\f[], \f[C]jats\f[], \f[C]html4\f[] and \f[C]html5\f[]).
+This is the default in \f[C]odt\f[] output.
+Note that currently only Firefox and Safari (and select e\-book readers)
+natively support MathML.
 .RS
 .RE
 .TP
 .B \f[C]\-\-webtex\f[][\f[C]=\f[]\f[I]URL\f[]]
-Render TeX formulas using an external script that converts TeX formulas
-to images.
-The formula will be concatenated with the URL provided.
-If \f[I]URL\f[] is not specified, the CodeCogs will be used.
+Convert TeX formulas to \f[C]<img>\f[] tags that link to an external
+script that converts formulas to images.
+The formula will be URL\-encoded and concatenated with the URL provided.
+For SVG images you can for example use
+\f[C]\-\-webtex\ https://latex.codecogs.com/svg.latex?\f[].
+If no URL is specified, the CodeCogs URL generating PNGs will be used
+(\f[C]https://latex.codecogs.com/png.latex?\f[]).
 Note: the \f[C]\-\-webtex\f[] option will affect Markdown output as well
-as HTML, which is useful if you're targeting a version of Markdown
+as HTML, which is useful if you\[aq]re targeting a version of Markdown
 without native math support.
 .RS
 .RE
@@ -1265,7 +1248,6 @@
 The \f[I]URL\f[] is the base URL for the KaTeX library.
 If a \f[I]URL\f[] is not provided, a link to the KaTeX CDN will be
 inserted.
-Note: KaTeX seems to work best with \f[C]html5\f[] output.
 .RS
 .RE
 .TP
@@ -1276,6 +1258,60 @@
 Note that this option does not imply \f[C]\-\-katex\f[].
 .RS
 .RE
+.TP
+.B \f[C]\-m\f[] [\f[I]URL\f[]], \f[C]\-\-latexmathml\f[][\f[C]=\f[]\f[I]URL\f[]]
+\f[I]Deprecated.\f[] Use the LaTeXMathML script to display embedded TeX
+math in HTML output.
+TeX math will be displayed between \f[C]$\f[] or \f[C]$$\f[] characters
+and put in \f[C]<span>\f[] tags with class \f[C]LaTeX\f[].
+The LaTeXMathML JavaScript will then change it to MathML.
+Note that currently only Firefox and Safari (and select e\-book readers)
+natively support MathML.
+To insert a link the \f[C]LaTeXMathML.js\f[] script, provide a
+\f[I]URL\f[].
+.RS
+.RE
+.TP
+.B \f[C]\-\-jsmath\f[][\f[C]=\f[]\f[I]URL\f[]]
+\f[I]Deprecated.\f[] Use jsMath (the predecessor of MathJax) to display
+embedded TeX math in HTML output.
+TeX math will be put inside \f[C]<span>\f[] tags (for inline math) or
+\f[C]<div>\f[] tags (for display math) with class \f[C]math\f[] and
+rendered by the jsMath script.
+The \f[I]URL\f[] should point to the script (e.g.
+\f[C]jsMath/easy/load.js\f[]); if provided, it will be linked to in the
+header of standalone HTML documents.
+If a \f[I]URL\f[] is not provided, no link to the jsMath load script
+will be inserted; it is then up to the author to provide such a link in
+the HTML template.
+.RS
+.RE
+.TP
+.B \f[C]\-\-gladtex\f[]
+\f[I]Deprecated.\f[] Enclose TeX math in \f[C]<eq>\f[] tags in HTML
+output.
+The resulting HTML can then be processed by gladTeX to produce images of
+the typeset formulas and an HTML file with links to these images.
+So, the procedure is:
+.RS
+.IP
+.nf
+\f[C]
+pandoc\ \-s\ \-\-gladtex\ input.md\ \-o\ myfile.htex
+gladtex\ \-d\ myfile\-images\ myfile.htex
+#\ produces\ myfile.html\ and\ images\ in\ myfile\-images
+\f[]
+.fi
+.RE
+.TP
+.B \f[C]\-\-mimetex\f[][\f[C]=\f[]\f[I]URL\f[]]
+\f[I]Deprecated.\f[] Render TeX math using the mimeTeX CGI script, which
+generates an image for each TeX formula.
+This should work in all browsers.
+If \f[I]URL\f[] is not specified, it is assumed that the script is at
+\f[C]/cgi\-bin/mimetex.cgi\f[].
+.RS
+.RE
 .SS Options for wrapper scripts
 .TP
 .B \f[C]\-\-dump\-args\f[]
@@ -1461,7 +1497,7 @@
 .RE
 .TP
 .B \f[C]meta\-json\f[]
-JSON representation of all of the document's metadata.
+JSON representation of all of the document\[aq]s metadata.
 Field values are transformed to the selected output format.
 .RS
 .RE
@@ -1504,8 +1540,8 @@
 \f[C]div\f[]s with the \f[C]dir\f[] attribute (value \f[C]rtl\f[] or
 \f[C]ltr\f[]) can be used to override the base direction in some output
 formats.
-This may not always be necessary if the final renderer (e.g.\ the
-browser, when generating HTML) supports the Unicode Bidirectional
+This may not always be necessary if the final renderer (e.g.
+the browser, when generating HTML) supports the Unicode Bidirectional
 Algorithm.
 .PP
 When using LaTeX for bidirectional documents, only the \f[C]xelatex\f[]
@@ -1565,8 +1601,8 @@
 .RE
 .TP
 .B \f[C]section\-titles\f[]
-enables on \[lq]title pages\[rq] for new sections in \f[C]beamer\f[]
-documents (default = true).
+enables on "title pages" for new sections in \f[C]beamer\f[] documents
+(default = true).
 .RS
 .RE
 .TP
@@ -1974,10 +2010,10 @@
 .PP
 Templates may contain comments: anything on a line after \f[C]$\-\-\f[]
 will be treated as a comment and ignored.
-.SH PANDOC'S MARKDOWN
+.SH PANDOC\[aq]S MARKDOWN
 .PP
 Pandoc understands an extended and slightly revised version of John
-Gruber's Markdown syntax.
+Gruber\[aq]s Markdown syntax.
 This document explains the syntax, noting differences from standard
 Markdown.
 Except where noted, these differences can be suppressed by using the
@@ -1986,7 +2022,7 @@
 name and disabled by adding \f[C]\-EXTENSION\f[].
 For example, \f[C]markdown_strict+footnotes\f[] is strict Markdown with
 footnotes enabled, while \f[C]markdown\-footnotes\-pipe_tables\f[] is
-pandoc's Markdown without footnotes or pipe tables.
+pandoc\[aq]s Markdown without footnotes or pipe tables.
 .SS Philosophy
 .PP
 Markdown is designed to be easy to write, and, even more importantly,
@@ -1994,16 +2030,16 @@
 .RS
 .PP
 A Markdown\-formatted document should be publishable as\-is, as plain
-text, without looking like it's been marked up with tags or formatting
-instructions.
-\[en] John Gruber
+text, without looking like it\[aq]s been marked up with tags or
+formatting instructions.
+\-\- John Gruber
 .RE
 .PP
-This principle has guided pandoc's decisions in finding syntax for
+This principle has guided pandoc\[aq]s decisions in finding syntax for
 tables, footnotes, and other extensions.
 .PP
-There is, however, one respect in which pandoc's aims are different from
-the original aims of Markdown.
+There is, however, one respect in which pandoc\[aq]s aims are different
+from the original aims of Markdown.
 Whereas Markdown was originally designed with HTML generation in mind,
 pandoc is designed for multiple output formats.
 Thus, while pandoc allows the embedding of raw HTML, it discourages it,
@@ -2027,8 +2063,8 @@
 There are two kinds of headers: Setext and ATX.
 .SS Setext\-style headers
 .PP
-A setext\-style header is a line of text \[lq]underlined\[rq] with a row
-of \f[C]=\f[] signs (for a level one header) or \f[C]\-\f[] signs (for a
+A setext\-style header is a line of text "underlined" with a row of
+\f[C]=\f[] signs (for a level one header) or \f[C]\-\f[] signs (for a
 level two header):
 .IP
 .nf
@@ -2116,7 +2152,7 @@
 (This syntax is compatible with PHP Markdown Extra.)
 .PP
 Note that although this syntax allows assignment of classes and
-key/value attributes, writers generally don't use all of this
+key/value attributes, writers generally don\[aq]t use all of this
 information.
 Identifiers, classes, and key/value attributes are used in HTML and
 HTML\-based formats such as EPUB and slidy.
@@ -2315,8 +2351,8 @@
 \f[]
 .fi
 .PP
-A \[lq]lazy\[rq] form, which requires the \f[C]>\f[] character only on
-the first line of each block, is also allowed:
+A "lazy" form, which requires the \f[C]>\f[] character only on the first
+line of each block, is also allowed:
 .IP
 .nf
 \f[C]
@@ -2448,9 +2484,9 @@
 with value \f[C]100\f[].
 Some output formats can use this information to do syntax highlighting.
 Currently, the only output formats that uses this information are HTML,
-LaTeX, Docx, and Ms.\ If highlighting is supported for your output
-format and language, then the code block above will appear highlighted,
-with numbered lines.
+LaTeX, Docx, and Ms.
+If highlighting is supported for your output format and language, then
+the code block above will appear highlighted, with numbered lines.
 (To see which languages are supported, type
 \f[C]pandoc\ \-\-list\-highlight\-languages\f[].) Otherwise, the code
 block above will appear as follows:
@@ -2550,8 +2586,8 @@
 \f[]
 .fi
 .PP
-This will produce a \[lq]compact\[rq] list.
-If you want a \[lq]loose\[rq] list, in which each item is formatted as a
+This will produce a "compact" list.
+If you want a "loose" list, in which each item is formatted as a
 paragraph, put spaces between the items:
 .IP
 .nf
@@ -2579,7 +2615,7 @@
 \f[]
 .fi
 .PP
-But Markdown also allows a \[lq]lazy\[rq] format:
+But Markdown also allows a "lazy" format:
 .IP
 .nf
 \f[C]
@@ -2641,8 +2677,8 @@
 \f[]
 .fi
 .PP
-As noted above, Markdown allows you to write list items
-\[lq]lazily,\[rq] instead of indenting continuation lines.
+As noted above, Markdown allows you to write list items "lazily,"
+instead of indenting continuation lines.
 However, if there are multiple paragraphs or other blocks in a list
 item, the first line of each must be indented.
 .IP
@@ -2696,8 +2732,8 @@
 and, if the list marker is a capital letter with a period, by at least
 two spaces.
 .PP
-The \f[C]fancy_lists\f[] extension also allows `\f[C]#\f[]' to be used
-as an ordered list marker in place of a numeral:
+The \f[C]fancy_lists\f[] extension also allows \[aq]\f[C]#\f[]\[aq] to
+be used as an ordered list marker in place of a numeral:
 .IP
 .nf
 \f[C]
@@ -2779,9 +2815,8 @@
 indented four spaces or one tab stop.
 The body of the definition (including the first line, aside from the
 colon or tilde) should be indented four spaces.
-However, as with other Markdown lists, you can \[lq]lazily\[rq] omit
-indentation except at the beginning of a paragraph or other block
-element:
+However, as with other Markdown lists, you can "lazily" omit indentation
+except at the beginning of a paragraph or other block element:
 .IP
 .nf
 \f[C]
@@ -2813,16 +2848,16 @@
 .fi
 .PP
 Note that space between items in a definition list is required.
-(A variant that loosens this requirement, but disallows \[lq]lazy\[rq]
-hard wrapping, can be activated with \f[C]compact_definition_lists\f[]:
-see Non\-pandoc extensions, below.)
+(A variant that loosens this requirement, but disallows "lazy" hard
+wrapping, can be activated with \f[C]compact_definition_lists\f[]: see
+Non\-pandoc extensions, below.)
 .SS Numbered example lists
 .SS Extension: \f[C]example_lists\f[]
 .PP
 The special list marker \f[C]\@\f[] can be used for sequentially
 numbered examples.
-The first list item with a \f[C]\@\f[] marker will be numbered `1', the
-next `2', and so on, throughout the document.
+The first list item with a \f[C]\@\f[] marker will be numbered
+\[aq]1\[aq], the next \[aq]2\[aq], and so on, throughout the document.
 The numbered examples need not occur in a single list; each new list
 using \f[C]\@\f[] will take up where the last stopped.
 So, for example:
@@ -2853,8 +2888,8 @@
 hyphens.
 .SS Compact and loose lists
 .PP
-Pandoc behaves differently from \f[C]Markdown.pl\f[] on some \[lq]edge
-cases\[rq] involving lists.
+Pandoc behaves differently from \f[C]Markdown.pl\f[] on some "edge
+cases" involving lists.
 Consider this source:
 .IP
 .nf
@@ -2869,15 +2904,14 @@
 \f[]
 .fi
 .PP
-Pandoc transforms this into a \[lq]compact list\[rq] (with no
-\f[C]<p>\f[] tags around \[lq]First\[rq], \[lq]Second\[rq], or
-\[lq]Third\[rq]), while Markdown puts \f[C]<p>\f[] tags around
-\[lq]Second\[rq] and \[lq]Third\[rq] (but not \[lq]First\[rq]), because
-of the blank space around \[lq]Third\[rq].
+Pandoc transforms this into a "compact list" (with no \f[C]<p>\f[] tags
+around "First", "Second", or "Third"), while Markdown puts \f[C]<p>\f[]
+tags around "Second" and "Third" (but not "First"), because of the blank
+space around "Third".
 Pandoc follows a simple rule: if the text is followed by a blank line,
 it is treated as a paragraph.
-Since \[lq]Second\[rq] is followed by a list, and not a blank line, it
-isn't treated as a paragraph.
+Since "Second" is followed by a list, and not a blank line, it isn\[aq]t
+treated as a paragraph.
 The fact that the list is followed by a blank line is irrelevant.
 (Note: Pandoc works this way even when the \f[C]markdown_strict\f[]
 format is specified.
@@ -2901,9 +2935,9 @@
 \f[C]{\ my\ code\ block\ }\f[] as the second paragraph of item two, and
 not as a code block.
 .PP
-To \[lq]cut off\[rq] the list after item two, you can insert some
-non\-indented content, like an HTML comment, which won't produce visible
-output in any format:
+To "cut off" the list after item two, you can insert some non\-indented
+content, like an HTML comment, which won\[aq]t produce visible output in
+any format:
 .IP
 .nf
 \f[C]
@@ -3176,7 +3210,7 @@
 separator lines.
 .PP
 Note: pandoc also recognizes pipe tables of the following form, as can
-be produced by Emacs' orgtbl\-mode:
+be produced by Emacs\[aq] orgtbl\-mode:
 .IP
 .nf
 \f[C]
@@ -3189,8 +3223,8 @@
 .PP
 The difference is that \f[C]+\f[] is used instead of \f[C]|\f[].
 Other orgtbl features are not supported.
-In particular, to get non\-default column alignment, you'll need to add
-colons as above.
+In particular, to get non\-default column alignment, you\[aq]ll need to
+add colons as above.
 .SS Metadata blocks
 .SS Extension: \f[C]pandoc_title_block\f[]
 .PP
@@ -3255,13 +3289,13 @@
 .PP
 Title blocks will always be parsed, but they will affect the output only
 when the \f[C]\-\-standalone\f[] (\f[C]\-s\f[]) option is chosen.
-In HTML output, titles will appear twice: once in the document head
-\[en] this is the title that will appear at the top of the window in a
-browser \[en] and once at the beginning of the document body.
+In HTML output, titles will appear twice: once in the document head \-\-
+this is the title that will appear at the top of the window in a browser
+\-\- and once at the beginning of the document body.
 The title in the document head can have an optional prefix attached
 (\f[C]\-\-title\-prefix\f[] or \f[C]\-T\f[] option).
-The title in the body appears as an H1 element with class
-\[lq]title\[rq], so it can be suppressed or reformatted with CSS.
+The title in the body appears as an H1 element with class "title", so it
+can be suppressed or reformatted with CSS.
 If a title prefix is specified with \f[C]\-T\f[] and no title block
 appears in the document, the title prefix will be used by itself as the
 HTML title.
@@ -3290,7 +3324,7 @@
 \f[]
 .fi
 .PP
-will also have \[lq]Pandoc User Manuals\[rq] in the footer.
+will also have "Pandoc User Manuals" in the footer.
 .IP
 .nf
 \f[C]
@@ -3298,7 +3332,7 @@
 \f[]
 .fi
 .PP
-will also have \[lq]Version 4.0\[rq] in the header.
+will also have "Version 4.0" in the header.
 .SS Extension: \f[C]yaml_metadata_block\f[]
 .PP
 A YAML metadata block is a valid YAML object, delimited by a line of
@@ -3438,7 +3472,7 @@
 \f[]
 .fi
 .PP
-This rule is easier to remember than standard Markdown's rule, which
+This rule is easier to remember than standard Markdown\[aq]s rule, which
 allows only the following characters to be backslash\-escaped:
 .IP
 .nf
@@ -3454,11 +3488,12 @@
 It will appear in TeX output as \f[C]~\f[] and in HTML and XML as
 \f[C]\\&#160;\f[] or \f[C]\\&nbsp;\f[].
 .PP
-A backslash\-escaped newline (i.e.\ a backslash occurring at the end of
-a line) is parsed as a hard line break.
+A backslash\-escaped newline (i.e.
+a backslash occurring at the end of a line) is parsed as a hard line
+break.
 It will appear in TeX output as \f[C]\\\\\f[] and in HTML as
 \f[C]<br\ />\f[].
-This is a nice alternative to Markdown's \[lq]invisible\[rq] way of
+This is a nice alternative to Markdown\[aq]s "invisible" way of
 indicating hard line breaks using two trailing spaces on a line.
 .PP
 Backslash escapes do not work in verbatim contexts.
@@ -3533,8 +3568,8 @@
 must be escaped with backslashes.
 (This is to prevent accidental superscripting and subscripting through
 the ordinary use of \f[C]~\f[] and \f[C]^\f[].) Thus, if you want the
-letter P with `a cat' in subscripts, use \f[C]P~a\\\ cat~\f[], not
-\f[C]P~a\ cat~\f[].
+letter P with \[aq]a cat\[aq] in subscripts, use \f[C]P~a\\\ cat~\f[],
+not \f[C]P~a\ cat~\f[].
 .SS Verbatim
 .PP
 To make a short span of text verbatim, put it inside backticks:
@@ -3613,9 +3648,9 @@
 its right, while the closing \f[C]$\f[] must have a non\-space character
 immediately to its left, and must not be followed immediately by a
 digit.
-Thus, \f[C]$20,000\ and\ $30,000\f[] won't parse as math.
+Thus, \f[C]$20,000\ and\ $30,000\f[] won\[aq]t parse as math.
 If for some reason you need to enclose text in literal \f[C]$\f[]
-characters, backslash\-escape them and they won't be treated as math
+characters, backslash\-escape them and they won\[aq]t be treated as math
 delimiters.
 .PP
 TeX math will be printed in all output formats.
@@ -3642,7 +3677,7 @@
 .RE
 .TP
 .B groff man
-It will be rendered verbatim without \f[C]$\f[]'s.
+It will be rendered verbatim without \f[C]$\f[]\[aq]s.
 .RS
 .RE
 .TP
@@ -3689,65 +3724,10 @@
 .TP
 .B HTML, Slidy, DZSlides, S5, EPUB
 The way math is rendered in HTML will depend on the command\-line
-options selected:
+options selected.
+Therefore see Math rendering in HTML above.
 .RS
-.IP "1." 3
-The default is to render TeX math as far as possible using Unicode
-characters, as with RTF, DocBook, and OpenDocument output.
-Formulas are put inside a \f[C]span\f[] with \f[C]class="math"\f[], so
-that they may be styled differently from the surrounding text if needed.
-.IP "2." 3
-If the \f[C]\-\-latexmathml\f[] option is used, TeX math will be
-displayed between \f[C]$\f[] or \f[C]$$\f[] characters and put in
-\f[C]<span>\f[] tags with class \f[C]LaTeX\f[].
-The LaTeXMathML script will be used to render it as formulas.
-(This trick does not work in all browsers, but it works in Firefox.
-In browsers that do not support LaTeXMathML, TeX math will appear
-verbatim between \f[C]$\f[] characters.)
-.IP "3." 3
-If the \f[C]\-\-jsmath\f[] option is used, TeX math will be put inside
-\f[C]<span>\f[] tags (for inline math) or \f[C]<div>\f[] tags (for
-display math) with class \f[C]math\f[].
-The jsMath script will be used to render it.
-.IP "4." 3
-If the \f[C]\-\-mimetex\f[] option is used, the mimeTeX CGI script will
-be called to generate images for each TeX formula.
-This should work in all browsers.
-The \f[C]\-\-mimetex\f[] option takes an optional URL as argument.
-If no URL is specified, it will be assumed that the mimeTeX CGI script
-is at \f[C]/cgi\-bin/mimetex.cgi\f[].
-.IP "5." 3
-If the \f[C]\-\-gladtex\f[] option is used, TeX formulas will be
-enclosed in \f[C]<eq>\f[] tags in the HTML output.
-The resulting \f[C]htex\f[] file may then be processed by gladTeX, which
-will produce image files for each formula and an HTML file with links to
-these images.
-So, the procedure is:
-.RS 4
-.IP
-.nf
-\f[C]
-pandoc\ \-s\ \-\-gladtex\ myfile.txt\ \-o\ myfile.htex
-gladtex\ \-d\ myfile\-images\ myfile.htex
-#\ produces\ myfile.html\ and\ images\ in\ myfile\-images
-\f[]
-.fi
 .RE
-.IP "6." 3
-If the \f[C]\-\-webtex\f[] option is used, TeX formulas will be
-converted to \f[C]<img>\f[] tags that link to an external script that
-converts formulas to images.
-The formula will be URL\-encoded and concatenated with the URL provided.
-For SVG images you can for example use
-\f[C]\-\-webtex\ https://latex.codecogs.com/svg.latex?\f[].
-If no URL is specified, the CodeCogs URL generating PNGs will be used
-(\f[C]https://latex.codecogs.com/png.latex?\f[]).
-.IP "7." 3
-If the \f[C]\-\-mathjax\f[] option is used, TeX math will be displayed
-between \f[C]\\(...\\)\f[] (for inline math) or \f[C]\\[...\\]\f[] (for
-display math) and put in \f[C]<span>\f[] tags with class \f[C]math\f[].
-The MathJax script will be used to render it as formulas.
-.RE
 .SS Raw HTML
 .SS Extension: \f[C]raw_html\f[]
 .PP
@@ -3763,9 +3743,9 @@
 suppressed in other formats.
 .SS Extension: \f[C]markdown_in_html_blocks\f[]
 .PP
-Standard Markdown allows you to include HTML \[lq]blocks\[rq]: blocks of
-HTML between balanced tags that are separated from the surrounding text
-with blank lines, and start and end at the left margin.
+Standard Markdown allows you to include HTML "blocks": blocks of HTML
+between balanced tags that are separated from the surrounding text with
+blank lines, and start and end at the left margin.
 Within these blocks, everything is interpreted as HTML, not Markdown; so
 (for example), \f[C]*\f[] does not signify emphasis.
 .PP
@@ -4116,7 +4096,7 @@
 .SS Images
 .PP
 A link immediately preceded by a \f[C]!\f[] will be treated as an image.
-The link text will be used as the image's alt text:
+The link text will be used as the image\[aq]s alt text:
 .IP
 .nf
 \f[C]
@@ -4131,7 +4111,7 @@
 .PP
 An image with nonempty alt text, occurring by itself in a paragraph,
 will be rendered as a figure with a caption.
-The image's alt text will be used as the caption.
+The image\[aq]s alt text will be used as the caption.
 .IP
 .nf
 \f[C]
@@ -4140,8 +4120,9 @@
 .fi
 .PP
 How this is rendered depends on the output format.
-Some output formats (e.g.\ RTF) do not yet support figures.
-In those formats, you'll just get an image in a paragraph by itself,
+Some output formats (e.g.
+RTF) do not yet support figures.
+In those formats, you\[aq]ll just get an image in a paragraph by itself,
 with no caption.
 .PP
 If you just want a regular inline image, just make sure it is not the
@@ -4227,7 +4208,7 @@
 .SS Footnotes
 .SS Extension: \f[C]footnotes\f[]
 .PP
-Pandoc's Markdown allows footnotes, using the following syntax:
+Pandoc\[aq]s Markdown allows footnotes, using the following syntax:
 .IP
 .nf
 \f[C]
@@ -4282,11 +4263,10 @@
 Interpret straight quotes as curly quotes, \f[C]\-\-\-\f[] as
 em\-dashes, \f[C]\-\-\f[] as en\-dashes, and \f[C]\&...\f[] as ellipses.
 Nonbreaking spaces are inserted after certain abbreviations, such as
-\[lq]Mr.\[rq] This option currently affects the input formats
-\f[C]markdown\f[], \f[C]commonmark\f[], \f[C]latex\f[],
-\f[C]mediawiki\f[], \f[C]org\f[], \f[C]rst\f[], and \f[C]twiki\f[], and
-the output formats \f[C]markdown\f[], \f[C]latex\f[], and
-\f[C]context\f[].
+"Mr." This option currently affects the input formats \f[C]markdown\f[],
+\f[C]commonmark\f[], \f[C]latex\f[], \f[C]mediawiki\f[], \f[C]org\f[],
+\f[C]rst\f[], and \f[C]twiki\f[], and the output formats
+\f[C]markdown\f[], \f[C]latex\f[], and \f[C]context\f[].
 .PP
 Note: If you are \f[I]writing\f[] Markdown, then the \f[C]smart\f[]
 extension has the reverse effect: what would have been curly quotes
@@ -4436,7 +4416,7 @@
 As an alternative to specifying a bibliography file using
 \f[C]\-\-bibliography\f[] or the YAML metadata field
 \f[C]bibliography\f[], you can include the citation data directly in the
-\f[C]references\f[] field of the document's YAML metadata.
+\f[C]references\f[] field of the document\[aq]s YAML metadata.
 The field should contain an array of YAML\-encoded references, for
 example:
 .IP
@@ -4486,7 +4466,7 @@
 entries, add \f[C]link\-citations:\ true\f[] to your YAML metadata.
 .PP
 Citations go inside square brackets and are separated by semicolons.
-Each citation must have a key, composed of `\@' + the citation
+Each citation must have a key, composed of \[aq]\@\[aq] + the citation
 identifier from the database, and may optionally have a prefix, a
 locator, and a suffix.
 The citation key must begin with a letter, digit, or \f[C]_\f[], and may
@@ -4521,7 +4501,7 @@
 \f[C]s.v.\f[]/\f[C]s.vv.\f[]; \f[C]verse\f[], \f[C]v.\f[]/\f[C]vv.\f[];
 \f[C]volume\f[], \f[C]vol.\f[]/\f[C]vols.\f[]; \f[C]¶\f[]/\f[C]¶¶\f[];
 \f[C]§\f[]/\f[C]§§\f[].
-If no locator term is used, \[lq]page\[rq] is assumed.
+If no locator term is used, "page" is assumed.
 .PP
 A minus sign (\f[C]\-\f[]) before the \f[C]\@\f[] will suppress mention
 of the author in the citation.
@@ -4617,7 +4597,7 @@
 .PP
 Allow \f[C]<\f[] and \f[C]>\f[] to be backslash\-escaped, as they can be
 in GitHub flavored Markdown but not original Markdown.
-This is implied by pandoc's default \f[C]all_symbols_escapable\f[].
+This is implied by pandoc\[aq]s default \f[C]all_symbols_escapable\f[].
 .SS Extension: \f[C]lists_without_preceding_blankline\f[]
 .PP
 Allow a list to occur right after a paragraph, with no intervening blank
@@ -4745,15 +4725,15 @@
 No blank line is required between consecutive items of the definition
 list.
 .IP \[bu] 2
-To get a \[lq]tight\[rq] or \[lq]compact\[rq] list, omit space between
-consecutive items; the space between a term and its definition does not
-affect anything.
+To get a "tight" or "compact" list, omit space between consecutive
+items; the space between a term and its definition does not affect
+anything.
 .IP \[bu] 2
 Lazy wrapping of paragraphs is not allowed: the entire definition must
 be indented four spaces.
 .SS Markdown variants
 .PP
-In addition to pandoc's extended Markdown, the following Markdown
+In addition to pandoc\[aq]s extended Markdown, the following Markdown
 variants are supported:
 .TP
 .B \f[C]markdown_phpextra\f[] (PHP Markdown Extra)
@@ -4834,7 +4814,8 @@
 reveal.js.
 You can also produce a PDF slide show using LaTeX \f[C]beamer\f[].
 .PP
-Here's the Markdown source for a simple slide show, \f[C]habits.txt\f[]:
+Here\[aq]s the Markdown source for a simple slide show,
+\f[C]habits.txt\f[]:
 .IP
 .nf
 \f[C]
@@ -4929,20 +4910,20 @@
 Headers \f[I]below\f[] the slide level in the hierarchy create headers
 \f[I]within\f[] a slide.
 .IP \[bu] 2
-Headers \f[I]above\f[] the slide level in the hierarchy create
-\[lq]title slides,\[rq] which just contain the section title and help to
-break the slide show into sections.
+Headers \f[I]above\f[] the slide level in the hierarchy create "title
+slides," which just contain the section title and help to break the
+slide show into sections.
 .IP \[bu] 2
 Content \f[I]above\f[] the slide level will not appear in the slide
 show.
 .IP \[bu] 2
-A title page is constructed automatically from the document's title
+A title page is constructed automatically from the document\[aq]s title
 block, if present.
 (In the case of beamer, this can be disabled by commenting out some
 lines in the default template.)
 .PP
 These rules are designed to support many different styles of slide show.
-If you don't care about structuring your slides into sections and
+If you don\[aq]t care about structuring your slides into sections and
 subsections, you can just use level 1 headers for all each slide.
 (In that case, level 1 will be the slide level.) But you can also
 structure the slide show into sections, as in the example above.
@@ -4954,9 +4935,9 @@
 reveal.js.
 .SS Incremental lists
 .PP
-By default, these writers produce lists that display \[lq]all at
-once.\[rq] If you want your lists to display incrementally (one item at
-a time), use the \f[C]\-i\f[] option.
+By default, these writers produce lists that display "all at once." If
+you want your lists to display incrementally (one item at a time), use
+the \f[C]\-i\f[] option.
 If you want a particular list to depart from the default (that is, to
 display incrementally without the \f[C]\-i\f[] option and all at once
 with the \f[C]\-i\f[] option), put it in a block quote:
@@ -4972,8 +4953,8 @@
 single document.
 .SS Inserting pauses
 .PP
-You can add \[lq]pauses\[rq] within a slide by including a paragraph
-containing three dots, separated by spaces:
+You can add "pauses" within a slide by including a paragraph containing
+three dots, separated by spaces:
 .IP
 .nf
 \f[C]
@@ -4993,8 +4974,8 @@
 Slidy), or \f[C]$DATADIR/slideous\f[] (for Slideous), where
 \f[C]$DATADIR\f[] is the user data directory (see
 \f[C]\-\-data\-dir\f[], above).
-The originals may be found in pandoc's system data directory (generally
-\f[C]$CABALDIR/pandoc\-VERSION/s5/default\f[]).
+The originals may be found in pandoc\[aq]s system data directory
+(generally \f[C]$CABALDIR/pandoc\-VERSION/s5/default\f[]).
 Pandoc will look there for any files it does not find in the user data
 directory.
 .PP
@@ -5092,7 +5073,7 @@
 .fi
 .PP
 All of the other frame attributes described in Section 8.1 of the Beamer
-User's Guide may also be used: \f[C]allowdisplaybreaks\f[],
+User\[aq]s Guide may also be used: \f[C]allowdisplaybreaks\f[],
 \f[C]allowframebreaks\f[], \f[C]b\f[], \f[C]c\f[], \f[C]t\f[],
 \f[C]environment\f[], \f[C]label\f[], \f[C]plain\f[], \f[C]shrink\f[].
 .SH CREATING EPUBS WITH PANDOC
@@ -5153,8 +5134,8 @@
 Either a string value, or an object with fields \f[C]role\f[],
 \f[C]file\-as\f[], and \f[C]text\f[], or a list of such objects.
 Valid values for \f[C]role\f[] are MARC relators, but pandoc will
-attempt to translate the human\-readable versions (like \[lq]author\[rq]
-and \[lq]editor\[rq]) to the appropriate marc relators.
+attempt to translate the human\-readable versions (like "author" and
+"editor") to the appropriate marc relators.
 .RS
 .RE
 .TP
@@ -5276,23 +5257,24 @@
 only), pandoc will treat the document as literate Haskell source.
 This means that
 .IP \[bu] 2
-In Markdown input, \[lq]bird track\[rq] sections will be parsed as
-Haskell code rather than block quotations.
+In Markdown input, "bird track" sections will be parsed as Haskell code
+rather than block quotations.
 Text between \f[C]\\begin{code}\f[] and \f[C]\\end{code}\f[] will also
 be treated as Haskell code.
-For ATX\-style headers the character `=' will be used instead of `#'.
+For ATX\-style headers the character \[aq]=\[aq] will be used instead of
+\[aq]#\[aq].
 .IP \[bu] 2
 In Markdown output, code blocks with classes \f[C]haskell\f[] and
 \f[C]literate\f[] will be rendered using bird tracks, and block
 quotations will be indented one space, so they will not be treated as
 Haskell code.
 In addition, headers will be rendered setext\-style (with underlines)
-rather than ATX\-style (with `#' characters).
-(This is because ghc treats `#' characters in column 1 as introducing
-line numbers.)
+rather than ATX\-style (with \[aq]#\[aq] characters).
+(This is because ghc treats \[aq]#\[aq] characters in column 1 as
+introducing line numbers.)
 .IP \[bu] 2
-In restructured text input, \[lq]bird track\[rq] sections will be parsed
-as Haskell code.
+In restructured text input, "bird track" sections will be parsed as
+Haskell code.
 .IP \[bu] 2
 In restructured text output, code blocks with class \f[C]haskell\f[]
 will be rendered using bird tracks.
@@ -5327,8 +5309,9 @@
 and pasted as literate Haskell source.
 .PP
 Note that GHC expects the bird tracks in the first column, so indentend
-literate code blocks (e.g.\ inside an itemized environment) will not be
-picked up by the Haskell compiler.
+literate code blocks (e.g.
+inside an itemized environment) will not be picked up by the Haskell
+compiler.
 .SH SYNTAX HIGHLIGHTING
 .PP
 Pandoc will automatically highlight syntax in fenced code blocks that
@@ -5349,8 +5332,8 @@
 To disable highlighting, use the \f[C]\-\-no\-highlight\f[] option.
 .SH CUSTOM STYLES IN DOCX OUTPUT
 .PP
-By default, pandoc's docx output applies a predefined set of styles for
-blocks such as paragraphs and block quotes, and uses largely default
+By default, pandoc\[aq]s docx output applies a predefined set of styles
+for blocks such as paragraphs and block quotes, and uses largely default
 formatting (italics, bold) for inlines.
 This will work for most purposes, especially alongside a
 \f[C]reference.docx\f[] file.
@@ -5369,8 +5352,8 @@
 \f[]
 .fi
 .PP
-would produce a docx file with \[lq]Get out,\[rq] styled with character
-style \f[C]Emphatically\f[].
+would produce a docx file with "Get out," styled with character style
+\f[C]Emphatically\f[].
 Similarly,
 .IP
 .nf
diff --git a/man/removeLinks.hs b/man/removeLinks.hs
deleted file mode 100644
--- a/man/removeLinks.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-import Text.Pandoc.JSON
-
-main :: IO ()
-main = toJSONFilter removeLinks
-
-removeLinks :: Inline -> [Inline]
-removeLinks (Link _ l _) = l
-removeLinks x = [x]
-
diff --git a/man/removeNotes.hs b/man/removeNotes.hs
deleted file mode 100644
--- a/man/removeNotes.hs
+++ /dev/null
@@ -1,9 +0,0 @@
-import Text.Pandoc.JSON
-
-main :: IO ()
-main = toJSONFilter removeNotes
-
-removeNotes :: Inline -> Inline
-removeNotes (Note _) = Str ""
-removeNotes x = x
-
diff --git a/pandoc.cabal b/pandoc.cabal
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -1,5 +1,5 @@
 name:            pandoc
-version:         2.0.1.1
+version:         2.0.2
 cabal-version:   >= 1.10
 build-type:      Custom
 license:         GPL
@@ -126,9 +126,7 @@
                  -- stack build plan
                  stack.yaml
                  -- files needed to build man page
-                 man/capitalizeHeaders.hs
-                 man/removeNotes.hs
-                 man/removeLinks.hs
+                 man/manfilter.lua
                  man/pandoc.1.template
                  -- trypandoc
                  trypandoc/Makefile
@@ -314,7 +312,7 @@
                  xml >= 1.3.12 && < 1.4,
                  split >= 0.2 && < 0.3,
                  random >= 1 && < 1.2,
-                 pandoc-types >= 1.17.2 && < 1.18,
+                 pandoc-types >= 1.17.3 && < 1.18,
                  aeson >= 0.7 && < 1.3,
                  aeson-pretty >= 0.8 && < 0.9,
                  tagsoup >= 0.13.7 && < 0.15,
@@ -478,6 +476,7 @@
                    Text.Pandoc.Readers.Org.Parsing,
                    Text.Pandoc.Readers.Org.Shared,
                    Text.Pandoc.Lua.PandocModule,
+                   Text.Pandoc.Lua.Filter,
                    Text.Pandoc.Lua.StackInstances,
                    Text.Pandoc.Lua.Util,
                    Text.Pandoc.CSS,
@@ -550,7 +549,7 @@
      other-modules:  Prelude
   build-depends:  base >= 4.2 && < 5,
                   pandoc,
-                  pandoc-types >= 1.17.2 && < 1.18,
+                  pandoc-types >= 1.17.3 && < 1.18,
                   bytestring >= 0.9 && < 0.11,
                   text >= 0.11 && < 1.3,
                   directory >= 1 && < 1.4,
diff --git a/src/Text/Pandoc/App.hs b/src/Text/Pandoc/App.hs
--- a/src/Text/Pandoc/App.hs
+++ b/src/Text/Pandoc/App.hs
@@ -76,7 +76,7 @@
 import System.IO.Error (isDoesNotExistError)
 import Text.Pandoc
 import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
-import Text.Pandoc.Builder (setMeta)
+import Text.Pandoc.Builder (setMeta, deleteMeta)
 import Text.Pandoc.Highlighting (highlightingStyles)
 import Text.Pandoc.Lua (LuaException (..), runLuaFilter)
 import Text.Pandoc.PDF (makePDF)
@@ -494,7 +494,7 @@
               (   (if isJust (optExtractMedia opts)
                       then fillMediaBag
                       else return)
-              >=> return . flip (foldr addMetadata) metadata
+              >=> return . addMetadata metadata
               >=> applyLuaFilters datadir (optLuaFilters opts) format
               >=> maybe return extractMedia (optExtractMedia opts)
               >=> applyTransforms transforms
@@ -722,8 +722,11 @@
     , optStripComments          = False
     }
 
-addMetadata :: (String, String) -> Pandoc -> Pandoc
-addMetadata (k, v) (Pandoc meta bs) = Pandoc meta' bs
+addMetadata :: [(String, String)] -> Pandoc -> Pandoc
+addMetadata kvs pdc = foldr addMeta (removeMetaKeys kvs pdc) kvs
+
+addMeta :: (String, String) -> Pandoc -> Pandoc
+addMeta (k, v) (Pandoc meta bs) = Pandoc meta' bs
   where meta' = case lookupMeta k meta of
                       Nothing -> setMeta k v' meta
                       Just (MetaList xs) ->
@@ -731,6 +734,9 @@
                       Just x  -> setMeta k (MetaList [x, v']) meta
         v' = readMetaValue v
 
+removeMetaKeys :: [(String,String)] -> Pandoc -> Pandoc
+removeMetaKeys kvs pdc = foldr (deleteMeta . fst) pdc kvs
+
 readMetaValue :: String -> MetaValue
 readMetaValue s = case decode (UTF8.fromString s) of
                        Just (Yaml.String t) -> MetaString $ T.unpack t
@@ -1401,29 +1407,12 @@
                   (\opt -> return opt { optCiteMethod = Biblatex }))
                  "" -- "Use biblatex cite commands in LaTeX output"
 
-    , Option "m" ["latexmathml", "asciimathml"]
-                 (OptArg
-                  (\arg opt ->
-                      return opt { optHTMLMathMethod = LaTeXMathML arg })
-                  "URL")
-                 "" -- "Use LaTeXMathML script in html output"
-
     , Option "" ["mathml"]
                  (NoArg
                   (\opt ->
                       return opt { optHTMLMathMethod = MathML }))
                  "" -- "Use mathml for HTML math"
 
-    , Option "" ["mimetex"]
-                 (OptArg
-                  (\arg opt -> do
-                      let url' = case arg of
-                                      Just u  -> u ++ "?"
-                                      Nothing -> "/cgi-bin/mimetex.cgi?"
-                      return opt { optHTMLMathMethod = WebTeX url' })
-                  "URL")
-                 "" -- "Use mimetex for HTML math"
-
     , Option "" ["webtex"]
                  (OptArg
                   (\arg opt -> do
@@ -1432,12 +1421,6 @@
                   "URL")
                  "" -- "Use web service for HTML math"
 
-    , Option "" ["jsmath"]
-                 (OptArg
-                  (\arg opt -> return opt { optHTMLMathMethod = JsMath arg})
-                  "URL")
-                 "" -- "Use jsMath for HTML math"
-
     , Option "" ["mathjax"]
                  (OptArg
                   (\arg opt -> do
@@ -1446,6 +1429,7 @@
                       return opt { optHTMLMathMethod = MathJax url'})
                   "URL")
                  "" -- "Use MathJax for HTML math"
+
     , Option "" ["katex"]
                  (OptArg
                   (\arg opt ->
@@ -1455,9 +1439,38 @@
                   "URL")
                   "" -- Use KaTeX for HTML Math
 
+    , Option "m" ["latexmathml", "asciimathml"]
+                 (OptArg
+                  (\arg opt -> do
+                      deprecatedOption "--latexmathml"
+                      return opt { optHTMLMathMethod = LaTeXMathML arg })
+                  "URL")
+                 "" -- "Use LaTeXMathML script in html output"
+
+    , Option "" ["mimetex"]
+                 (OptArg
+                  (\arg opt -> do
+                      deprecatedOption "--mimetex"
+                      let url' = case arg of
+                                      Just u  -> u ++ "?"
+                                      Nothing -> "/cgi-bin/mimetex.cgi?"
+                      return opt { optHTMLMathMethod = WebTeX url' })
+                  "URL")
+                 "" -- "Use mimetex for HTML math"
+
+    , Option "" ["jsmath"]
+                 (OptArg
+                  (\arg opt -> do
+                      deprecatedOption "--jsmath"
+                      return opt { optHTMLMathMethod = JsMath arg})
+                  "URL")
+                 "" -- "Use jsMath for HTML math"
+
     , Option "" ["gladtex"]
                  (NoArg
-                  (\opt -> return opt { optHTMLMathMethod = GladTeX }))
+                  (\opt -> do
+                      deprecatedOption "--gladtex"
+                      return opt { optHTMLMathMethod = GladTeX }))
                  "" -- "Use gladtex for HTML math"
 
     , Option "" ["abbreviations"]
@@ -1655,3 +1668,10 @@
 
 baseWriterName :: String -> String
 baseWriterName = takeWhile (\c -> c /= '+' && c /= '-')
+
+deprecatedOption :: String -> IO ()
+deprecatedOption o =
+  runIO (report $ Deprecated o "") >>=
+    \r -> case r of
+       Right () -> return ()
+       Left e   -> E.throwIO e
diff --git a/src/Text/Pandoc/Lua.hs b/src/Text/Pandoc/Lua.hs
--- a/src/Text/Pandoc/Lua.hs
+++ b/src/Text/Pandoc/Lua.hs
@@ -33,25 +33,18 @@
 -}
 module Text.Pandoc.Lua (LuaException (..), pushPandocModule, runLuaFilter) where
 
-import Control.Monad (mplus, unless, when, (>=>))
+import Control.Monad (when, (>=>))
 import Control.Monad.Identity (Identity)
 import Control.Monad.Trans (MonadIO (..))
-import Data.Data (Data, DataType, dataTypeConstrs, dataTypeName, dataTypeOf,
-                  showConstr, toConstr, tyconUQname)
-import Data.Foldable (foldrM)
 import Data.IORef (IORef, newIORef, readIORef)
-import Data.Map (Map)
-import Data.Maybe (isJust)
-import Foreign.Lua (FromLuaStack (peek), Lua, LuaException (..), StackIndex,
+import Foreign.Lua (FromLuaStack (peek), Lua, LuaException (..),
                     Status (OK), ToLuaStack (push))
 import Text.Pandoc.Class (CommonState, PandocIO, getCommonState, getMediaBag,
                           setMediaBag)
 import Text.Pandoc.Definition
 import Text.Pandoc.Lua.PandocModule (pushMediaBagModule, pushPandocModule)
+import Text.Pandoc.Lua.Filter (LuaFilter, walkMWithLuaFilter)
 import Text.Pandoc.MediaBag (MediaBag)
-import Text.Pandoc.Walk (walkM)
-
-import qualified Data.Map as Map
 import qualified Foreign.Lua as Lua
 
 runLuaFilter :: Maybe FilePath -> FilePath -> String
@@ -109,142 +102,5 @@
 runAll :: [LuaFilter] -> Pandoc -> Lua Pandoc
 runAll = foldr ((>=>) . walkMWithLuaFilter) return
 
-walkMWithLuaFilter :: LuaFilter -> Pandoc -> Lua Pandoc
-walkMWithLuaFilter (LuaFilter fnMap) =
-  walkInlines >=> walkBlocks >=> walkMeta >=> walkPandoc
- where
-    walkInlines :: Pandoc -> Lua Pandoc
-    walkInlines =
-      if hasOneOf inlineFilterNames
-      then walkM (mconcatMapM (tryFilter fnMap :: Inline -> Lua [Inline]))
-      else return
-
-    walkBlocks :: Pandoc -> Lua Pandoc
-    walkBlocks =
-      if hasOneOf blockFilterNames
-      then walkM (mconcatMapM (tryFilter fnMap :: Block -> Lua [Block]))
-      else return
-
-    walkMeta :: Pandoc -> Lua Pandoc
-    walkMeta =
-      case Map.lookup "Meta" fnMap of
-        Just fn -> walkM (\(Pandoc meta blocks) -> do
-                             meta' <- runFilterFunction fn meta *> singleElement meta
-                             return $ Pandoc meta' blocks)
-        Nothing -> return
-
-    walkPandoc :: Pandoc -> Lua Pandoc
-    walkPandoc =
-      case foldl mplus Nothing (map (`Map.lookup` fnMap) pandocFilterNames) of
-        Just fn -> \x -> runFilterFunction fn x *> singleElement x
-        Nothing -> return
-
-    mconcatMapM f = fmap mconcat . mapM f
-    hasOneOf = any (\k -> isJust (Map.lookup k fnMap))
-
-constructorsFor :: DataType -> [String]
-constructorsFor x = map show (dataTypeConstrs x)
-
-inlineFilterNames :: [String]
-inlineFilterNames = "Inline" : constructorsFor (dataTypeOf (Str []))
-
-blockFilterNames :: [String]
-blockFilterNames = "Block" : constructorsFor (dataTypeOf (Para []))
-
-metaFilterName :: String
-metaFilterName = "Meta"
-
-pandocFilterNames :: [String]
-pandocFilterNames = ["Pandoc", "Doc"]
-
-type FunctionMap = Map String LuaFilterFunction
-newtype LuaFilter = LuaFilter FunctionMap
-newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
-
--- | Try running a filter for the given element
-tryFilter :: (Data a, FromLuaStack a, ToLuaStack a)
-          => FunctionMap -> a -> Lua [a]
-tryFilter fnMap x =
-  let filterFnName = showConstr (toConstr x)
-      catchAllName = tyconUQname $ dataTypeName (dataTypeOf x)
-  in
-  case Map.lookup filterFnName fnMap `mplus` Map.lookup catchAllName fnMap of
-    Just fn -> runFilterFunction fn x *> elementOrList x
-    Nothing -> return [x]
-
-instance FromLuaStack LuaFilter where
-  peek idx =
-    let constrs = metaFilterName : pandocFilterNames
-                  ++ blockFilterNames
-                  ++ inlineFilterNames
-        fn c acc = do
-          Lua.getfield idx c
-          filterFn <- Lua.tryLua (peek (-1))
-          Lua.pop 1
-          return $ case filterFn of
-            Left _  -> acc
-            Right f -> (c, f) : acc
-    in LuaFilter . Map.fromList <$> foldrM fn [] constrs
-
--- | Push a value to the stack via a lua filter function. The filter function is
--- called with given element as argument and is expected to return an element.
--- Alternatively, the function can return nothing or nil, in which case the
--- element is left unchanged.
-runFilterFunction :: ToLuaStack a => LuaFilterFunction -> a -> Lua ()
-runFilterFunction lf x = do
-  pushFilterFunction lf
-  push x
-  z <- Lua.pcall 1 1 Nothing
-  when (z /= OK) $ do
-    let addPrefix = ("Error while running filter function: " ++)
-    Lua.throwTopMessageAsError' addPrefix
-
-elementOrList :: FromLuaStack a => a -> Lua [a]
-elementOrList x = do
-  let topOfStack = Lua.StackIndex (-1)
-  elementUnchanged <- Lua.isnil topOfStack
-  if elementUnchanged
-    then [x] <$ Lua.pop 1
-    else do
-       mbres <- Lua.peekEither topOfStack
-       case mbres of
-         Right res -> [res] <$ Lua.pop 1
-         Left _    -> Lua.toList topOfStack <* Lua.pop 1
-
-singleElement :: FromLuaStack a => a -> Lua a
-singleElement x = do
-  elementUnchanged <- Lua.isnil (-1)
-  if elementUnchanged
-    then x <$ Lua.pop 1
-    else do
-    mbres <- Lua.peekEither (-1)
-    case mbres of
-      Right res -> res <$ Lua.pop 1
-      Left err  -> do
-        Lua.pop 1
-        Lua.throwLuaError $
-          "Error while trying to get a filter's return " ++
-          "value from lua stack.\n" ++ err
-
--- | Push the filter function to the top of the stack.
-pushFilterFunction :: LuaFilterFunction -> Lua ()
-pushFilterFunction lf =
-  -- The function is stored in a lua registry table, retrieve it from there.
-  Lua.rawgeti Lua.registryindex (functionIndex lf)
-
-registerFilterFunction :: StackIndex -> Lua LuaFilterFunction
-registerFilterFunction idx = do
-  isFn <- Lua.isfunction idx
-  unless isFn . Lua.throwLuaError $ "Not a function at index " ++ show idx
-  Lua.pushvalue idx
-  refIdx <- Lua.ref Lua.registryindex
-  return $ LuaFilterFunction refIdx
-
 instance (FromLuaStack a) => FromLuaStack (Identity a) where
   peek = fmap return . peek
-
-instance ToLuaStack LuaFilterFunction where
-  push = pushFilterFunction
-
-instance FromLuaStack LuaFilterFunction where
-  peek = registerFilterFunction
diff --git a/src/Text/Pandoc/Lua/Filter.hs b/src/Text/Pandoc/Lua/Filter.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/Pandoc/Lua/Filter.hs
@@ -0,0 +1,168 @@
+{-# LANGUAGE FlexibleContexts #-}
+
+module Text.Pandoc.Lua.Filter ( LuaFilterFunction
+                              , LuaFilter
+                              , tryFilter
+                              , runFilterFunction
+                              , walkMWithLuaFilter
+                              , walkInlines
+                              , walkBlocks
+                              , blockElementNames
+                              , inlineElementNames
+                              ) where
+import Control.Monad (mplus, unless, when, (>=>))
+import Text.Pandoc.Definition
+import Data.Foldable (foldrM)
+import Data.Map (Map)
+import qualified Data.Map as Map
+import qualified Foreign.Lua as Lua
+import Foreign.Lua (FromLuaStack (peek), Lua, StackIndex,
+                    Status (OK), ToLuaStack (push))
+import Text.Pandoc.Walk (walkM, Walkable)
+import Data.Data (Data, DataType, dataTypeConstrs, dataTypeName, dataTypeOf,
+                  showConstr, toConstr, tyconUQname)
+import Text.Pandoc.Lua.StackInstances()
+
+type FunctionMap = Map String LuaFilterFunction
+
+newtype LuaFilterFunction = LuaFilterFunction { functionIndex :: Int }
+
+instance ToLuaStack LuaFilterFunction where
+  push = pushFilterFunction
+
+instance FromLuaStack LuaFilterFunction where
+  peek = registerFilterFunction
+
+newtype LuaFilter = LuaFilter FunctionMap
+
+instance FromLuaStack LuaFilter where
+  peek idx =
+    let constrs = metaFilterName : pandocFilterNames
+                  ++ blockElementNames
+                  ++ inlineElementNames
+        fn c acc = do
+          Lua.getfield idx c
+          filterFn <- Lua.tryLua (peek (-1))
+          Lua.pop 1
+          return $ case filterFn of
+            Left _  -> acc
+            Right f -> (c, f) : acc
+    in LuaFilter . Map.fromList <$> foldrM fn [] constrs
+
+-- | Push the filter function to the top of the stack.
+pushFilterFunction :: LuaFilterFunction -> Lua ()
+pushFilterFunction lf =
+  -- The function is stored in a lua registry table, retrieve it from there.
+  Lua.rawgeti Lua.registryindex (functionIndex lf)
+
+registerFilterFunction :: StackIndex -> Lua LuaFilterFunction
+registerFilterFunction idx = do
+  isFn <- Lua.isfunction idx
+  unless isFn . Lua.throwLuaError $ "Not a function at index " ++ show idx
+  Lua.pushvalue idx
+  refIdx <- Lua.ref Lua.registryindex
+  return $ LuaFilterFunction refIdx
+
+elementOrList :: FromLuaStack a => a -> Lua [a]
+elementOrList x = do
+  let topOfStack = Lua.StackIndex (-1)
+  elementUnchanged <- Lua.isnil topOfStack
+  if elementUnchanged
+    then [x] <$ Lua.pop 1
+    else do
+       mbres <- Lua.peekEither topOfStack
+       case mbres of
+         Right res -> [res] <$ Lua.pop 1
+         Left _    -> Lua.toList topOfStack <* Lua.pop 1
+
+-- | Try running a filter for the given element
+tryFilter :: (Data a, FromLuaStack a, ToLuaStack a)
+          => LuaFilter -> a -> Lua [a]
+tryFilter (LuaFilter fnMap) x =
+  let filterFnName = showConstr (toConstr x)
+      catchAllName = tyconUQname $ dataTypeName (dataTypeOf x)
+  in
+  case Map.lookup filterFnName fnMap `mplus` Map.lookup catchAllName fnMap of
+    Just fn -> runFilterFunction fn x *> elementOrList x
+    Nothing -> return [x]
+
+-- | Push a value to the stack via a lua filter function. The filter function is
+-- called with given element as argument and is expected to return an element.
+-- Alternatively, the function can return nothing or nil, in which case the
+-- element is left unchanged.
+runFilterFunction :: ToLuaStack a => LuaFilterFunction -> a -> Lua ()
+runFilterFunction lf x = do
+  pushFilterFunction lf
+  push x
+  z <- Lua.pcall 1 1 Nothing
+  when (z /= OK) $ do
+    let addPrefix = ("Error while running filter function: " ++)
+    Lua.throwTopMessageAsError' addPrefix
+
+walkMWithLuaFilter :: LuaFilter -> Pandoc -> Lua Pandoc
+walkMWithLuaFilter f =
+  walkInlines f >=> walkBlocks f >=> walkMeta f >=> walkPandoc f
+
+mconcatMapM :: (Monad m, Functor m) => (a -> m [a]) -> [a] -> m [a]
+mconcatMapM f = fmap mconcat . mapM f
+
+hasOneOf :: LuaFilter -> [String] -> Bool
+hasOneOf (LuaFilter fnMap) = any (\k -> Map.member k fnMap)
+
+walkInlines :: Walkable [Inline] a => LuaFilter -> a -> Lua a
+walkInlines f =
+  if f `hasOneOf` inlineElementNames
+     then walkM (mconcatMapM (tryFilter f :: Inline -> Lua [Inline]))
+     else return
+
+walkBlocks :: Walkable [Block] a => LuaFilter -> a -> Lua a
+walkBlocks f =
+  if f `hasOneOf` blockElementNames
+     then walkM (mconcatMapM (tryFilter f :: Block -> Lua [Block]))
+     else return
+
+walkMeta :: LuaFilter -> Pandoc -> Lua Pandoc
+walkMeta (LuaFilter fnMap) =
+  case Map.lookup "Meta" fnMap of
+    Just fn -> walkM (\(Pandoc meta blocks) -> do
+                         meta' <- runFilterFunction fn meta *> singleElement meta
+                         return $ Pandoc meta' blocks)
+    Nothing -> return
+
+walkPandoc :: LuaFilter -> Pandoc -> Lua Pandoc
+walkPandoc (LuaFilter fnMap) =
+  case foldl mplus Nothing (map (`Map.lookup` fnMap) pandocFilterNames) of
+    Just fn -> \x -> runFilterFunction fn x *> singleElement x
+    Nothing -> return
+
+constructorsFor :: DataType -> [String]
+constructorsFor x = map show (dataTypeConstrs x)
+
+inlineElementNames :: [String]
+inlineElementNames = "Inline" : constructorsFor (dataTypeOf (Str []))
+
+blockElementNames :: [String]
+blockElementNames = "Block" : constructorsFor (dataTypeOf (Para []))
+
+metaFilterName :: String
+metaFilterName = "Meta"
+
+pandocFilterNames :: [String]
+pandocFilterNames = ["Pandoc", "Doc"]
+
+singleElement :: FromLuaStack a => a -> Lua a
+singleElement x = do
+  elementUnchanged <- Lua.isnil (-1)
+  if elementUnchanged
+    then x <$ Lua.pop 1
+    else do
+    mbres <- Lua.peekEither (-1)
+    case mbres of
+      Right res -> res <$ Lua.pop 1
+      Left err  -> do
+        Lua.pop 1
+        Lua.throwLuaError $
+          "Error while trying to get a filter's return " ++
+          "value from lua stack.\n" ++ err
+
+
diff --git a/src/Text/Pandoc/Lua/PandocModule.hs b/src/Text/Pandoc/Lua/PandocModule.hs
--- a/src/Text/Pandoc/Lua/PandocModule.hs
+++ b/src/Text/Pandoc/Lua/PandocModule.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE FlexibleContexts #-}
 {-
 Copyright © 2017 Albert Krewinkel <tarleb+pandoc@moltkeplatz.de>
 
@@ -38,13 +40,15 @@
 import Data.IORef
 import Data.Maybe (fromMaybe)
 import Data.Text (pack)
-import Foreign.Lua (FromLuaStack, Lua, NumResults, liftIO)
+import Foreign.Lua (ToLuaStack, FromLuaStack, Lua, NumResults, liftIO)
 import Foreign.Lua.FunctionCalling (ToHaskellFunction)
 import System.Exit (ExitCode (..))
 import Text.Pandoc.Class (CommonState (..), fetchItem, putCommonState,
                           readDataFile, runIO, runIOorExplode, setMediaBag,
                           setUserDataDir)
 import Text.Pandoc.Lua.StackInstances ()
+import Text.Pandoc.Definition (Block, Inline)
+import Text.Pandoc.Walk (Walkable)
 import Text.Pandoc.MIME (MimeType)
 import Text.Pandoc.Options (ReaderOptions (readerExtensions))
 import Text.Pandoc.Process (pipeProcess)
@@ -53,6 +57,7 @@
 import qualified Data.ByteString.Lazy as BL
 import qualified Foreign.Lua as Lua
 import qualified Text.Pandoc.MediaBag as MB
+import Text.Pandoc.Lua.Filter (walkInlines, walkBlocks, LuaFilter)
 
 -- | Push the "pandoc" on the lua stack.
 pushPandocModule :: Maybe FilePath -> Lua ()
@@ -63,11 +68,26 @@
   addFunction "_pipe" pipeFn
   addFunction "_read" readDoc
   addFunction "sha1" sha1HashFn
+  addFunction "walk_block" walkBlock
+  addFunction "walk_inline" walkInline
 
 -- | Get the string representation of the pandoc module
 pandocModuleScript :: Maybe FilePath -> IO String
 pandocModuleScript datadir = unpack <$>
   runIOorExplode (setUserDataDir datadir >> readDataFile "pandoc.lua")
+
+walkElement :: (ToLuaStack a, Walkable [Inline] a, Walkable [Block] a)
+            => a -> LuaFilter -> Lua NumResults
+walkElement x f = do
+  x' <- walkInlines f x >>= walkBlocks f
+  Lua.push x'
+  return 1
+
+walkInline :: Inline -> LuaFilter -> Lua NumResults
+walkInline = walkElement
+
+walkBlock :: Block -> LuaFilter -> Lua NumResults
+walkBlock = walkElement
 
 readDoc :: String -> String -> Lua NumResults
 readDoc formatSpec content = do
diff --git a/src/Text/Pandoc/Readers/HTML.hs b/src/Text/Pandoc/Readers/HTML.hs
--- a/src/Text/Pandoc/Readers/HTML.hs
+++ b/src/Text/Pandoc/Readers/HTML.hs
@@ -54,8 +54,7 @@
 import Data.List.Split (wordsBy)
 import qualified Data.Map as M
 import Data.Maybe (fromMaybe, isJust, isNothing)
-import Data.Monoid (First (..))
-import Data.Monoid ((<>))
+import Data.Monoid (First (..), (<>))
 import qualified Data.Set as Set
 import Data.Text (Text)
 import qualified Data.Text as T
@@ -89,7 +88,7 @@
              parseTagsOptions parseOptions{ optTagPosition = True }
              (crFilter inp)
       parseDoc = do
-        blocks <- (fixPlains False) . mconcat <$> manyTill block eof
+        blocks <- fixPlains False . mconcat <$> manyTill block eof
         meta <- stateMeta . parserState <$> getState
         bs' <- replaceNotes (B.toList blocks)
         reportLogMessages
@@ -223,10 +222,10 @@
 eCase :: PandocMonad m => TagParser m (Maybe Inlines)
 eCase = do
   skipMany pBlank
-  TagOpen _ attr' <- lookAhead $ pSatisfy $ (matchTagOpen "case" [])
+  TagOpen _ attr' <- lookAhead $ pSatisfy (matchTagOpen "case" [])
   let attr = toStringAttr attr'
-  case (flip lookup namespaces) =<< lookup "required-namespace" attr of
-    Just p -> Just <$> (pInTags "case" (skipMany pBlank *> p <* skipMany pBlank))
+  case flip lookup namespaces =<< lookup "required-namespace" attr of
+    Just p -> Just <$> pInTags "case" (skipMany pBlank *> p <* skipMany pBlank)
     Nothing -> Nothing <$ manyTill pAnyTag (pSatisfy (matchTagClose "case"))
 
 eFootnote :: PandocMonad m => TagParser m ()
@@ -235,20 +234,20 @@
   guardEnabled Ext_epub_html_exts
   (TagOpen tag attr') <- lookAhead pAnyTag
   let attr = toStringAttr attr'
-  guard (maybe False (flip elem notes) (lookup "type" attr))
+  guard $ maybe False (`elem` notes) (lookup "type" attr)
   let ident = fromMaybe "" (lookup "id" attr)
   content <- pInTags tag block
   addNote ident content
 
 addNote :: PandocMonad m => String -> Blocks -> TagParser m ()
-addNote uid cont = updateState (\s -> s {noteTable = (uid, cont) : (noteTable s)})
+addNote uid cont = updateState (\s -> s {noteTable = (uid, cont) : noteTable s})
 
 eNoteref :: PandocMonad m => TagParser m Inlines
 eNoteref = try $ do
   guardEnabled Ext_epub_html_exts
-  TagOpen tag attr' <- lookAhead $ pAnyTag
+  TagOpen tag attr' <- lookAhead pAnyTag
   let attr = toStringAttr attr'
-  guard (maybe False (== "noteref") (lookup "type" attr))
+  guard $ lookup "type" attr == Just "noteref"
   let ident = maybe "" (dropWhile (== '#')) (lookup "href" attr)
   guard (not (null ident))
   pInTags tag block
@@ -258,8 +257,8 @@
 eTOC :: PandocMonad m => TagParser m ()
 eTOC = try $ do
   guardEnabled Ext_epub_html_exts
-  (TagOpen tag attr) <- lookAhead $ pAnyTag
-  guard (maybe False (== "toc") (lookup "type" attr))
+  (TagOpen tag attr) <- lookAhead pAnyTag
+  guard $ lookup "type" attr == Just "toc"
   void (pInTags tag block)
 
 pList :: PandocMonad m => TagParser m Blocks
@@ -285,7 +284,7 @@
                            (Plain ils:xs) -> B.fromList (Plain
                                 [Span (ident, [], []) ils] : xs)
                            _ -> B.divWith (ident, [], []) bs
-  (maybe id addId (lookup "id" attr)) <$>
+  maybe id addId (lookup "id" attr) <$>
     pInTags "li" block <* skipMany nonItem
 
 parseListStyleType :: String -> ListNumberStyle
@@ -356,14 +355,14 @@
 fixPlains inList bs = if any isParaish bs'
                          then B.fromList $ map plainToPara bs'
                          else bs
-  where isParaish (Para _)           = True
-        isParaish (CodeBlock _ _)    = True
-        isParaish (Header _ _ _)     = True
-        isParaish (BlockQuote _)     = True
-        isParaish (BulletList _)     = not inList
-        isParaish (OrderedList _ _)  = not inList
-        isParaish (DefinitionList _) = not inList
-        isParaish _                  = False
+  where isParaish Para{}           = True
+        isParaish CodeBlock{}      = True
+        isParaish Header{}         = True
+        isParaish BlockQuote{}     = True
+        isParaish BulletList{}     = not inList
+        isParaish OrderedList{}    = not inList
+        isParaish DefinitionList{} = not inList
+        isParaish _                = False
         plainToPara (Plain xs) = Para xs
         plainToPara x          = x
         bs' = B.toList bs
@@ -427,10 +426,10 @@
   setInChapter (pInTags tag block)
 
 headerLevel :: PandocMonad m => Text -> TagParser m Int
-headerLevel tagtype = do
+headerLevel tagtype =
   case safeRead (T.unpack (T.drop 1 tagtype)) of
         Just level ->
-          (try $ do
+          try (do
             guardEnabled Ext_epub_html_exts
             asks inChapter >>= guard
             return (level - 1))
@@ -481,12 +480,12 @@
       pTBody = pOptInTag "tbody" $ many1 pTr
   head'' <- pOptInTag "thead" pTh
   head'  <- map snd <$>
-             (pOptInTag "tbody" $
-               if null head'' then pTh else return head'')
+             pOptInTag "tbody"
+               (if null head'' then pTh else return head'')
   rowsLs <- many pTBody
   rows'  <- pOptInTag "tfoot" $ many pTr
   TagClose _ <- pSatisfy (matchTagClose "table")
-  let rows'' = (concat rowsLs) <> rows'
+  let rows'' = concat rowsLs <> rows'
   let rows''' = map (map snd) rows''
   -- let rows''' = map (map snd) rows''
   -- fail on empty table
@@ -691,7 +690,7 @@
 pSubscript = pInlinesInTags "sub" B.subscript
 
 pStrikeout :: PandocMonad m => TagParser m Inlines
-pStrikeout = do
+pStrikeout =
   pInlinesInTags "s" B.strikeout <|>
     pInlinesInTags "strike" B.strikeout <|>
     pInlinesInTags "del" B.strikeout <|>
@@ -719,7 +718,7 @@
   tag <- pSatisfy $ tagOpenLit "a" (const True)
   let title = T.unpack $ fromAttrib "title" tag
   -- take id from id attribute if present, otherwise name
-  let uid = maybe (T.unpack $ fromAttrib "name" tag) id $
+  let uid = fromMaybe (T.unpack $ fromAttrib "name" tag) $
                maybeFromAttrib "id" tag
   let cls = words $ T.unpack $ fromAttrib "class" tag
   lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
@@ -750,7 +749,7 @@
   let getAtt k = case fromAttrib k tag of
                    "" -> []
                    v  -> [(T.unpack k, T.unpack v)]
-  let kvs = concat $ map getAtt ["width", "height", "sizes", "srcset"]
+  let kvs = concatMap getAtt ["width", "height", "sizes", "srcset"]
   return $ B.imageWith (uid, cls, kvs) (escapeURI url) title (B.text alt)
 
 pCode :: PandocMonad m => TagParser m Inlines
@@ -846,7 +845,7 @@
 pCloses tagtype = try $ do
   t <- lookAhead $ pSatisfy $ \tag -> isTagClose tag || isTagOpen tag
   case t of
-       (TagClose t') | t' == tagtype -> pAnyTag >> return ()
+       (TagClose t') | t' == tagtype -> void pAnyTag
        (TagOpen t' _) | t' `closes` tagtype -> return ()
        (TagClose "ul") | tagtype == "li" -> return ()
        (TagClose "ol") | tagtype == "li" -> return ()
@@ -1197,7 +1196,7 @@
 mkAttr :: [(String, String)] -> Attr
 mkAttr attr = (attribsId, attribsClasses, attribsKV)
   where attribsId = fromMaybe "" $ lookup "id" attr
-        attribsClasses = (words $ fromMaybe "" $ lookup "class" attr) <> epubTypes
+        attribsClasses = words (fromMaybe "" $ lookup "class" attr) <> epubTypes
         attribsKV = filter (\(k,_) -> k /= "class" && k /= "id") attr
         epubTypes = words $ fromMaybe "" $ lookup "epub:type" attr
 
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -290,8 +290,8 @@
 toMetaValue x =
   parseFromString' parser' (T.unpack x)
   where parser' = (asInlines <$> ((trimInlinesF . mconcat)
-                       <$> (guard (not endsWithNewline)
-                             *> manyTill inline eof)))
+                       <$> try (guard (not endsWithNewline)
+                                *> manyTill inline eof)))
                   <|> (asBlocks <$> parseBlocks)
         asBlocks p = do
           p' <- p
@@ -623,8 +623,9 @@
 blockDelimiter :: PandocMonad m
                => (Char -> Bool)
                -> Maybe Int
-               -> ParserT [Char] st m Int
+               -> ParserT [Char] ParserState m Int
 blockDelimiter f len = try $ do
+  skipNonindentSpaces
   c <- lookAhead (satisfy f)
   case len of
       Just l  -> count l (char c) >> many (char c) >> return l
@@ -689,6 +690,8 @@
 
 codeBlockFenced :: PandocMonad m => MarkdownParser m (F Blocks)
 codeBlockFenced = try $ do
+  indentchars <- nonindentSpaces
+  let indentLevel = length indentchars
   c <- try (guardEnabled Ext_fenced_code_blocks >> lookAhead (char '~'))
      <|> (guardEnabled Ext_backtick_code_blocks >> lookAhead (char '`'))
   size <- blockDelimiter (== c) Nothing
@@ -701,7 +704,8 @@
           <|> ((\x -> ("",[toLanguageId x],[])) <$> many1 nonspaceChar)))
   blankline
   contents <- intercalate "\n" <$>
-                 manyTill anyLine (blockDelimiter (== c) (Just size))
+                 manyTill (gobbleAtMostSpaces indentLevel >> anyLine)
+                          (blockDelimiter (== c) (Just size))
   blanklines
   return $ return $
     case rawattr of
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -44,7 +44,7 @@
 import qualified Data.Foldable as F
 import Data.List (intercalate, intersperse, isPrefixOf)
 import qualified Data.Map as M
-import Data.Maybe (fromMaybe)
+import Data.Maybe (fromMaybe, maybeToList)
 import Data.Monoid ((<>))
 import Data.Sequence (ViewL (..), viewl, (<|))
 import qualified Data.Set as Set
@@ -239,7 +239,7 @@
                          Nothing -> 1.0
   caption <- option mempty tableCaption
   optional rowsep
-  hasheader <- option False $ True <$ (lookAhead (skipSpaces *> char '!'))
+  hasheader <- option False $ True <$ lookAhead (skipSpaces *> char '!')
   (cellspecs',hdr) <- unzip <$> tableRow
   let widths = map ((tableWidth *) . snd) cellspecs'
   let restwidth = tableWidth - sum widths
@@ -358,7 +358,7 @@
   let mblang = lookup "lang" attrs
   let mbstart = lookup "start" attrs
   let mbline = lookup "line" attrs
-  let classes = maybe [] (:[]) mblang ++ maybe [] (const ["numberLines"]) mbline
+  let classes = maybeToList mblang ++ maybe [] (const ["numberLines"]) mbline
   let kvs = maybe [] (\x -> [("startFrom",x)]) mbstart
   contents <- charsInTags tag
   return $ B.codeBlockWith ("",classes,kvs) $ trimCode contents
@@ -373,7 +373,7 @@
 preformatted = try $ do
   guardColumnOne
   char ' '
-  let endline' = B.linebreak <$ (try $ newline <* char ' ')
+  let endline' = B.linebreak <$ try (newline <* char ' ')
   let whitespace' = B.str <$> many1 ('\160' <$ spaceChar)
   let spToNbsp ' ' = '\160'
       spToNbsp x   = x
@@ -382,7 +382,7 @@
                   (htmlTag (~== TagOpen "nowiki" []) *>
                    manyTill anyChar (htmlTag (~== TagClose "nowiki")))
   let inline' = whitespace' <|> endline' <|> nowiki'
-                  <|> (try $ notFollowedBy newline *> inline)
+                  <|> try (notFollowedBy newline *> inline)
   contents <- mconcat <$> many1 inline'
   let spacesStr (Str xs) = all isSpace xs
       spacesStr _        = False
@@ -397,7 +397,7 @@
         strToCode  x      = x
         normalizeCode []  = []
         normalizeCode (Code a1 x : Code a2 y : zs) | a1 == a2 =
-          normalizeCode $ (Code a1 (x ++ y)) : zs
+          normalizeCode $ Code a1 (x ++ y) : zs
         normalizeCode (x:xs) = x : normalizeCode xs
 
 header :: PandocMonad m => MWParser m Blocks
@@ -510,8 +510,8 @@
 firstParaToPlain :: Blocks -> Blocks
 firstParaToPlain contents =
   case viewl (B.unMany contents) of
-       (Para xs) :< ys -> B.Many $ (Plain xs) <| ys
-       _               -> contents
+       Para xs :< ys -> B.Many $ Plain xs <| ys
+       _             -> contents
 
 --
 -- inline parsers
@@ -612,13 +612,13 @@
   choice imageIdentifiers
   fname <- addUnderscores <$> many1 (noneOf "|]")
   _ <- many imageOption
-  dims <- try (char '|' *> (sepBy (many digit) (char 'x')) <* string "px")
+  dims <- try (char '|' *> sepBy (many digit) (char 'x') <* string "px")
           <|> return []
   _ <- many imageOption
   let kvs = case dims of
-              w:[]     -> [("width", w)]
-              w:(h:[]) -> [("width", w), ("height", h)]
-              _        -> []
+              [w]    -> [("width", w)]
+              [w, h] -> [("width", w), ("height", h)]
+              _      -> []
   let attr = ("", [], kvs)
   caption <-   (B.str fname <$ sym "]]")
            <|> try (char '|' *> (mconcat <$> manyTill inline (sym "]]")))
@@ -651,7 +651,7 @@
              (  (mconcat <$> many1 (notFollowedBy (char ']') *> inline))
              -- the "pipe trick"
              -- [[Help:Contents|] -> "Contents"
-             <|> (return $ B.text $ drop 1 $ dropWhile (/=':') pagename) )
+             <|> return (B.text $ drop 1 $ dropWhile (/=':') pagename) )
   sym "]]"
   linktrail <- B.text <$> many letter
   let link = B.link (addUnderscores pagename) "wikilink" (label <> linktrail)
diff --git a/src/Text/Pandoc/Readers/Odt/ContentReader.hs b/src/Text/Pandoc/Readers/Odt/ContentReader.hs
--- a/src/Text/Pandoc/Readers/Odt/ContentReader.hs
+++ b/src/Text/Pandoc/Readers/Odt/ContentReader.hs
@@ -247,7 +247,7 @@
       modifyExtraState (putPrettyAnchor uglyAnchor newPretty) -<< newPretty
 
 -- | Input: basis for a new header anchor
--- Ouput: saved new anchor
+-- Output: saved new anchor
 getHeaderAnchor :: OdtReaderSafe Inlines Anchor
 getHeaderAnchor = proc title -> do
   state <- getExtraState -< ()
@@ -566,7 +566,7 @@
 
 
 -- specifically. I honor that, although the current implementation of '(<>)'
--- for 'Inlines' in "Text.Pandoc.Builder" will collaps them agein.
+-- for 'Inlines' in "Text.Pandoc.Builder" will collapse them again.
 -- The rational is to be prepared for future modifications.
 read_spaces      :: InlineMatcher
 read_spaces       = matchingElement NsText "s" (
diff --git a/src/Text/Pandoc/Readers/Odt/StyleReader.hs b/src/Text/Pandoc/Readers/Odt/StyleReader.hs
--- a/src/Text/Pandoc/Readers/Odt/StyleReader.hs
+++ b/src/Text/Pandoc/Readers/Odt/StyleReader.hs
@@ -104,7 +104,7 @@
 instance Default FontPitch where
   def = PitchVariable
 
--- The font pitch can be specifed in a style directly. Normally, however,
+-- The font pitch can be specified in a style directly. Normally, however,
 -- it is defined in the font. That is also the specs' recommendation.
 --
 -- Thus, we want
@@ -340,8 +340,8 @@
   readsPrec _ "em" = [(XslUnitEM     , "")]
   readsPrec _  _   = []
 
--- | Rough conversion of measures into millimeters.
--- Pixels and em's are actually implemetation dependant/relative measures,
+-- | Rough conversion of measures into millimetres.
+-- Pixels and em's are actually implementation dependant/relative measures,
 -- so I could not really easily calculate anything exact here even if I wanted.
 -- But I do not care about exactness right now, as I only use measures
 -- to determine if a paragraph is "indented" or not.
@@ -425,7 +425,7 @@
 --------------------------------------------------------------------------------
 -- Readers
 --
--- ...it seems like a whole lot of this should be automatically deriveable
+-- ...it seems like a whole lot of this should be automatically derivable
 --    or at least moveable into a class. Most of this is data concealed in
 --    code.
 --------------------------------------------------------------------------------
diff --git a/src/Text/Pandoc/Readers/Txt2Tags.hs b/src/Text/Pandoc/Readers/Txt2Tags.hs
--- a/src/Text/Pandoc/Readers/Txt2Tags.hs
+++ b/src/Text/Pandoc/Readers/Txt2Tags.hs
@@ -1,4 +1,3 @@
-{-# LANGUAGE ViewPatterns #-}
 {-
 Copyright (C) 2014 Matthew Pickering <matthewtpickering@gmail.com>
 
@@ -94,7 +93,7 @@
         readWithM parseT2T (def {stateOptions = opts}) $
         T.unpack (crFilter s) ++ "\n\n"
   case parsed of
-    Right result -> return $ result
+    Right result -> return result
     Left e       -> throwError e
 
 -- | Read Txt2Tags (ignoring all macros) from an input string returning
@@ -149,7 +148,7 @@
   string "%!"
   keyword <- ignoreSpacesCap (many1 alphaNum)
   char ':'
-  value <- ignoreSpacesCap (manyTill anyChar (newline))
+  value <- ignoreSpacesCap (manyTill anyChar newline)
   return (keyword, value)
 
 -- Blocks
@@ -158,7 +157,7 @@
 parseBlocks = mconcat <$> manyTill block eof
 
 block :: T2T Blocks
-block = do
+block =
   choice
     [ mempty <$ blanklines
     , quote
@@ -196,7 +195,7 @@
     listStart = try bulletListStart <|> orderedListStart
 
 commentBlock :: T2T Blocks
-commentBlock = try (blockMarkupArea (anyLine) (const mempty) "%%%") <|> comment
+commentBlock = try (blockMarkupArea anyLine (const mempty) "%%%") <|> comment
 
 -- Seperator and Strong line treated the same
 hrule :: T2T Blocks
@@ -230,7 +229,7 @@
               <$> many1 (listItem orderedListStart parseBlocks)
 
 definitionList :: T2T Blocks
-definitionList = try $ do
+definitionList = try $
   B.definitionList . compactifyDL <$>
     many1 (listItem definitionListStart definitionListEnd)
 
@@ -282,17 +281,17 @@
   rows <- many1 (many commentLine *> tableRow)
   let columns = transpose rows
   let ncolumns = length columns
-  let aligns = map (foldr1 findAlign) (map (map fst) columns)
+  let aligns = map (foldr1 findAlign . map fst) columns
   let rows' = map (map snd) rows
   let size = maximum (map length rows')
   let rowsPadded = map (pad size) rows'
-  let headerPadded = if (not (null tableHeader)) then pad size tableHeader else mempty
+  let headerPadded = if null tableHeader then mempty else pad size tableHeader
   return $ B.table mempty
                     (zip aligns (replicate ncolumns 0.0))
                       headerPadded rowsPadded
 
 pad :: (Monoid a) => Int -> [a] -> [a]
-pad n xs = xs ++ (replicate (n - length xs) mempty)
+pad n xs = xs ++ replicate (n - length xs) mempty
 
 
 findAlign :: Alignment -> Alignment -> Alignment
@@ -315,7 +314,7 @@
 tableCell :: T2T (Alignment, Blocks)
 tableCell = try $ do
   leftSpaces <- length <$> lookAhead (many1 space) -- Case of empty cell means we must lookAhead
-  content <- (manyTill inline (try $ lookAhead (cellEnd)))
+  content <- manyTill inline (try $ lookAhead cellEnd)
   rightSpaces <- length <$> many space
   let align =
         case compare leftSpaces rightSpaces of
@@ -323,9 +322,9 @@
               EQ -> AlignCenter
               GT -> AlignRight
   endOfCell
-  return $ (align, B.plain (B.trimInlines $ mconcat content))
+  return (align, B.plain (B.trimInlines $ mconcat content))
   where
-    cellEnd = (void newline <|> (many1 space *> endOfCell))
+    cellEnd = void newline <|> (many1 space *> endOfCell)
 
 endOfCell :: T2T ()
 endOfCell = try (skipMany1 $ char '|') <|> ( () <$ lookAhead newline)
@@ -348,10 +347,10 @@
 genericBlock :: Monoid a => T2T a -> (a -> Blocks) -> String -> T2T Blocks
 genericBlock p f s = blockMarkupArea p f s <|> blockMarkupLine p f s
 
-blockMarkupArea :: Monoid a => (T2T a) -> (a -> Blocks) -> String -> T2T Blocks
-blockMarkupArea p f s = try $ (do
+blockMarkupArea :: Monoid a => T2T a -> (a -> Blocks) -> String -> T2T Blocks
+blockMarkupArea p f s = try (do
   string s *> blankline
-  f . mconcat <$> (manyTill p (eof <|> void (string s *> blankline))))
+  f . mconcat <$> manyTill p (eof <|> void (string s *> blankline)))
 
 blockMarkupLine :: T2T a -> (a -> Blocks) -> String -> T2T Blocks
 blockMarkupLine p f s = try (f <$> (string s *> space *> p))
@@ -369,7 +368,7 @@
 parseInlines = trimInlines . mconcat <$> many1 inline
 
 inline :: T2T Inlines
-inline = do
+inline =
   choice
     [ endline
     , macro
@@ -391,16 +390,16 @@
     ]
 
 bold :: T2T Inlines
-bold = inlineMarkup inline B.strong '*' (B.str)
+bold = inlineMarkup inline B.strong '*' B.str
 
 underline :: T2T Inlines
-underline = inlineMarkup inline underlineSpan '_' (B.str)
+underline = inlineMarkup inline underlineSpan '_' B.str
 
 strike :: T2T Inlines
-strike = inlineMarkup inline B.strikeout '-' (B.str)
+strike = inlineMarkup inline B.strikeout '-' B.str
 
 italic :: T2T Inlines
-italic = inlineMarkup inline B.emph '/' (B.str)
+italic = inlineMarkup inline B.emph '/' B.str
 
 code :: T2T Inlines
 code = inlineMarkup ((:[]) <$> anyChar) B.code '`' id
@@ -419,7 +418,7 @@
 -- Glued meaning that markup must be tight to content
 -- Markup can't pass newlines
 inlineMarkup :: Monoid a
-             => (T2T a) -- Content parser
+             => T2T a -- Content parser
              -> (a -> Inlines) -- Constructor
              -> Char -- Fence
              -> (String -> a) -- Special Case to handle ******
@@ -431,7 +430,7 @@
   when (l == 2) (void $ notFollowedBy space)
   -- We must make sure that there is no space before the start of the
   -- closing tags
-  body <-  optionMaybe (try $ manyTill (noneOf "\n\r") $
+  body <-  optionMaybe (try $ manyTill (noneOf "\n\r")
                 (try $ lookAhead (noneOf " " >> string [c,c] )))
   case body of
     Just middle -> do
@@ -448,7 +447,7 @@
       return $ f (start' <> body' <> end')
     Nothing -> do -- Either bad or case such as *****
       guard (l >= 5)
-      let body' = (replicate (l - 4) c)
+      let body' = replicate (l - 4) c
       return $ f (special body')
 
 link :: T2T Inlines
@@ -463,7 +462,7 @@
   guard (length tokens >= 2)
   char ']'
   let link' = last tokens
-  guard (length link' > 0)
+  guard $ not $ null link'
   let tit = concat (intersperse " " (init tokens))
   return $ B.link link' "" (B.text tit)
 
@@ -489,7 +488,7 @@
 -- raw URLs in text are automatically linked
 url :: T2T Inlines
 url = try $ do
-  (rawUrl, escapedUrl) <- (try uri <|> emailAddress)
+  (rawUrl, escapedUrl) <- try uri <|> emailAddress
   return $ B.link rawUrl "" (B.str escapedUrl)
 
 uri :: T2T (String, String)
@@ -563,8 +562,7 @@
   return B.softbreak
 
 str :: T2T Inlines
-str = try $ do
-  B.str <$> many1 (noneOf $ specialChars ++ "\n\r ")
+str = try $ B.str <$> many1 (noneOf $ specialChars ++ "\n\r ")
 
 whitespace :: T2T Inlines
 whitespace = try $ B.space <$ spaceChar
diff --git a/src/Text/Pandoc/Readers/Vimwiki.hs b/src/Text/Pandoc/Readers/Vimwiki.hs
--- a/src/Text/Pandoc/Readers/Vimwiki.hs
+++ b/src/Text/Pandoc/Readers/Vimwiki.hs
@@ -244,7 +244,7 @@
   lookAhead newline
   contents <- manyTill anyChar (try (char '\n' >> many spaceChar >> string "}}}"
     >> many spaceChar >> newline))
-  if not (contents == "") && (head contents == '\n')
+  if (contents /= "") && (head contents == '\n')
      then return $ B.codeBlockWith (makeAttr attrText) (tail contents)
      else return $ B.codeBlockWith (makeAttr attrText) contents
 
@@ -310,10 +310,10 @@
           curLine <- listItemContent
           let listBuilder =
                 if builder == "ul" then B.bulletList else B.orderedList
-          (subList, lowInd) <- (mixedList' curInd)
+          (subList, lowInd) <- mixedList' curInd
           if lowInd >= curInd
              then do
-                  (sameIndList, endInd) <- (mixedList' lowInd)
+                  (sameIndList, endInd) <- mixedList' lowInd
                   let curList = combineList curLine subList ++ sameIndList
                   if curInd > prevInd
                      then return ([listBuilder curList], endInd)
@@ -388,7 +388,7 @@
 
 orderedListMarkers :: PandocMonad m => VwParser m String
 orderedListMarkers =
-  ("ol" <$choice ((orderedListMarker Decimal Period):(($OneParen)
+  ("ol" <$choice (orderedListMarker Decimal Period:(($OneParen)
     <$> orderedListMarker
     <$> [Decimal, LowerRoman, UpperRoman, LowerAlpha, UpperAlpha])))
     <|> ("ol" <$ char '#')
@@ -435,7 +435,7 @@
 
 tableCell :: PandocMonad m => VwParser m Blocks
 tableCell = try $
-  B.plain . trimInlines . mconcat <$> (manyTill inline' (char '|'))
+  B.plain . trimInlines . mconcat <$> manyTill inline' (char '|')
 
 placeholder :: PandocMonad m => VwParser m ()
 placeholder = try $
@@ -444,7 +444,7 @@
 ph :: PandocMonad m => String -> VwParser m ()
 ph s = try $ do
   many spaceChar >>string ('%':s) >> spaceChar
-  contents <- trimInlines . mconcat <$> (manyTill inline (lookAhead newline))
+  contents <- trimInlines . mconcat <$> manyTill inline (lookAhead newline)
     --use lookAhead because of placeholder in the whitespace parser
   let meta' = return $ B.setMeta s contents nullMeta :: F Meta
   updateState $ \st -> st { stateMeta' = stateMeta' st <> meta' }
@@ -515,12 +515,12 @@
 strong :: PandocMonad m => VwParser m Inlines
 strong = try $ do
   s <- lookAhead $ between (char '*') (char '*') (many1 $ noneOf "*")
-  guard $ not ((head s) `elem` spaceChars)
-             &&not ((last s) `elem` spaceChars)
+  guard $ (head s `notElem` spaceChars)
+             && (last s `notElem` spaceChars)
   char '*'
   contents <- mconcat <$>manyTill inline' (char '*'
     >> notFollowedBy alphaNum)
-  return $ B.spanWith ((makeId contents), [], []) mempty
+  return $ B.spanWith (makeId contents, [], []) mempty
     <> B.strong contents
 
 makeId :: Inlines -> String
@@ -529,8 +529,8 @@
 emph :: PandocMonad m => VwParser m Inlines
 emph = try $ do
   s <- lookAhead $ between (char '_') (char '_') (many1 $ noneOf "_")
-  guard $ not ((head s) `elem` spaceChars)
-          &&not ((last s) `elem` spaceChars)
+  guard $ (head s `notElem` spaceChars)
+          && (last s `notElem` spaceChars)
   char '_'
   contents <- mconcat <$>manyTill inline' (char '_'
     >> notFollowedBy alphaNum)
@@ -539,7 +539,7 @@
 strikeout :: PandocMonad m => VwParser m Inlines
 strikeout = try $ do
   string "~~"
-  contents <- mconcat <$>many1Till inline' (string $ "~~")
+  contents <- mconcat <$>many1Till inline' (string "~~")
   return $ B.strikeout contents
 
 code :: PandocMonad m => VwParser m Inlines
@@ -568,7 +568,7 @@
                     return $ B.link (procLink contents) "" (B.str contents)
                   True  -> do
                     url <- manyTill anyChar $ char '|'
-                    lab <- mconcat <$> (manyTill inline $ string "]]")
+                    lab <- mconcat <$> manyTill inline (string "]]")
                     return $ B.link (procLink url) "" lab
 
 image :: PandocMonad m => VwParser m Inlines
@@ -584,7 +584,7 @@
            return $ B.image (procImgurl imgurl) "" (B.str "")
   | k == 1 = do
            imgurl <- manyTill anyChar (char '|')
-           alt <- mconcat <$> (manyTill inline (try $ string "}}"))
+           alt <- mconcat <$> manyTill inline (try $ string "}}")
            return $ B.image (procImgurl imgurl) "" alt
   | k == 2 = do
            imgurl <- manyTill anyChar (char '|')
@@ -600,8 +600,8 @@
 
 procLink' :: String -> String
 procLink' s
-  | (take 6 s) == "local:" = "file" ++ drop 5 s
-  | (take 6 s) == "diary:" = "diary/" ++ drop 6 s ++ ".html"
+  | take 6 s == "local:" = "file" ++ drop 5 s
+  | take 6 s == "diary:" = "diary/" ++ drop 6 s ++ ".html"
   | or ((`isPrefixOf` s) <$> [ "http:", "https:", "ftp:", "file:", "mailto:",
                               "news:", "telnet:" ])
                              = s
@@ -614,7 +614,7 @@
   where (x, y) = break (=='#') s
 
 procImgurl :: String -> String
-procImgurl s = if (take 6 s) == "local:" then "file" ++ drop 5 s else s
+procImgurl s = if take 6 s == "local:" then "file" ++ drop 5 s else s
 
 inlineMath :: PandocMonad m => VwParser m Inlines
 inlineMath = try $ do
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -48,7 +48,7 @@
 import qualified Data.Text as TS
 import qualified Data.Text.Lazy as TL
 import Network.HTTP (urlEncode)
-import System.FilePath (takeExtension, takeFileName)
+import System.FilePath (takeExtension, takeFileName, makeRelative)
 import Text.HTML.TagSoup (Tag (TagOpen), fromAttrib, parseTags)
 import Text.Pandoc.Builder (fromList, setMeta)
 import Text.Pandoc.Class (PandocMonad, report)
@@ -81,6 +81,7 @@
 
 data EPUBState = EPUBState {
         stMediaPaths  :: [(FilePath, (FilePath, Maybe Entry))]
+      , stEpubSubdir  :: String
       }
 
 type E m = StateT EPUBState m
@@ -149,6 +150,20 @@
 removeNote (Note _) = Str ""
 removeNote x        = x
 
+mkEntry :: PandocMonad m => FilePath -> B.ByteString -> E m Entry
+mkEntry path content = do
+  epubSubdir <- gets stEpubSubdir
+  let addEpubSubdir :: Entry -> Entry
+      addEpubSubdir e = e{ eRelativePath =
+          (if null epubSubdir
+              then ""
+              else epubSubdir ++ "/") ++ eRelativePath e }
+  epochtime <- floor <$> lift P.getPOSIXTime
+  return $
+       (if path == "mimetype" || "META-INF" `isPrefixOf` path
+           then id
+           else addEpubSubdir) $ toEntry path epochtime content
+
 getEPUBMetadata :: PandocMonad m => WriterOptions -> Meta -> E m EPUBMetadata
 getEPUBMetadata opts meta = do
   let md = metadataFromMeta opts meta
@@ -366,11 +381,13 @@
           -> WriterOptions  -- ^ Writer options
           -> Pandoc         -- ^ Document to convert
           -> m B.ByteString
-writeEPUB epubVersion opts doc =
-  let initState = EPUBState { stMediaPaths = [] }
-  in
-    evalStateT (pandocToEPUB epubVersion opts doc)
-      initState
+writeEPUB epubVersion opts doc = do
+  let epubSubdir = writerEpubSubdirectory opts
+  -- sanity check on epubSubdir
+  unless (all (\c -> isAscii c && isAlphaNum c) epubSubdir) $
+    throwError $ PandocEpubSubdirectoryError epubSubdir
+  let initState = EPUBState { stMediaPaths = [], stEpubSubdir = epubSubdir }
+  evalStateT (pandocToEPUB epubVersion opts doc) initState
 
 pandocToEPUB :: PandocMonad m
              => EPUBVersion
@@ -378,27 +395,18 @@
              -> Pandoc
              -> E m B.ByteString
 pandocToEPUB version opts doc@(Pandoc meta _) = do
-  let epubSubdir = writerEpubSubdirectory opts
-  -- sanity check on epubSubdir
-  unless (all (\c -> isAscii c && isAlphaNum c) epubSubdir) $
-    throwError $ PandocEpubSubdirectoryError epubSubdir
-  let inSubdir f = if null epubSubdir
-                      then f
-                      else epubSubdir ++ "/" ++ f
-
+  epubSubdir <- gets stEpubSubdir
   let epub3 = version == EPUB3
   let writeHtml o = fmap (UTF8.fromTextLazy . TL.fromStrict) .
                       writeHtmlStringForEPUB version o
-  epochtime <- floor <$> lift P.getPOSIXTime
   metadata <- getEPUBMetadata opts meta
-  let mkEntry path content = toEntry path epochtime content
 
   -- stylesheet
   stylesheets <- case epubStylesheets metadata of
                       [] -> (\x -> [B.fromChunks [x]]) <$>
                              P.readDataFile "epub.css"
                       fs -> mapM P.readFileLazy fs
-  let stylesheetEntries = zipWith
+  stylesheetEntries <- zipWithM
         (\bs n -> mkEntry ("styles/stylesheet" ++ show n ++ ".css") bs)
         stylesheets [(1 :: Int)..]
 
@@ -406,10 +414,10 @@
              : [(x,y) | (x,y) <- writerVariables opts, x /= "css"]
 
   let cssvars useprefix = map (\e -> ("css",
-                               (if useprefix && not (null epubSubdir)
+                               (if useprefix
                                    then "../"
                                    else "")
-                               ++ eRelativePath e))
+                               ++ makeRelative epubSubdir (eRelativePath e)))
                           stylesheetEntries
 
   let opts' = opts{ writerEmailObfuscation = NoObfuscation
@@ -430,18 +438,21 @@
                        cpContent <- lift $ writeHtml
                             opts'{ writerVariables =
                                     ("coverpage","true"):
-                                     cssvars False ++ vars }
-                            (Pandoc meta [RawBlock (Format "html") $ "<div id=\"cover-image\">\n<img src=\"" ++ coverImage ++ "\" alt=\"cover image\" />\n</div>"])
+                                     cssvars True ++ vars }
+                            (Pandoc meta [RawBlock (Format "html") $ "<div id=\"cover-image\">\n<img src=\"../media/" ++ coverImage ++ "\" alt=\"cover image\" />\n</div>"])
                        imgContent <- lift $ P.readFileLazy img
-                       return ( [mkEntry "cover.xhtml" cpContent]
-                              , [mkEntry coverImage imgContent] )
+                       coverEntry <- mkEntry "text/cover.xhtml" cpContent
+                       coverImageEntry <- mkEntry ("media/" ++ coverImage)
+                                             imgContent
+                       return ( [ coverEntry ]
+                              , [ coverImageEntry ] )
 
   -- title page
   tpContent <- lift $ writeHtml opts'{
                                   writerVariables = ("titlepage","true"):
                                   cssvars True ++ vars }
                                (Pandoc meta [])
-  let tpEntry = mkEntry (inSubdir "title_page.xhtml") tpContent
+  tpEntry <- mkEntry "text/title_page.xhtml" tpContent
 
   -- handle pictures
   -- mediaRef <- P.newIORef []
@@ -454,7 +465,7 @@
         when (null xs) $
           report $ CouldNotFetchResource f "glob did not match any font files"
         return xs
-  let mkFontEntry f = mkEntry ("fonts/" ++ takeFileName f) <$>
+  let mkFontEntry f = mkEntry ("fonts/" ++ takeFileName f) =<<
                         lift (P.readFileLazy f)
   fontFiles <- concat <$> mapM matchingGlob (writerEpubFonts opts')
   fontEntries <- mapM mkFontEntry fontFiles
@@ -540,7 +551,7 @@
                  chapters'
 
   let chapToEntry num (Chapter mbnum bs) =
-       mkEntry (inSubdir (showChapter num)) <$>
+        mkEntry ("text/" ++ showChapter num) =<<
         writeHtml opts'{ writerNumberOffset = fromMaybe [] mbnum
                        , writerVariables = cssvars True ++ vars }
                  (case bs of
@@ -550,7 +561,7 @@
                                  nullMeta) bs
                      _                   -> Pandoc nullMeta bs)
 
-  chapterEntries <- lift $ zipWithM chapToEntry [1..] chapters
+  chapterEntries <- zipWithM chapToEntry [1..] chapters
 
   -- incredibly inefficient (TODO):
   let containsMathML ent = epub3 &&
@@ -563,24 +574,34 @@
 
   -- contents.opf
   let chapterNode ent = unode "item" !
-                           ([("id", toId $ eRelativePath ent),
-                             ("href", eRelativePath ent),
+                           ([("id", toId $ makeRelative epubSubdir
+                                         $ eRelativePath ent),
+                             ("href", makeRelative epubSubdir
+                                      $ eRelativePath ent),
                              ("media-type", "application/xhtml+xml")]
                             ++ case props ent of
                                     [] -> []
                                     xs -> [("properties", unwords xs)])
                         $ ()
+
   let chapterRefNode ent = unode "itemref" !
-                             [("idref", toId $ eRelativePath ent)] $ ()
+                             [("idref", toId $ makeRelative epubSubdir
+                                             $ eRelativePath ent)] $ ()
   let pictureNode ent = unode "item" !
-                           [("id", toId $ eRelativePath ent),
-                            ("href", eRelativePath ent),
-                            ("media-type", fromMaybe "application/octet-stream"
+                           [("id", toId $ makeRelative epubSubdir
+                                        $ eRelativePath ent),
+                            ("href", makeRelative epubSubdir
+                                     $ eRelativePath ent),
+                            ("media-type",
+                               fromMaybe "application/octet-stream"
                                $ mediaTypeOf $ eRelativePath ent)] $ ()
   let fontNode ent = unode "item" !
-                           [("id", toId $ eRelativePath ent),
-                            ("href", eRelativePath ent),
-                            ("media-type", fromMaybe "" $ getMimeType $ eRelativePath ent)] $ ()
+                           [("id", toId $ makeRelative epubSubdir
+                                        $ eRelativePath ent),
+                            ("href", makeRelative epubSubdir
+                                     $ eRelativePath ent),
+                            ("media-type", fromMaybe "" $
+                                  getMimeType $ eRelativePath ent)] $ ()
   let plainTitle = case docTitle' meta of
                         [] -> case epubTitle metadata of
                                    []    -> "UNTITLED"
@@ -613,7 +634,9 @@
              ] ++
              [ unode "item" ! [("id","style"), ("href",fp)
                               ,("media-type","text/css")] $ () |
-                          fp <- map eRelativePath stylesheetEntries ] ++
+                             fp <- map
+                               (makeRelative epubSubdir . eRelativePath)
+                               stylesheetEntries ] ++
              map chapterNode (cpgEntry ++ (tpEntry : chapterEntries)) ++
              (case cpicEntry of
                     []    -> []
@@ -648,7 +671,7 @@
                | isJust (epubCoverImage metadata)
              ]
           ]
-  let contentsEntry = mkEntry "content.opf" contentsData
+  contentsEntry <- mkEntry "content.opf" contentsData
 
   -- toc.ncx
   let secs = hierarchicalize blocks'
@@ -681,12 +704,12 @@
       navMapFormatter n tit src subs = unode "navPoint" !
                [("id", "navPoint-" ++ show n)] $
                   [ unode "navLabel" $ unode "text" $ stringify tit
-                  , unode "content" ! [("src", inSubdir src)] $ ()
+                  , unode "content" ! [("src", "text/" ++ src)] $ ()
                   ] ++ subs
 
   let tpNode = unode "navPoint" !  [("id", "navPoint-0")] $
                   [ unode "navLabel" $ unode "text" (stringify $ docTitle' meta)
-                  , unode "content" ! [("src", inSubdir "title_page.xhtml")]
+                  , unode "content" ! [("src", "text/title_page.xhtml")]
                   $ () ]
 
   navMap <- lift $ evalStateT (mapM (navPointNode navMapFormatter) secs) 1
@@ -710,13 +733,13 @@
           , unode "navMap" $
               tpNode : navMap
           ]
-  let tocEntry = mkEntry "toc.ncx" tocData
+  tocEntry <- mkEntry "toc.ncx" tocData
 
   let navXhtmlFormatter :: Int -> [Inline] -> String -> [Element] -> Element
       navXhtmlFormatter n tit src subs = unode "li" !
                                        [("id", "toc-li-" ++ show n)] $
                                             (unode "a" !
-                                                [("href", inSubdir src)]
+                                                [("href", "text/" ++ src)]
                                              $ titElements)
                                             : case subs of
                                                  []    -> []
@@ -766,36 +789,37 @@
             (Pandoc (setMeta "title"
                      (walk removeNote $ fromList $ docTitle' meta) nullMeta)
                (navBlocks ++ landmarks))
-  let navEntry = mkEntry "nav.xhtml" navData
+  navEntry <- mkEntry "nav.xhtml" navData
 
   -- mimetype
-  let mimetypeEntry = mkEntry "mimetype" $ UTF8.fromStringLazy "application/epub+zip"
+  mimetypeEntry <- mkEntry "mimetype" $
+                        UTF8.fromStringLazy "application/epub+zip"
 
   -- container.xml
   let containerData = UTF8.fromStringLazy $ ppTopElement $
        unode "container" ! [("version","1.0")
               ,("xmlns","urn:oasis:names:tc:opendocument:xmlns:container")] $
          unode "rootfiles" $
-           unode "rootfile" ! [("full-path", inSubdir "content.opf")
+           unode "rootfile" ! [("full-path",
+                    (if null epubSubdir
+                        then ""
+                        else epubSubdir ++ "/") ++ "content.opf")
                ,("media-type","application/oebps-package+xml")] $ ()
-  let containerEntry = mkEntry "META-INF/container.xml" containerData
+  containerEntry <- mkEntry "META-INF/container.xml" containerData
 
   -- com.apple.ibooks.display-options.xml
   let apple = UTF8.fromStringLazy $ ppTopElement $
         unode "display_options" $
           unode "platform" ! [("name","*")] $
             unode "option" ! [("name","specified-fonts")] $ "true"
-  let appleEntry = mkEntry "META-INF/com.apple.ibooks.display-options.xml" apple
+  appleEntry <- mkEntry "META-INF/com.apple.ibooks.display-options.xml" apple
 
-  let addEpubSubdir :: Entry -> Entry
-      addEpubSubdir e = e{ eRelativePath = inSubdir (eRelativePath e) }
   -- construct archive
   let archive = foldr addEntryToArchive emptyArchive $
-                 [mimetypeEntry, containerEntry, appleEntry] ++
-                 map addEpubSubdir
-                 (tpEntry : contentsEntry : tocEntry : navEntry :
-                  (stylesheetEntries ++ picEntries ++ cpicEntry ++
-                   cpgEntry ++ chapterEntries ++ fontEntries))
+                 [mimetypeEntry, containerEntry, appleEntry,
+                  contentsEntry, tocEntry, navEntry, tpEntry] ++
+                  stylesheetEntries ++ picEntries ++ cpicEntry ++
+                  cpgEntry ++ chapterEntries ++ fontEntries
   return $ fromArchive archive
 
 metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element
@@ -918,8 +942,8 @@
   newsrc <- modifyMediaRef src
   newposter <- modifyMediaRef poster
   let attr' = filter (\(x,_) -> x /= "src" && x /= "poster") attr ++
-              [("src", newsrc) | not (null newsrc)] ++
-              [("poster", newposter) | not (null newposter)]
+              [("src", "../" ++ newsrc) | not (null newsrc)] ++
+              [("poster", "../" ++ newposter) | not (null newposter)]
   return $ TagOpen name attr'
 transformTag tag = return tag
 
@@ -936,8 +960,7 @@
                let new = "media/file" ++ show (length media) ++
                           fromMaybe (takeExtension (takeWhile (/='?') oldsrc))
                           (('.':) <$> (mbMime >>= extensionFromMimeType))
-               epochtime <- floor `fmap` lift P.getPOSIXTime
-               let entry = toEntry new epochtime (B.fromChunks . (:[]) $ img)
+               entry <- mkEntry new (B.fromChunks . (:[]) $ img)
                modify $ \st -> st{ stMediaPaths =
                             (oldsrc, (new, Just entry)):media}
                return new)
diff --git a/stack.yaml b/stack.yaml
--- a/stack.yaml
+++ b/stack.yaml
@@ -7,7 +7,7 @@
 packages:
 - '.'
 extra-deps:
-- pandoc-types-1.17.2
+- pandoc-types-1.17.3
 - hslua-0.9.2
 - skylighting-0.4.3.2
 - texmath-0.10
diff --git a/test/command/4054.md b/test/command/4054.md
new file mode 100644
--- /dev/null
+++ b/test/command/4054.md
@@ -0,0 +1,14 @@
+```
+% pandoc -t native -s -M title=New
+% Old
+^D
+Pandoc (Meta {unMeta = fromList [("title",MetaString "New")]})
+[]
+```
+
+```
+% pandoc -t native -s -M foo=1 -M foo=2
+^D
+Pandoc (Meta {unMeta = fromList [("foo",MetaList [MetaString "1",MetaString "2"])]})
+[]
+```
diff --git a/test/command/indented-fences.md b/test/command/indented-fences.md
new file mode 100644
--- /dev/null
+++ b/test/command/indented-fences.md
@@ -0,0 +1,20 @@
+`````
+% pandoc -t native
+  ```haskell
+  let x = y
+in y
+   ```
+^D
+[CodeBlock ("",["haskell"],[]) "let x = y\nin y"]
+`````
+`````
+% pandoc -t native
+ ~~~ {.haskell}
+  let x = y
+ in y +
+y +
+ y
+~~~
+^D
+[CodeBlock ("",["haskell"],[]) " let x = y\nin y +\ny +\ny"]
+`````
diff --git a/test/command/yaml-with-chomp.md b/test/command/yaml-with-chomp.md
new file mode 100644
--- /dev/null
+++ b/test/command/yaml-with-chomp.md
@@ -0,0 +1,12 @@
+```
+% pandoc -s -t native
+---
+ml: |-
+    TEST
+
+    BLOCK
+...
+^D
+Pandoc (Meta {unMeta = fromList [("ml",MetaBlocks [Para [Str "TEST"],Plain [Str "BLOCK"]])]})
+[]
+```
