Skip to content

Instantly share code, notes, and snippets.

View tarleb's full-sized avatar
🌱
Growing some software

Albert Krewinkel tarleb

🌱
Growing some software
View GitHub Profile
@tarleb
tarleb / list-formats.lua
Last active April 26, 2024 14:55
list-formats.lua
--- Lists the formats that support all the extensions given on the command line.
--
-- Usage:
--
-- pandoc lua list-formats.lua [extensions,...]
--
-- Example:
--
-- $ pandoc lua list-formats.lua native_numbering citations
-- docx
@tarleb
tarleb / sentence.lua
Created October 29, 2022 15:05
One sentece per line
local function sentence_lines (el)
local inlines = el.content
for i = 2, #inlines do
if inlines[i].t == 'Space' and
inlines[i-1].t == 'Str' and
inlines[i-1].text:match '%.$' then
inlines[i] = pandoc.SoftBreak()
end
end
return el
@tarleb
tarleb / highlight.lua
Created July 15, 2022 12:54
Custom syntax extension
--[[
Add support for a custom inline syntax.
This pandoc Lua filter allows to add a custom markup syntax
extension. It is designed to be adjustable; it should not be
necessary to modify the code below the separator line.
The example here allows to add highlighted text by enclosing the
text with `==` on each side. Pandoc supports this for HTML output
out of the box. Other outputs will need additional filters.
@tarleb
tarleb / interactive.lua
Last active October 21, 2022 11:02
Helper function for interactive Lua filters
function interactive (it, env)
local has_readline, RL = pcall(require, 'readline')
if not has_readline then
RL = {
readline = function (prompt)
io.stdout:write(prompt)
return io.read()
end
}
@tarleb
tarleb / toc.lua
Created February 10, 2022 19:55
Adaptable Lua filter to generate a Table of Contents
-- Generate a Table of Contents.
--
-- This is an adaption of the Haskell code used in pandoc. This script
-- is intended to be adapted to specific requirements before use. E.g.,
-- it can be modified to add additional elements as TOC items, to add
-- more info to each line in the TOC, or to control whether the heading
-- number is included in the link.
local PANDOC_WRITER_OPTIONS = PANDOC_WRITER_OPTIONS
_ENV = pandoc
@tarleb
tarleb / custom-markdown.lua
Last active June 27, 2023 23:55
Custom Lua writer, using the `layout` module to produce nicely layed-out Markdown.
-- This is a sample custom writer for pandoc, using Layout to
-- produce nicely wrapped output.
local layout = pandoc.layout
local text = pandoc.text
local type = pandoc.utils.type
local l = layout.literal
-- Table to store footnotes, so they can be included at the end.
@tarleb
tarleb / image-extension.lua
Last active December 20, 2020 18:23
Add file extension to images
local known_exts = pandoc.List{".png", ".jpg", "jpeg"}
if FORMAT:match 'tex' then
known_exts = pandoc.List {
".pdf", ".png", ".jpg", ".mps", ".jpeg", ".jbig2", ".jb2"
}
elseif FORMAT:match 'html' then
known_exts = pandoc.List {
".svg", ".png", ".jpg", ".jpeg", ".webp", ".gif"
}
end
@tarleb
tarleb / latex-logo.lua
Last active April 8, 2021 10:33
Lua filter to render TeX and LaTeX as logos like the \TeX and \LaTeX{} macros do.
-- Render TeX and LaTeX like the `\TeX` and `\LaTeX{}` macros do.
-- Copyright © 2020 Albert Krewinkel <albert+pandoc@zeitkraut.de>
-- License: MIT License
-- Style inspired by https://tess.oconnor.cx/2007/08/tex-poshlet
local style = pandoc.RawBlock('html', [[
<style>
.tex-logo sub, .latex-logo sub {
font-size: 100%;
margin-left: -0.1667em;
local List = require 'pandoc.List'
local meta
function merge_meta(m1, m2)
local result = m1
for k, v in pairs(m2) do
if result[k] == nil then
result[k] = v
end
@tarleb
tarleb / org-header-beautification.lua
Last active August 16, 2020 20:30
No-id org headers
-- Licensed, at your choice, under the MIT or GPL-2-or-later license
local header_ids = {}
local function collect_id (header)
if header.identifier and header.identifier ~= "" then
header_ids[header.identifier] = header.content
header.identifier = ""
return header
end
end