Skip to content

Commit

Permalink
Translate help links using a pandoc Lua filter instead of sed
Browse files Browse the repository at this point in the history
Using a pandoc filter is more reliable - it ensures that only links
are rewritten, and not other parts of the text that look like a link
but aren't actually one.
  • Loading branch information
dgelessus committed Feb 10, 2020
1 parent 27e5900 commit dccf0ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ convert_single() {
echo "Converting ${file} to ${format} (.${extension})..."

rm -f "${file}.${extension}"
pandoc "${file}" -f markdown_github -t "${format}" -s | sed "s/\.md/.${extension}/g" > "${file%.md}.${extension}"
pandoc "${file}" -f markdown_github -t "${format}" --lua-filter pandoc_links_to_html.lua -o "${file%.md}.${extension}"
}

if ! which pandoc &> /dev/null; then
echo "pandoc is not installed. Aborting..."
exit 1
elif ! which sed &> /dev/null; then
echo "sed is not installed. Aborting..."
exit 1
fi

find src/main/resources/help -name "*.md" -print0 | while IFS="" read -r -d "" file; do
Expand Down
11 changes: 11 additions & 0 deletions pandoc_links_to_html.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Based on https://stackoverflow.com/a/49396058 (CC-BY-SA 4.0)

local extensions_by_format = {
["html"] = ".html",
["asciidoc"] = ".adoc",
}

function Link(el)
el.target = string.gsub(el.target, "%.md", extensions_by_format[FORMAT])
return el
end

0 comments on commit dccf0ee

Please sign in to comment.