From d0e7d60d939db2871c74ccdc180df55d714d4781 Mon Sep 17 00:00:00 2001 From: James Tomasino Date: Wed, 28 Oct 2020 22:58:04 +0000 Subject: [PATCH] fixes false positive on markdown script --- bb.sh | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/bb.sh b/bb.sh index 304b17f..73c86b6 100755 --- a/bb.sh +++ b/bb.sh @@ -150,7 +150,15 @@ global_variables() { # 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=$(command -v Markdown.pl 2>/dev/null || command -v markdown 2>/dev/null) + + if [[ -f "./Markdown.pl" ]]; then + markdown_bin="./Markdown.pl" + else + markdown_bin=$(command -v Markdown.pl 2>/dev/null) + if [ -z "$markdown_bin" ]; then + markdown_bin=$(command -v markdown 2>/dev/null) + fi + fi } # Check for the validity of some variables @@ -167,17 +175,21 @@ global_variables_check() { # Test if the markdown script is working correctly test_markdown() { - local m1; m1=$("$markdown_bin" <<< $'line 1\n\nline 2') - local m2; m2=$("$markdown_bin" <<< $'line 1\n\nline 2') - local c1=$'

line 1

\n\n

line 2

' - local c2=$'

line 1

\n

line 2

' - # shellcheck disable=SC2235 # must enforce order of operations - [[ -n $markdown_bin ]] && ( [[ "$m1" == "$c1" ]] || [[ "$m2" == "$c2" ]] ) + if [[ -n $markdown_bin ]]; then + local m1; m1=$("$markdown_bin" <<< $'line 1\n\nline 2') + local m2; m2=$("$markdown_bin" <<< $'line 1\n\nline 2') + local c1=$'

line 1

\n\n

line 2

' + local c2=$'

line 1

\n

line 2

' + # shellcheck disable=SC2235 # must enforce order of operations + [[ "$m1" == "$c1" ]] || [[ "$m2" == "$c2" ]] + else + return 1 + fi } # Parse a Markdown file into HTML and return the generated file -markdown() { +mrkdwn() { out=${1%.md}.html while [[ -f $out ]]; do out=${out%.html}.$RANDOM.html; done $markdown_bin "$1" > "$out" @@ -233,7 +245,7 @@ edit() { fi # editing markdown file $EDITOR "$1" - TMPFILE=$(markdown "$1") + TMPFILE=$(mrkdwn "$1") filename=${1%%.*}.html else # Create the content file @@ -518,7 +530,7 @@ EOF [[ -n $filename ]] && rm "$filename" # Delete the generated html file, if any $EDITOR "$TMPFILE" if [[ $fmt == md ]]; then - html_from_md=$(markdown "$TMPFILE") + html_from_md=$(mrkdwn "$TMPFILE") parse_file "$html_from_md" rm "$html_from_md" else