Lacking Natural Simplicity (Posts about groff ms macros)https://tkurtbond.github.io/categories/groff-ms-macros.atom2024-01-23T18:49:40ZT. Kurt BondNikolaCustomizing pandoc ms output with a Lua filterhttps://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/2020-05-03T01:01:53-04:002020-05-03T01:01:53-04:00T. Kurt Bond<p>This article started as a <a class="reference external" href="https://groups.google.com/d/msg/pandoc-discuss/UJgyLbxTNxo/MZDVFts-BAAJ">message</a> I sent to the the <a class="reference external" href="https://groups.google.com/forum/#!forum/pandoc-discuss">pandoc-discuss</a>
Google Group. This version has more links and has been slightly
reworded.</p>
<p>I work with <a class="reference external" href="https://docutils.sourceforge.io/rst.html">ReStructuredText</a> documents a lot and often use <a class="reference external" href="https://pandoc.org/">pandoc</a> to
format them, especially to PDF by way of <span class="app">pandoc</span>'s <code class="docutils literal">ms</code>
output format, which uses <span class="app">groff</span> with the <code class="docutils literal"><span class="pre">-ms</span></code> macros to produce the
PDF output. Using <code class="docutils literal">ms</code> output is fast, <span class="app">groff</span> is usually available
on the operating systems I use, and if you <em>do</em> have to install <span class="app">groff</span>
it is easy to do and much, much smaller than any <span class="app">TeX</span> distributions.</p>
<p>However, it would be a nice to be able to customize the <code class="docutils literal">ms</code> output
more for specific input, like if you are using technical writing and
are pining for something like the various inline roles of <a class="reference external" href="https://tdg.docbook.org/tdg/5.1/ch02.html#s.inline">DocBook</a>, or
wanted poems to be typeset more stylishly that the <code class="docutils literal">ms</code> output does.</p>
<p>You should probably be a little familiar with the <a class="reference external" href="https://pandoc.org/MANUAL.html">Pandoc User
Manual</a> and have the documentation for <a class="reference external" href="https://pandoc.org/lua-filters.html">Lua Filter</a>'s available for
reference while reading this article. And having a reading
familiarity with <a class="reference external" href="https://www.gnu.org/software/groff/">groff</a> and its <a class="reference external" href="https://www.gnu.org/software/groff/manual/">manual</a> and specifically the <a class="reference external" href="https://www.gnu.org/software/groff/manual/html_node/ms.html#ms">-ms
macros</a> will be useful too. And maybe <a class="reference external" href="https://www.lua.org/">Lua</a> as well.</p>
<p>Starting with an <a class="reference external" href="https://dave.autonoma.ca/blog/2020/04/28/typesetting-markdown-part-8/">article</a> from Dave Jarvis that had an example <a class="reference external" href="https://pandoc.org/lua-filters.html">Lua
filter</a> for customizing the <span class="app">ConTeXt</span> output and a little help
from the pandoc-discuss mailing list I came up with this example <a class="reference external" href="https://pandoc.org/lua-filters.html">Lua
Filter</a> that formats program names and poems specially.</p>
<p>This filter wraps spans with a class, such as from interpreted text
roles defined in the source ReST (like <code class="docutils literal"><span class="pre">:program:`pandoc`</span></code>) in calls
to user defined <span class="app">groff</span> strings <code class="docutils literal"><span class="pre">\*[start<class>]</span></code> and
<code class="docutils literal"><span class="pre">\*[stop<class>]</span></code>. (I've specified the string definitions for
<code class="docutils literal"><span class="pre">\*[startprogram]</span></code> and <code class="docutils literal"><span class="pre">\*[stopprogram]</span></code> in the source ReST as a
raw block for <code class="docutils literal">ms</code> output but they could be in a customized <code class="docutils literal">ms</code>
pandoc template, too.) These strings can include <span class="app">groff</span> escapes to
change the font and the glyph color and then change back to the
previous font and glyph color. In this example I made PDF output for
the interpreted text role <code class="docutils literal">program</code> come out in a constant width
font and in red.</p>
<p>It also wraps divs with classes with calls to user defined <span class="app">groff</span>
macros <code class="docutils literal">.start<class></code> and <code class="docutils literal">.stop<class></code> (also included in the
source ReST in the raw block for ms output).</p>
<p>For divs with the poem class, it converts any contained LineBlock
elements into a list of Plain elements containing its contents,
avoiding the ms output for the LineBlock starting with <code class="docutils literal">.LP</code>, which
would cancel the <code class="docutils literal">.DS</code> (display start) macro I want to use in the
.startpoem macro definition. The <code class="docutils literal">.LP</code> would also reset the font family
in use to the default, another reason to avoid it. <a class="footnote-reference brackets" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#lp" id="footnote-reference-1" role="doc-noteref"><span class="fn-bracket">[</span>1<span class="fn-bracket">]</span></a></p>
<p>The filter also converts the empty element that occurs in the line block
as a result of a blank line in the line block input into a RawBlock
that creates a blank line in the ms output, to show the division into
stanzas of the poem.</p>
<p>Interestingly, the first Str elements in the each line in the content
of the line block preserved the leading spaces from the input as
Unicode NO-BREAK SPACE characters, preserving indentation of lines in
the line block. Unfortunately, the width of those spaces alone is not
enough create a visually distinct indentation, so this filter changes
those Str elements into a RawInline that outputs a <span class="app">groff</span> horizfontal
movement whose width is based on the number of leading NO-BREAK SPACE
characters, and follow this with a new Str element that has the
leading NO-BREAK SPACE characters removed.</p>
<p>Here is the Lua filter, <span class="file">classify-rst-ms.lua</span>:</p>
<div class="code"><pre class="code lua"><a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-1" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-1" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-1"></a><span class="n">onig</span> <span class="o">=</span> <span class="nb">require</span> <span class="p">(</span><span class="s2">"rex_onig"</span><span class="p">)</span> <span class="c1">-- Need a regex package that understands UTF8.</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-2" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-2" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-2"></a><span class="c1">-- text in LineBreak preserves leading spaces as Unicode NO-BREAK SPACE</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-3" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-3" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-3"></a><span class="n">leading_nobreakspace_rx</span> <span class="o">=</span> <span class="n">onig</span><span class="p">.</span><span class="n">new</span> <span class="p">(</span><span class="s2">"^(</span><span class="se">\u{a0}</span><span class="s2">+)(.*)$"</span><span class="p">,</span> <span class="kc">nil</span><span class="p">,</span> <span class="s2">"UTF8"</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-4" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-4" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-4"></a>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-5" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-5" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-5"></a><span class="kr">function</span> <span class="nf">Div</span><span class="p">(</span> <span class="n">element</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-6" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-6" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-6"></a> <span class="kd">local</span> <span class="n">annotation</span> <span class="o">=</span> <span class="n">element</span><span class="p">.</span><span class="n">classes</span><span class="p">:</span><span class="n">find_if</span><span class="p">(</span> <span class="n">matches</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-7" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-7" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-7"></a> <span class="kd">local</span> <span class="n">numPara</span> <span class="o">=</span> <span class="mi">0</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-8" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-8" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-8"></a> <span class="kr">if</span> <span class="n">annotation</span> <span class="kr">then</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-9" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-9" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-9"></a> <span class="n">annotation</span> <span class="o">=</span> <span class="n">annotation</span><span class="p">:</span><span class="n">gsub</span><span class="p">(</span> <span class="s2">"[^%w]*"</span><span class="p">,</span> <span class="s2">""</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-10" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-10" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-10"></a> <span class="kr">if</span> <span class="n">annotation</span> <span class="o">==</span> <span class="s2">"poem"</span> <span class="kr">then</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-11" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-11" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-11"></a> <span class="n">element</span> <span class="o">=</span> <span class="n">pandoc</span><span class="p">.</span><span class="n">walk_block</span> <span class="p">(</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-12" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-12" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-12"></a> <span class="n">element</span><span class="p">,</span> <span class="p">{</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-13" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-13" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-13"></a> <span class="c1">-- Replace LineBlock element with a list of Plain elements</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-14" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-14" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-14"></a> <span class="c1">-- containing the LineBlock's subelements.</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-15" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-15" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-15"></a> <span class="n">LineBlock</span> <span class="o">=</span> <span class="kr">function</span> <span class="p">(</span><span class="n">el</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-16" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-16" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-16"></a> <span class="kd">local</span> <span class="n">l</span> <span class="o">=</span> <span class="p">{}</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-17" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-17" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-17"></a> <span class="kr">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">subel</span> <span class="kr">in</span> <span class="nb">ipairs</span> <span class="p">(</span><span class="n">el</span><span class="p">.</span><span class="n">content</span><span class="p">)</span> <span class="kr">do</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-18" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-18" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-18"></a> <span class="kr">if</span> <span class="o">#</span><span class="n">subel</span> <span class="o">==</span> <span class="mi">0</span> <span class="kr">then</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-19" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-19" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-19"></a> <span class="c1">-- If subel is an empty table, output a raw empty line</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-20" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-20" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-20"></a> <span class="nb">table.insert</span> <span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="n">pandoc</span><span class="p">.</span><span class="n">RawBlock</span> <span class="p">(</span><span class="s2">"ms"</span><span class="p">,</span> <span class="s2">"</span><span class="se">\n\n</span><span class="s2">"</span><span class="p">))</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-21" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-21" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-21"></a> <span class="kr">else</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-22" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-22" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-22"></a> <span class="c1">-- Check for leading NO-BREAK SPACE charaters</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-23" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-23" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-23"></a> <span class="kd">local</span> <span class="n">m1</span><span class="p">,</span> <span class="n">m2</span> <span class="o">=</span> <span class="n">onig</span><span class="p">.</span><span class="n">match</span> <span class="p">(</span><span class="n">subel</span><span class="p">[</span><span class="mi">1</span><span class="p">].</span><span class="n">text</span><span class="p">,</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-24" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-24" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-24"></a> <span class="n">leading_nobreakspace_rx</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-25" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-25" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-25"></a> <span class="kr">if</span> <span class="n">m1</span> <span class="kr">then</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-26" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-26" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-26"></a> <span class="c1">-- Replace the NO-BREAK SPACE characters with a raw</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-27" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-27" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-27"></a> <span class="c1">-- groff horizontal movement, because the</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-28" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-28" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-28"></a> <span class="c1">-- NO-BREAK SPACE characters are too narrow.</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-29" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-29" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-29"></a> <span class="nb">table.insert</span> <span class="p">(</span><span class="n">subel</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">pandoc</span><span class="p">.</span><span class="n">RawInline</span> <span class="p">(</span><span class="s2">"ms"</span><span class="p">,</span> <span class="nb">string.format</span> <span class="p">(</span><span class="s2">"</span><span class="se">\\</span><span class="s2">h'%dn'"</span><span class="p">,</span> <span class="nb">utf8.len</span> <span class="p">(</span><span class="n">m1</span><span class="p">))))</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-30" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-30" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-30"></a> <span class="c1">-- Modify what was used to be the first item to just</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-31" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-31" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-31"></a> <span class="c1">-- include the trailing characters of the match.</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-32" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-32" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-32"></a> <span class="n">subel</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">pandoc</span><span class="p">.</span><span class="n">Str</span> <span class="p">(</span><span class="n">m2</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-33" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-33" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-33"></a> <span class="nb">table.insert</span> <span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="n">pandoc</span><span class="p">.</span><span class="n">Plain</span> <span class="p">(</span><span class="n">subel</span><span class="p">))</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-34" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-34" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-34"></a> <span class="kr">else</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-35" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-35" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-35"></a> <span class="c1">-- Just put the subel in Plain element.</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-36" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-36" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-36"></a> <span class="nb">table.insert</span> <span class="p">(</span><span class="n">l</span><span class="p">,</span> <span class="p">(</span><span class="n">pandoc</span><span class="p">.</span><span class="n">Plain</span> <span class="p">(</span><span class="n">subel</span><span class="p">)))</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-37" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-37" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-37"></a> <span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-38" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-38" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-38"></a> <span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-39" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-39" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-39"></a> <span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-40" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-40" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-40"></a> <span class="kr">return</span> <span class="n">l</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-41" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-41" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-41"></a> <span class="kr">end</span> <span class="p">})</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-42" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-42" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-42"></a> <span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-43" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-43" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-43"></a> <span class="kr">return</span> <span class="p">{</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-44" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-44" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-44"></a> <span class="n">ms</span><span class="p">(</span> <span class="s2">".start"</span><span class="p">,</span> <span class="n">annotation</span> <span class="p">),</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-45" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-45" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-45"></a> <span class="n">element</span><span class="p">,</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-46" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-46" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-46"></a> <span class="n">ms</span><span class="p">(</span> <span class="s2">".stop"</span><span class="p">,</span> <span class="n">annotation</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-47" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-47" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-47"></a> <span class="p">}</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-48" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-48" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-48"></a> <span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-49" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-49" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-49"></a><span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-50" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-50" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-50"></a>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-51" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-51" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-51"></a><span class="kr">function</span> <span class="nf">Span</span><span class="p">(</span><span class="n">element</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-52" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-52" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-52"></a> <span class="kd">local</span> <span class="n">annotation</span> <span class="o">=</span> <span class="n">element</span><span class="p">.</span><span class="n">classes</span><span class="p">:</span><span class="n">find_if</span><span class="p">(</span><span class="n">matches</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-53" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-53" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-53"></a>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-54" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-54" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-54"></a> <span class="kr">if</span> <span class="n">annotation</span> <span class="kr">then</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-55" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-55" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-55"></a> <span class="n">annotation</span> <span class="o">=</span> <span class="n">annotation</span><span class="p">:</span><span class="n">gsub</span><span class="p">(</span><span class="s2">"[^%w]*"</span><span class="p">,</span> <span class="s2">""</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-56" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-56" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-56"></a>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-57" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-57" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-57"></a> <span class="kr">return</span> <span class="p">{</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-58" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-58" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-58"></a> <span class="n">ms_inline</span><span class="p">(</span><span class="s2">"</span><span class="se">\\</span><span class="s2">*[start"</span><span class="p">,</span> <span class="n">annotation</span><span class="p">,</span> <span class="s2">"]"</span><span class="p">),</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-59" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-59" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-59"></a> <span class="n">element</span><span class="p">,</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-60" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-60" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-60"></a> <span class="n">ms_inline</span><span class="p">(</span><span class="s2">"</span><span class="se">\\</span><span class="s2">*[stop"</span><span class="p">,</span> <span class="n">annotation</span><span class="p">,</span> <span class="s2">"]"</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-61" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-61" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-61"></a> <span class="p">}</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-62" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-62" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-62"></a> <span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-63" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-63" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-63"></a><span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-64" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-64" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-64"></a>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-65" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-65" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-65"></a><span class="kr">function</span> <span class="nf">matches</span><span class="p">(</span> <span class="n">s</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-66" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-66" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-66"></a> <span class="kr">return</span> <span class="n">s</span><span class="p">:</span><span class="n">match</span><span class="p">(</span> <span class="s2">"^%a+"</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-67" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-67" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-67"></a><span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-68" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-68" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-68"></a>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-69" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-69" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-69"></a><span class="kr">function</span> <span class="nf">ms</span><span class="p">(</span> <span class="n">macro</span><span class="p">,</span> <span class="n">annotation</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-70" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-70" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-70"></a> <span class="kr">return</span> <span class="n">pandoc</span><span class="p">.</span><span class="n">RawBlock</span><span class="p">(</span> <span class="s2">"ms"</span><span class="p">,</span> <span class="n">macro</span> <span class="o">..</span> <span class="n">annotation</span> <span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-71" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-71" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-71"></a><span class="kr">end</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-72" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-72" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-72"></a>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-73" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-73" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-73"></a><span class="kr">function</span> <span class="nf">ms_inline</span> <span class="p">(</span><span class="n">macro</span><span class="p">,</span> <span class="n">annotation</span><span class="p">,</span> <span class="n">stop</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-74" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-74" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-74"></a> <span class="kr">return</span> <span class="n">pandoc</span><span class="p">.</span><span class="n">RawInline</span> <span class="p">(</span><span class="s2">"ms"</span><span class="p">,</span> <span class="n">macro</span> <span class="o">..</span> <span class="n">annotation</span> <span class="o">..</span> <span class="n">stop</span><span class="p">)</span>
<a id="rest_code_d7a56000eea347d29a9fd0b471629dbf-75" name="rest_code_d7a56000eea347d29a9fd0b471629dbf-75" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_d7a56000eea347d29a9fd0b471629dbf-75"></a><span class="kr">end</span>
</pre></div>
<p>Here is the ReST source of the document, <span class="file">poem-plus.rst</span>:</p>
<div class="code"><pre class="code ReST"><a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-1" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-1" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-1"></a>Lua Filters For Massaging <span class="s">``ms``</span> Output
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-2" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-2" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-2"></a>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-3" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-3" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-3"></a>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-4" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-4" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-4"></a><span class="p">..</span> <span class="ow">raw</span><span class="p">::</span> ms
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-5" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-5" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-5"></a>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-6" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-6" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-6"></a> .ds startprogram \\f[CW]\\m[red]
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-7" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-7" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-7"></a> .ds stopprogram \\m[]\\fP
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-8" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-8" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-8"></a> .de startpoem
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-9" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-9" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-9"></a> .ds OLDFAM \\*[FAM]
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-10" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-10" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-10"></a> .ds FAM BM
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-11" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-11" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-11"></a> .DS I 3
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-12" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-12" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-12"></a><span class="cp"> ..</span>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-13" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-13" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-13"></a><span class="cp"> .de stoppoem</span>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-14" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-14" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-14"></a><span class="cp"> .DE</span>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-15" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-15" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-15"></a><span class="cp"> .ds FAM \\*[OLDFAM]</span>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-16" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-16" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-16"></a><span class="cp"> ..</span>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-17" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-17" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-17"></a>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-18" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-18" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-18"></a><span class="p">..</span> <span class="ow">role</span><span class="p">::</span> program
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-19" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-19" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-19"></a>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-20" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-20" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-20"></a>This is a sentence. This sentence talks about <span class="na">:program:</span><span class="nv">`pandoc`</span>.
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-21" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-21" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-21"></a>This is
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-22" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-22" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-22"></a>another sentence.
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-23" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-23" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-23"></a>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-24" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-24" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-24"></a><span class="p">..</span> <span class="ow">class</span><span class="p">::</span> poem
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-25" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-25" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-25"></a>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-26" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-26" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-26"></a> <span class="o">|</span> Some say the world will end in fire,
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-27" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-27" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-27"></a> <span class="o">|</span> Some say in ice.
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-28" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-28" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-28"></a> <span class="o">|</span> From what I've tasted of desire
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-29" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-29" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-29"></a> <span class="o">|</span> I hold with those who favor fire.
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-30" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-30" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-30"></a> <span class="o">|</span> But if it had to perish twice,
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-31" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-31" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-31"></a> <span class="o">|</span> I think I know enough of hate
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-32" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-32" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-32"></a> <span class="o">|</span> To say that for destruction ice
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-33" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-33" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-33"></a> <span class="o">|</span> Is also great,
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-34" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-34" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-34"></a> <span class="o">|</span> And would suffice.
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-35" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-35" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-35"></a> |
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-36" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-36" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-36"></a> <span class="o">|</span> And another line,
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-37" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-37" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-37"></a> <span class="o">|</span> And an indented line.
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-38" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-38" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-38"></a>
<a id="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-39" name="rest_code_0f4dd3d29ca847dc943816a43dfb9cba-39" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_0f4dd3d29ca847dc943816a43dfb9cba-39"></a>This is a final sentence.
</pre></div>
<p>And here is the ms output:</p>
<div class="code"><pre class="code groff"><a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-1" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-1" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-1"></a>.<span class="k">SH</span> <span class="m">1</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-2" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-2" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-2"></a>Lua Filters For Massaging <span class="se">\f[CB]ms\f[B]</span> Output
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-3" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-3" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-3"></a>.<span class="k">pdfhref</span> <span class="s">O</span> <span class="m">1</span> <span class="s2">"Lua Filters For Massaging ms Output"</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-4" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-4" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-4"></a>.<span class="k">pdfhref</span> <span class="s">M</span> <span class="s2">"lua-filters-for-massaging-ms-output"</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-5" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-5" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-5"></a>.<span class="k">ds</span> <span class="s">startprogram</span> <span class="se">\\</span><span class="s">f[CW]\\m[red]</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-6" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-6" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-6"></a>.<span class="k">ds</span> <span class="s">stopprogram</span> <span class="se">\\</span><span class="s">m[]\\fP</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-7" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-7" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-7"></a>.<span class="k">de</span> <span class="s">startpoem</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-8" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-8" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-8"></a>.<span class="k">ds</span> <span class="s">OLDFAM</span> <span class="se">\\</span><span class="s">*[FAM]</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-9" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-9" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-9"></a>.<span class="k">ds</span> <span class="s">FAM</span> <span class="s">BM</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-10" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-10" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-10"></a>.<span class="k">DS</span> <span class="s">I</span> <span class="m">3</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-11" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-11" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-11"></a><span class="p">.</span><span class="s">.</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-12" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-12" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-12"></a>.<span class="k">de</span> <span class="s">stoppoem</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-13" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-13" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-13"></a>.<span class="k">DE</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-14" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-14" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-14"></a>.<span class="k">ds</span> <span class="s">FAM</span> <span class="se">\\</span><span class="s">*[OLDFAM]</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-15" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-15" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-15"></a><span class="p">.</span><span class="s">.</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-16" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-16" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-16"></a>.<span class="k">LP</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-17" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-17" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-17"></a>This is a sentence.
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-18" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-18" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-18"></a>This sentence talks about <span class="se">\*[startprogram]pandoc\*[stopprogram]</span>.
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-19" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-19" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-19"></a>This is
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-20" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-20" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-20"></a>another sentence.
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-21" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-21" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-21"></a>.<span class="k">startpoem</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-22" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-22" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-22"></a>Some say the world will end in fire,
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-23" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-23" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-23"></a><span class="se">\h</span>'3n'Some say in ice.
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-24" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-24" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-24"></a>From what I<span class="se">\[</span>aq]ve tasted of desire
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-25" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-25" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-25"></a><span class="se">\h</span>'3n'I hold with those who favor fire.
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-26" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-26" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-26"></a>But if it had to perish twice,
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-27" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-27" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-27"></a><span class="se">\h</span>'3n'I think I know enough of hate
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-28" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-28" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-28"></a><span class="se">\h</span>'3n'To say that for destruction ice
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-29" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-29" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-29"></a><span class="se">\h</span>'3n'Is also great,
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-30" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-30" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-30"></a>And would suffice.
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-31" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-31" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-31"></a>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-32" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-32" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-32"></a>And another line,
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-33" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-33" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-33"></a><span class="se">\h</span>'3n'And an indented line.
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-34" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-34" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-34"></a>.<span class="k">stoppoem</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-35" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-35" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-35"></a>.<span class="k">LP</span>
<a id="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-36" name="rest_code_9aca7e0f0ab1490d80af0b671f0559d1-36" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_9aca7e0f0ab1490d80af0b671f0559d1-36"></a>This is a final sentence.
</pre></div>
<p>The command to produce the ms output is:</p>
<div class="code"><pre class="code bash"><a id="rest_code_316a58b86c874e41b75bc562e8387152-1" name="rest_code_316a58b86c874e41b75bc562e8387152-1" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_316a58b86c874e41b75bc562e8387152-1"></a>pandoc<span class="w"> </span>-f<span class="w"> </span>rst<span class="w"> </span>-t<span class="w"> </span>ms<span class="w"> </span>--lua-filter<span class="w"> </span>classify-rst-ms.lua<span class="w"> </span>--wrap<span class="o">=</span>preserve<span class="w"> </span>poem-plus.rst<span class="w"> </span>--output<span class="o">=</span>poem-plus-rst.ms
</pre></div>
<p>and the command to produce a PDF is:</p>
<div class="code"><pre class="code bash"><a id="rest_code_7e7a49c659494c09ae73ebd75383748c-1" name="rest_code_7e7a49c659494c09ae73ebd75383748c-1" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#rest_code_7e7a49c659494c09ae73ebd75383748c-1"></a>pandoc<span class="w"> </span>-f<span class="w"> </span>rst<span class="w"> </span>-t<span class="w"> </span>ms<span class="w"> </span>--lua-filter<span class="w"> </span>classify-rst-ms.lua<span class="w"> </span>--wrap<span class="o">=</span>preserve<span class="w"> </span>poem-plus.rst<span class="w"> </span>--output<span class="o">=</span>poem-plus-rst.ms.pdf
</pre></div>
<p><a class="reference external" href="https://tkurtbond.github.io/poem-plus-rst.ms.pdf">Here</a> is the output PDF.</p>
<p>Being able to rewrite the tree and insert RawBlocks and RawInlines is
really powerful when it comes to customizing output for particular
output formats.</p>
<p>I hope this example is useful for others like me just learning to use
Lua filters.</p>
<aside class="footnote-list brackets">
<aside class="footnote brackets" id="lp" role="doc-footnote">
<span class="label"><span class="fn-bracket">[</span><a role="doc-backlink" href="https://tkurtbond.github.io/posts/2020/05/03/customizing-pandoc-ms-output-with-a-lua-filter/#footnote-reference-1">1</a><span class="fn-bracket">]</span></span>
<p>The <code class="docutils literal">.LP</code> macro in the <code class="docutils literal"><span class="pre">-ms</span></code> macros resets a lot of
things back to the default when it is used, so if you want the custom
<span class="app">groff</span> setting from your user defined macros to continue from the
start to the end you can't allow the use of <code class="docutils literal">.LP</code> between the
<code class="docutils literal">.start<class></code> and <code class="docutils literal">.stop<class></code> macros.</p>
</aside>
</aside>