Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
Created April 25, 2026 16:00
Show Gist options
  • Select an option

  • Save jhartikainen/da3111d829edded15e0b019705bcfe01 to your computer and use it in GitHub Desktop.

Select an option

Save jhartikainen/da3111d829edded15e0b019705bcfe01 to your computer and use it in GitHub Desktop.
filter.lua
function CodeBlock(el)
if FORMAT == 'markdown' and #el.classes == 0 then
return pandoc.RawBlock("markdown", "```\n" .. el.text .. "\n```")
end
end
function Link(el)
-- Replace internal post links with wikilinks
str_pos, str_end = string.find(el.target, "codeutopia.net/%d%d%d%d/%d%d/%d%d/")
if str_pos then
str = string.sub(el.target, str_end + 1)
-- md conversions currently use spaces in filenames instead of dashes
str = string.gsub(str, "-", " ")
-- there could be an ending / at the end of the link
str = string.gsub(str, "/", "")
link_text = pandoc.utils.stringify(el.content)
if str ~= link_text then
-- Include link text if it doesn't match the name of the file
str = str .. "|" .. link_text
end
return pandoc.RawInline("markdown", "[[" .. str .. "]]")
end
return nil
end
local lowest_heading = 999
function Header(head)
lowest_heading = math.min(head.level, lowest_heading)
end
local function fix_headers(head)
head.level = head.level - lowest_heading + 1
return head
end
function Pandoc(doc)
-- Fix headers to start from h1 instead of whatever they do now
doc = doc:walk { Header = fix_headers }
return doc
end
function Meta(meta)
-- reformat frontmatter
meta.aliases = { meta.title }
meta.title = nil
-- Used by Hakyll
meta.published = meta.date
-- don't have a better way to identify creation date so we'll just go with this
meta.created = meta.date
return meta
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment