Skip to content

Instantly share code, notes, and snippets.

Avatar

Benct Philip Jonsson bpj

View GitHub Profile
@bpj
bpj / move-image-caption.lua
Last active Aug 15, 2020 — forked from zuphilip/move-image-caption.lua
Pandoc filter for moving image caption [CC0]
View move-image-caption.lua
-- If the image caption is a separate paragraph below the
-- image, then this script will move it into the curly braces in
-- Markdown and make sure it is not redundantly present.
-- For example:
--
-- ![](image1.png)
-- ==> ![Abb. 1: title](image1.png)
-- Abb. 1: title
--
-- You can configure which "prefixes" (like "Abb.") identify a caption paragraph
View import-select.moon
-- DWIM selective table item copying for Moonscript (and Lua)
import_select = (target, source, ...) ->
names = {...}
-- allow passing a table of names,
-- possibly with renames
if 1 == #names and 'table' == type names[1]
names = names[1]
-- map keys are "new" names
@bpj
bpj / variable-length-lookbehind.pl
Created Dec 21, 2019
Emulate variable length lookbehind in Perl regexes
View variable-length-lookbehind.pl
#!/usr/bin/env perl
#===============================================================================
# Perl used to not support variable-length lookbehind (VLLB) in
# regexes. Version 5.30 supports *limited length*
# VLLB, but this trick emulates VLLB in older versions too,
# and apparently without any arbitrary
# length limit!
#
# See <http://www.drregex.com/2019/02/variable-length-lookbehinds-actually.html?m=1>
#
@bpj
bpj / pandoc-texlive.sh
Created Jun 24, 2019
Minimal TeXLive installation for Pandoc
View pandoc-texlive.sh
#!/bin/sh
# pandoc-texlive.sh
# TeXLive packages needed to produce PDFs with Pandoc
# using different *TeX `--pdf-engine` options.
tlmgr install \
scheme-basic \
amsfonts \
amsmath \
@bpj
bpj / pandoc-fix-backtick-codeblocks.lua
Last active Feb 13, 2019
Pandoc filter which prevents code blocks containing backticks being mangled in Markdown output
View pandoc-fix-backtick-codeblocks.lua
--[[
Pandoc filter which prevents code blocks containing backticks being mangled in Markdown output.
| This software is Copyright (c) 2019 by Benct Philip Jonsson.
|
| This is free software, licensed under:
|
| The MIT (X11) License
@bpj
bpj / pandoc-poetry-line-blocks.lua
Last active Jan 1, 2019
Pandoc Lua filter which converts docx with poetry as found in the wild to one line block per verse
View pandoc-poetry-line-blocks.lua
--[[
Pandoc Lua filter which converts docx with poetry as found in the wild
where each line is a paragraph and each verse is separated by an empty
paragraph into one Pandoc line block per verse, if run like this:
pandoc -r docx+empty_paragraphs --lua-filter pandoc-poetry-line-blocks.lua poetry.docx -so poetry.md
Note the `+empty_paragraphs` extension! It is necessary for this filter to
do its work correctly!
@bpj
bpj / pandoc-backslashes.pl
Last active Dec 27, 2018
Remove unnecessary backslashes in Markdown which has been reformatted by Pandoc
View pandoc-backslashes.pl
#!/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 Oct 20, 2018
Let Pandoc combine several files with some markup inserted between them
View ABOUT.md

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}
<div style="page-break-after: always;"></div>
@bpj
bpj / pandoc-option-anchors.lua
Last active Sep 18, 2018
Pandoc filter to add anchors to option descriptions in CLI program documentation
View pandoc-option-anchors.lua
--[[
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 Jul 30, 2018
Pandoc Lua filter which replaces \TeX, \LaTeX etc. logos with appropriate HTML
View pandoc-texlogo2html.lua
--[[
# 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
You can’t perform that action at this time.