Skip to content

Instantly share code, notes, and snippets.

View bpj's full-sized avatar

Benct Philip Jonsson bpj

View GitHub Profile
@bpj
bpj / no-fig-pandoc.lua
Last active June 11, 2023 13:41
Pandoc filter implementing a better logic for image-in-a-para vs. figure in Markdown
--[===[# `no-fig-pandoc.lua`
Pandoc filter implementing a better logic for image-in-a-para vs. figure in Markdown
This Pandoc filter strips the Figure around an Image if the Figure
has no other practical child than that Image, by replacing the Figure
with a paragraph containing the Image and a non-breaking space (U+00A0)
An Image with a class `.fig` will cause the Figure to be preserved.
@bpj
bpj / merge-abbrevs-pandoc.pl
Last active June 11, 2023 14:22
Create/update a Pandoc abbreviations file from YAML/text files
#!/usr/bin/env perl
use 5.014;
# use utf8;
use utf8::all;
use strict;
use warnings;
use warnings FATAL => 'utf8';
use autodie;
@bpj
bpj / env2div.lua
Last active December 31, 2020 16:58
Pandoc filter which converts select raw LaTeX environments into Pandoc native divs
--[==============================[
Pandoc filter which converts select raw LaTeX environments into Pandoc native divs,
with the evironment name as first/only class and a possible
mandatory argument after the environment name converted to a first
paragraph in the div. This was in response to a question on how to
convert certain environments into ReStructuredText directives, so some
of the comments relate to that.
To use this filter run pandoc like this:
@bpj
bpj / attr-color.lua
Last active February 12, 2024 08:11
A Pandoc filter which sets LaTeX text/background/frame color(s) on Span and Div elements based on Pandoc attributes.
--[==============================[
# attr-color.lua
A Pandoc filter which sets LaTeX text/background/frame color(s) on
Span and Div elements based on Pandoc attributes.
## Usage
See https://git.io/JI4yA
@bpj
bpj / move-image-caption.lua
Last active August 15, 2020 18:01 — forked from zuphilip/move-image-caption.lua
Pandoc filter for moving image caption [CC0]
-- 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
-- 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 December 21, 2019 21:56
Emulate variable length lookbehind in Perl regexes
#!/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 June 24, 2019 16:24
Minimal TeXLive installation for Pandoc
#!/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 February 13, 2019 17:14
Pandoc filter which prevents code blocks containing backticks being mangled in Markdown output
--[[
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 January 1, 2019 02:16
Pandoc Lua filter which converts docx with poetry as found in the wild to one line block per verse
--[[
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!