Write Ascii for Check Box when Converting to HTML

Viewed 375

I'm writing out to HTML but then copying the text and pasting into MS Teams. So, I would like the check boxes to be ASCII instead of HTML inputs.

I'm using pandoc version 2.10 on Windows.

This is what I think I should be doing. But it doesn't seem to work:

echo - [ ] Yep | pandoc --ascii -f MARKDOWN -t HTML

The above was done with the terminal cmder. I tried it with Powershell 7 like below and it still gives the incorrect result:

echo "- [ ] Yep" | pandoc --ascii -f MARKDOWN -t HTML

Returns:

<ul class="task-list">
<li><input type="checkbox" disabled="" />
Yep</li>
</ul>

But I'm expecting:

<ul class="task-list">
<li>☐ Yep</li>
</ul>
3 Answers

As you discovered, the following input renders a checkbox when outputting to HTML:

- [ ] Yep

This is due to pandoc's task_list extension, which you can turn off as follows:

pandoc -f markdown-task_lists

which will output:

<ul>
  <li>[ ] Yep</li>
</ul

However, what you seem to expect is the checkbox unicode char, you can do this e.g. with generic raw attribute:

- `&#9744;`{=html} Yep

Solution using a Lua filter:

-- file: unicode-checkbox.lua
function Str (s)
  if s.text == '☐' then
    return pandoc.RawInline('html', s.text)
  end
end

Use with command

echo "- [ ] Yep" | pandoc --lua-filter=unicode-checkbox.lua -f MARKDOWN -t HTML

After some trial and error, there are a few changes you need to make to the command:

echo "\- &#9744 Yep" | pandoc -f markdown -t HTML | % {$_.replace("&amp;","&")}
  1. &#9744 is the HTML entity code for ☐
  2. pandoc formats & as &amp; by default so you need to replace this in the output using powershell's replace % {$_.replace("&amp;","&")}.

This should give <p>- &#9744 Yep</p>, which is "- ☐ Yep" (without quotes) in HTML.

You can see the demo here: https://jsfiddle.net/Fermicide/4jsnoya3/1/

If you want to copy directly to the clipboard, you can pipe the output into Set-Cipboard:

echo "\- &#9744 Yep" | pandoc -f markdown -t HTML | % {$_.replace("&amp;","&")} | Set-Clipboard
Related