--[=====================================================================[ Get [[...]] style wiki links in Pandoc Markdown output: [PAGE NAME]() becomes [[PAGE NAME]] (Formatting is lost) [FORMATTED TEXT]{wiki="PAGE NAME"} becomes [[PAGE NAME|FORMATTED TEXT]] `TEXT`{.wiki} becomes [[TEXT]] (Very fast!) $ pandoc --lua-filter wiki-links.lua -w gfm [foo]() [*bar*]{wiki="baz"} `quux`{.wiki} ^D [[foo]] [[baz|*bar*]] [[quux]] --]=====================================================================] local wiki_class = "wiki" -- feel free to change this to e.g. "w" function Link (elem) if "" == elem.target then local text = pandoc.utils.stringify(elem) return { pandoc.RawInline('markdown', '[[' .. text .. ']]' ) } end return nil end function Code (elem) if elem.classes:includes(wiki_class) then return { pandoc.RawInline('markdown', '[[' .. elem.text .. ']]') } end return nil end function Span (elem) local wiki = elem.attributes[wiki_class] if wiki then -- construct the part before the formatted text prefix = pandoc.RawInline('markdown', '[[' .. wiki .. '|') -- the part after the formatted text suffix = pandoc.RawInline('markdown', ']]') -- the formatted text == the span content local content = elem.content -- prepend the prefix table.insert(content, 1, prefix) -- append the suffix most efficiently content[#content+1] = suffix return content end return nil end --[=====================================================================[ This software is Copyright (c) 2019 by Benct Philip Jonsson. This is free software, licensed under: The MIT (X11) License The MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --]=====================================================================] -- Vim: set ft=lua sw=2 sts=2 et fdm=indent: