Adding Pandoc Arguments in BBEdit
Published 3 years, 7 months pastThanks to the long and winding history of my blog, I write posts in Markdown in BBEdit, export them to HTML, and paste the resulting HTML into WordPress. I do it that way because switching WordPress over to auto-parsing Markdown in posts causes problems with rendering the markup of some posts I wrote 15-20 years ago, and finding and fixing every instance is a lengthy project for which I do not have the time right now.
(And I don’t use the block editor because whenever I use it to edit an old post, the markup in those posts get mangled so much that it makes me want to hurl. This is as much the fault of my weird idiosyncratic bespoke-ancient setup as of WordPress itself, but it’s still super annoying and so I avoid it entirely.)
Anyway, the point here is that I write Markdown in BBEdit, and export it from there. This works okay, but there have always been things missing, like a way to easily add attributes to elements like my code blocks. BBEdit’s default Markdown exporter, CommonMark, sort of supports that, except it doesn’t appear to give me control over the class names: telling it I want a class value of css
on a preformatted block means I get a class value of language-css
instead. Also it drops that class value on the code
element it inserts into the pre
element, instead of attaching it directly to the pre
element. Not good, unless I start using Prism, which I may one day but am not yet.
Pandoc, another exporter you can use in BBEdit, offers much more robust and yet simple element attribute attachment: you put {.class #id}
or whatever at the beginning of any element, and you get those things attached directly to the element. But by default, it also wraps elements around, and adds attributes to, the pre
element, apparently in anticipation of some other kind of syntax highlighting.
I spent an hour reading the Pandoc man page (just kidding, I was actually skimming, that’s the only way I could possibly get through all that in an hour) and found the --no-highlight
option. Perfect! So I dropped into Preferences > Languages > Language-specific settings:Markdown > Markdown, set the “Markdown processor” dropdown to “Custom”, and filled in the following:
Command | pandoc |
---|---|
Arguments | --no-highlight |
Done and done. I get a more powerful flavor of Markdown in an editor I know and love. It’s not perfect — I still have to manually tweak table markup by hand, for example — but it’s covering probably 95% of my use cases for writing blog posts.
Now all I need to do is find a Pandoc Markdown option or extensions or whatever that keeps it from collapsing the whitespace between elements in its HTML output, and I’ll be well and truly satisfied.
One Comment
Hi
I am just a huge fan of your books and your site.
Perhaps this is totally useless and old news.
After trying and giving up on wordpress for its huge restrictions and “trying to make it easier” approach which just makes everything more difficult, I opted for Hugo (www.gohugo.io) (it is not as static as it would appear) which renders markdown through Blackfriday and Goldmark. Since I also wanted to to plots and tables with R (for Statistical Computing, I used the markdown Blogdown-Bookdown (https://bookdown.org/yihui/blogdown/) (which is rendered with Pandoc and RMarkdown) and it will render clean elegant html, epub, pdf, you name it. It will not mess with your whitespaces, I think!
Probably old news for you!
Wishing you all the best! Keep up the good work and the good spirit.