Adds the ability to convert to html
Issue #14 I still want, at some point, to add to other formats but this is fine for now. The tool uses pandoc to do the conversion from md to html A sample template (without any styling) is provided. This can be overwritten in $HOME/.config/kb/templates/main.html or in the knowledgebase directory under `templates`.
This commit is contained in:
parent
4c891efdce
commit
7d554d5326
4 changed files with 47 additions and 3 deletions
28
inc/to-html
28
inc/to-html
|
@ -31,6 +31,30 @@ generate-html-toc(){
|
|||
|
||||
to-html(){
|
||||
local destination="$1"
|
||||
local toc="$(generate-html-toc)"
|
||||
echo "$toc"
|
||||
local preTemplate="/usr/local/share/kb/templates/main.html"
|
||||
local tocFile="$(mktemp)"
|
||||
local templateFile="$(mktemp)"
|
||||
generate-html-toc > "$tocFile"
|
||||
|
||||
# If there is a template in the users .local/share directory, use that
|
||||
[ -e "${XDG_CONFIG_HOME:-$HOME/.config}/kb/templates/main.html" ] &&
|
||||
preTemplate="${XDG_CONFIG_HOME:-$HOME/.config}/kb/templates/main.html"
|
||||
|
||||
# If there is a template in the data directory, use that
|
||||
[ -e "${dataDir}templates/main.html" ] &&
|
||||
preTemplate="${dataDir}templates/main.html"
|
||||
|
||||
|
||||
sed "s#\#TOC\##\${ $tocFile() }#" "$preTemplate" > "$templateFile"
|
||||
|
||||
|
||||
find "$dataDir" -name "*.md" | while read file; do
|
||||
local newFile="${file##*/}"
|
||||
newFile="${newFile/.md/.html}"
|
||||
sed -E 's/\.md( *)\)/.html\1\)/' "$file" |
|
||||
pandoc -f markdown -t html --template "$templateFile" > "$destination/$newFile"
|
||||
done
|
||||
|
||||
rm "$tocFile" "$templateFile"
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue