-
-
Save jhartikainen/da3111d829edded15e0b019705bcfe01 to your computer and use it in GitHub Desktop.
filter.lua
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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