Skip to content

Instantly share code, notes, and snippets.

View bpj's full-sized avatar

Benct Philip Jonsson bpj

View GitHub Profile
@bpj
bpj / pandoc-backslashes.pl
Last active December 27, 2018 18:27
Remove unnecessary backslashes in Markdown which has been reformatted by Pandoc
#!/usr/bin/env perl
use utf8;
use v5.14;
use strict;
use warnings;
use warnings qw(FATAL utf8);
use open qw(:std :utf8);
use charnames qw(:full :short);
@bpj
bpj / ABOUT.md
Last active October 20, 2018 15:08
Let Pandoc combine several files with some markup inserted between them

This Makefile does the trick of producing a file with Pandoc from a directory of Markdown files, with some Markdown appended after the content of each Markdown file — by default three blocks of raw markup which will insert a pagebreak in DOCX, HTML or LaTeX output, but it can be taken from a file and so can be anything — before producing a single output file (by default a DOCX file) from the combined inputs with the appendage file inserted after each input file.

The content to append is taken from the file ./append.md. If it doesn’t already exist it will be created with the following content:

````{=openxml}
<w:p><w:r><w:br w:type="page" /></w:r></w:p>
````

````{=html}
@bpj
bpj / pandoc-option-anchors.lua
Last active September 18, 2018 15:02
Pandoc filter to add anchors to option descriptions in CLI program documentation
--[[
pandoc options-anchors.lua
Pandoc filter which walks all definition lists in all divs with a class
`options-list` (or `optionslist` or `option-list` or `optionlist`) and
wraps all DL terms whose stringification starts with what looks like a
CLI option name[^1] in a span with an id `option-LONG-OPTION-NAME`,
where `LONG-OPTION-NAME` is the first long option name[^2] in the
stringified term. e.g.
@bpj
bpj / pandoc-texlogo2html.lua
Last active November 10, 2021 23:50
Pandoc Lua filter which replaces \TeX, \LaTeX etc. logos with appropriate HTML
--[[
# pandoc-texlogo2html.lua -- convert `\TeX` logo and friends to HTML
TL;DR: type `\LaTeX` in your Pandoc Markdown document and get sensible HTML!
This Pandoc filter replaces raw tex/latex blocks and inlines whose content
are tex logo commands like `\TeX`, `\LaTeX`, `\XeLaTeX`, `\LuaTeX` etc.
(The ones shown in the tex_logos table below, you can easily add more!)
with a raw block/inline with `html` as format and an HTML string which
@bpj
bpj / pandoc-quote-styles.pl
Last active November 14, 2017 12:56
pandoc-quote-styles.pl - Use custom smart quotes in Pandoc
#!/usr/bin/env perl
# version 0.4
use utf8;
use autodie 2.29;
use 5.010001;
use strict;
use warnings;
use warnings qw(FATAL utf8);
@bpj
bpj / README.md
Last active October 29, 2017 17:59
Move inline CSS styles to a stylesheet
@bpj
bpj / md-head2ul.pl
Last active October 31, 2021 04:21
Massage Markdown converted with Pandoc from OPML exported from Dynalist
#!/usr/bin/env perl
=head1 SYNOPSIS
pandoc -f opml -t markdown --atx-headers [PANDOC OPTIONS] input.opml \
| perl md-head2dl.pl [OPTIONS] > output.md
=head1 DESCRIPTION
Massage Markdown converted with Pandoc L<http://pandoc.org> from OPML exported from Dynalist <https://dynalist.io>.
@bpj
bpj / bidibug.latex
Created June 7, 2017 16:05
Modified Pandoc LaTeX template which makes sure bidi is loaded as very late as possible
\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$babel-lang$,$endif$$if(papersize)$$papersize$paper,$endif$$for(classoption)$$classoption$$sep$,$endfor$]{$documentclass$}
$if(beamerarticle)$
\usepackage{beamerarticle} % needs to be loaded first
$endif$
$if(fontfamily)$
\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
$else$
\usepackage{lmodern}
$endif$
$if(linestretch)$
@bpj
bpj / pandoc-class2style.pl
Last active June 9, 2017 12:55
pandoc-class2style.pl - filter to translate single pandoc classes into attribute lists or LaTeX commands (with POD documentation)
#!/usr/bin/env perl
# pandoc-class2style.pl - filter to translate single span/div classes into LaTeX commands and attribute lists
# POD documentation below the code!
use utf8;
use autodie 2.29;
use 5.010001;
use strict;
@bpj
bpj / pandoc-class2style.pl
Created March 11, 2017 17:47
Pandoc filter which 'converts' span and div classes with a trailing period into LaTeX commands/environments or DOCX styles
#!/usr/bin/env perl
=encoding UTF-8
=head1 DOCUMENTATION
# DESCRIPTION
Pandoc filter which 'converts' span and div classes with a
trailing period into LaTeX commands (for spans) or environments