Skip to content

Instantly share code, notes, and snippets.

View bpj's full-sized avatar

Benct Philip Jonsson bpj

View GitHub Profile
@bpj
bpj / README.md
Last active April 6, 2022 08:40
Pandoc Markdown Quick Reference by Examples

pandoc-quick-ref.markdown

#!/usr/bin/env perl
#----------------------------------------------------------------------
# pandoc-small-caps.pl
#
# Pandoc filter to convert spans with class 'small-caps'
# (and optionally ~~Strikeout~~) to SmallCaps.
#
# pandoc -F pandoc-small-caps.pl [-M strikeout2smallcaps] ARGUMENTS...
#
@bpj
bpj / wikilink2link.pl
Last active December 6, 2021 06:26
wikilink2link.pl - Convert GitHub wikilinks to Markdown links.
#!/usr/bin/env perl
=encoding UTF-8
This is a Pandoc <http://pandoc.org> filter to turn
code blocks and code spans which have certain specified
classes into RawBlock or RawInline elements in specified
output formats, wrapping them in specified markup as needed.
It can be used e.g. to output LaTeX math in both LaTeX and HTML,
@bpj
bpj / pandoc-poetry.pl
Created March 27, 2015 09:54
A pandoc filter to format poetry nicely for HTML
#!/usr/bin/env perl
#----------------------------------------------------------------------
# pandoc-poetry.pl
# ================
#
# A pandoc filter to format poetry nicely for HTML.
#
# See <https://groups.google.com/d/msg/pandoc-discuss/_JnTJnsSK3k/SkM9tjfYyg0J>
#
@bpj
bpj / string2attrs.md
Created November 19, 2015 15:23
Extract HTML-like attributes from an arbitrary string with CSS-like shortcuts

Note: This documents the usage of both the perl and the python version. I have made the perl and python version work as alike as I could. In order to not favoritize either side hashes/dictionaries are called "associative arrays" and depicted as JSON objects in all their ugliness! :-)

The string2attrs function parses a string, e.g. a title string from a Pandoc Link or Image element, with attributes similar to those used with Pandoc Code, CodeBlock and Header elements (minus the braces) into an associative array of key--value pairs. Something like

"#foo .bar lang=la baz='biz buz'"

becomes

{"baz":"biz buz","id":"foo","lang":"la","class":"bar"}
@bpj
bpj / pandoc-collect-floats.pl
Last active April 8, 2016 11:12
Pandoc filters (pl and py) to collect all figures and tables at a specified place in a document
#!/usr/bin/env perl
=pod
Pandoc filter which emulate the LaTeX endfloat package by extracting all
elements which would be LaTeX floats (figures and tables) from a
document and putting them in div with the id "figures" or "tables"
respectively. You must mark the points in the document where you want
the floats to go with a paragraph containing *only* the text
"FiguresHere" or "TablesHere" -- exactly as written here in CamelCase --
@bpj
bpj / perl_and_pod_folding.vim
Last active December 11, 2015 15:55
A foldexpr function to fold both Pod and Perl code sensibly in the same file
" vim: set ft=vim et tw=80:
" A foldexpr function to fold both Pod and Perl code sensibly in the same
" file. It folds Pod according to its logical structure and code by
" indentation.
"
" Author: Benct Philip Jonsson <bpjonsson@gmail.com>
" Version: 2015-12-11-14 (YYYY-MM-DD-HH)
"
" It requires that the Pod blocks are well-behaved and start with `=pod` or
@bpj
bpj / pandoc-expand-simple.py
Last active January 6, 2016 19:29
Pandoc filter to wrap Span/Div in LaTeX based on classes
#!/usr/bin/env python
"""
Pandoc filter to wrap Span/Div in LaTeX based on classes
"""
import pandocfilters as pf
import re
begin_command = None
@bpj
bpj / pandoc-brace-spans.py
Created January 6, 2016 19:31
Pandoc filter to restore pre 1.16 behavior of wrapping Span contents in braces in LaTeX output
#!/usr/bin/env python
"""
Pandoc filter to restore pre 1.16 behavior of wrapping Span contents in braces in LaTeX output,
since I and maybe others have documents and/or filters relying on the old behavior
"""
import pandocfilters as pf
want_braces = None
open_brace = [pf.RawInline('tex', '{')]