Skip to content

Commit

Permalink
docs: script to convert HTML manual pages to markdown
Browse files Browse the repository at this point in the history
Script to convert recursively all .html files to .md (GitHub flavoured Markdown).

(see related OSGeo#3849)
  • Loading branch information
neteler committed Oct 31, 2024
1 parent 528763f commit cbb2324
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
42 changes: 42 additions & 0 deletions utils/grass_html2md.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
set -eu

###############################################################################
# Convert recursively all .html files to .md (GitHub flavoured Markdown)
#
# Dependencies:
# pandoc
# wget
#
# Author(s):
# Martin Landa, Markus Neteler
#
# Usage:
# If you have "pandoc" in PATH, execute for HTML file conversion in
# current directory and subdirectories:
# ./utils/grass_html2md.sh
#
# COPYRIGHT: (C) 2024 by the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
###############################################################################

# define $TMP if not present
if test -z "${TMP}" ; then
TMP="/tmp"
fi

# TODO: path to LUA file setting to be improved (./utils/pandoc_codeblock.lua)
#wget https://raw.githubusercontent.com/OSGeo/grass/refs/heads/main/utils/pandoc_codeblock.lua -O "${TMP}/pandoc_codeblock.lua"
TMP="utils"

# run recursively: HTML to MD
for f in `find . -name *.html`; do
echo "${f}"
cat "${f}" | sed 's#<div class="code"><pre>#<pre><code>#g' | sed 's#</pre></div>#</code></pre>#g' | pandoc \
--from=html --to=markdown -t gfm --lua-filter "${TMP}/pandoc_codeblock.lua" | \
sed 's+ $++g' | sed 's+\.html)+\.md)+g' > "${f%%.html}.md"
done
8 changes: 8 additions & 0 deletions utils/pandoc_codeblock.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- Pandoc Lua filter to handle code blocks
-- Test cases
-- raster/r.sun/r.sun.html

-- Function to convert code blocks to markdown
function CodeBlock (cb)
return pandoc.RawBlock('markdown', '```bash\n' .. cb.text .. '\n```\n')
end

0 comments on commit cbb2324

Please sign in to comment.