Changed pandoc funcionality from commonmark to reStructuredText for possible table and other functionality. Changed Footer blurb on line 980

This commit is contained in:
PresGas 2021-06-28 20:59:05 -04:00
parent 7c2024e3bc
commit 905cc4db8b
1 changed files with 30 additions and 30 deletions

60
bb.sh
View File

@ -81,15 +81,15 @@ global_variables() {
blog_feed="feed.rss"
number_of_feed_articles="10"
# "cut" blog entry when putting it to index page. Leave blank for full articles in front page
# i.e. include only up to first '<hr>', or '----' in commonmark
# i.e. include only up to first '<hr>', or '----' in rst
cut_do=""
# When cutting, cut also tags? If "no", tags will appear in index page for cut articles
cut_tags="yes"
# Regexp matching the HTML line where to do the cut
# note that slash is regexp separator so you need to prepend it with backslash
cut_line='<hr ?\/?>'
# save commonmark file when posting with "bb post -m". Leave blank to discard it.
save_commonmark="yes"
# save rst file when posting with "bb post -m". Leave blank to discard it.
save_rst="yes"
# prefix for tags/categories files
# please make sure that no other html file starts with this prefix
prefix_tags="tag_"
@ -165,7 +165,7 @@ global_variables() {
# pandoc location.
pandoc_bin=$(which pandoc 2>/dev/null)
# pandoc command
pandoc_command="$pandoc_bin -f commonmark -t html"
pandoc_command="$pandoc_bin -f rst -t html"
# Markdown location. Trying to autodetect by default.
# The invocation must support the signature 'markdown_bin in.md > out.html'
#[[ -f Markdown.pl ]] && markdown_bin=./Markdown.pl || markdown_bin=$(which Markdown.pl 2>/dev/null || which markdown 2>/dev/null)
@ -202,9 +202,9 @@ test_pandoc() {
}
# Parse a Commonmark Markdown file into HTML and return the generated file
commonmark() {
out=${1%.md}.html
# Parse a reStructuredText file into HTML and return the generated file
rst() {
out=${1%.rst}.html
while [[ -f $out ]]; do out=${out%.html}.$RANDOM.html; done
$pandoc_command "$1" > "$out"
echo "$out"
@ -294,7 +294,7 @@ get_html_file_content() {
# Please note that this function does not automatically republish anything, as
# it is usually called from 'main'.
#
# Note that it edits HTML file, even if you wrote the post as commonmark originally
# Note that it edits HTML file, even if you wrote the post as reStructuredText originally
# Note that if you edit title then filename might also change
#
# $1 the file to edit
@ -312,15 +312,15 @@ edit() {
$EDITOR "$1"
filename=$1
else
if [[ ${1##*.} == md ]]; then
if [[ ${1##*.} == rst ]]; then
test_pandoc
if (($? != 0)); then
echo "pandoc is not working, please edit HTML file directly."
exit
fi
# editing commonmark file
# editing reStructuredText file
$EDITOR "$1"
TMPFILE=$(commonmark "$1")
TMPFILE=$(rst "$1")
filename=${1%%.*}.html
else
# Create the content file
@ -337,7 +337,7 @@ edit() {
parse_file "$TMPFILE" "$edit_timestamp" "$filename"
else
parse_file "$TMPFILE" "$edit_timestamp" # this command sets $filename as the html processed file
[[ ${1##*.} == md ]] && mv "$1" "${filename%%.*}.md" 2>/dev/null
[[ ${1##*.} == rst ]] && mv "$1" "${filename%%.*}.rst" 2>/dev/null
fi
rm "$TMPFILE"
fi
@ -471,7 +471,7 @@ create_html_page() {
if [[ $index == no ]]; then
echo '<!-- entry begin -->' # marks the beginning of the whole post
echo "<h3><a class=\"ablack\" href=\"$file_url\">"
# remove possible <p>'s on the title because of commonmark markdown conversion
# remove possible <p>'s on the title because of reStructuredText conversion
title=${title//<p>/}
title=${title//<\/p>/}
echo "$title"
@ -568,7 +568,7 @@ parse_file() {
# Manages the creation of the text file and the parsing to html file
# also the drafts
write_entry() {
test_pandoc && fmt=md || fmt=html
test_pandoc && fmt=rst || fmt=html
f=$2
[[ $2 == -html ]] && fmt=html && f=$3
@ -581,11 +581,11 @@ write_entry() {
fi
# guess format from TMPFILE
extension=${TMPFILE##*.}
[[ $extension == md || $extension == html ]] && fmt=$extension
# but let user override it (`bb.sh post -html file.md`)
[[ $extension == rst || $extension == html ]] && fmt=$extension
# but let user override it (`bb.sh post -html file.rst`)
[[ $2 == -html ]] && fmt=html
# Test if pandoc is working before re-posting a .md file
if [[ $extension == md ]]; then
# Test if pandoc is working before re-posting a .rst file
if [[ $extension == rst ]]; then
test_pandoc
if (($? != 0)); then
echo "pandoc is not working, please edit HTML file directly."
@ -602,8 +602,8 @@ as you exit your editor.</p>
<p>$template_tags_line_header keep-this-tag-format, tags-are-optional, example</p>
EOF
[[ $fmt == md ]] && cat << EOF >> "$TMPFILE"
The rest of the text file is a **Commonmark Markdown** blog post. The process will continue
[[ $fmt == rst ]] && cat << EOF >> "$TMPFILE"
The rest of the text file is a **reStructuredText** blog post. The process will continue
as soon as you exit your editor.
$template_tags_line_header keep-this-tag-format, tags-are-optional, beware-with-underscores-in-markdown, example
@ -616,10 +616,10 @@ EOF
while [[ $post_status != "p" && $post_status != "P" ]]; do
[[ -n $filename ]] && rm "$filename" # Delete the generated html file, if any
$EDITOR "$TMPFILE"
if [[ $fmt == md ]]; then
html_from_md=$(commonmark "$TMPFILE")
parse_file "$html_from_md"
rm "$html_from_md"
if [[ $fmt == rst ]]; then
html_from_rst=$(rst "$TMPFILE")
parse_file "$html_from_rst"
rm "$html_from_rst"
else
parse_file "$TMPFILE" # this command sets $filename as the html processed file
fi
@ -648,8 +648,8 @@ EOF
fi
done
if [[ $fmt == md && -n $save_commonmark ]]; then
mv "$TMPFILE" "${filename%%.*}.md"
if [[ $fmt == rst && -n $save_rst ]]; then
mv "$TMPFILE" "${filename%%.*}.rst"
else
rm "$TMPFILE"
fi
@ -977,7 +977,7 @@ create_includes() {
protected_mail=${global_email//@/&#64;}
protected_mail=${protected_mail//./&#46;}
echo "<div id=\"footer\">$global_license <a href=\"$global_author_url\">$global_author</a> &mdash; <a href=\"mailto:$protected_mail\">$protected_mail</a><br/>"
echo 'Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>'
echo 'Generated with <a href="https://git.disroot.org/PresGas/bashblog-unbound">bashblog-unbound</a>.</div>'
} >> ".footer.html"
fi
}
@ -1074,9 +1074,9 @@ usage() {
echo ""
echo "Commands:"
echo " post [-html] [filename] insert a new blog post, or the filename of a draft to continue editing it"
echo " it tries to use pandoc commonmark markdown by default, and falls back to HTML if it's not available."
echo " it tries to use pandoc reStructuredText by default, and falls back to HTML if it's not available."
echo " use '-html' to override it and edit the post as HTML even when pandoc is available"
echo " edit [-n|-f] [filename] edit an already published .html or .md file. **NEVER** edit manually a published .html file,"
echo " edit [-n|-f] [filename] edit an already published .html or .rst file. **NEVER** edit manually a published .html file,"
echo " always use this function as it keeps internal data and rebuilds the blog"
echo " use '-n' to give the file a new name, if title was changed"
echo " use '-f' to edit full html file, instead of just text part (also preserves name)"
@ -1161,7 +1161,7 @@ do_main() {
if [[ $1 == edit ]]; then
if (($# < 2)) || [[ ! -f ${!#} ]]; then
echo "Please enter a valid .md or .html file to edit"
echo "Please enter a valid .rst or .html file to edit"
exit
fi
fi