fixes false positive on markdown script
This commit is contained in:
parent
1226e78561
commit
d0e7d60d93
32
bb.sh
32
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=$'<p>line 1</p>\n\n<p>line 2</p>'
|
||||
local c2=$'<p>line 1</p>\n<p>line 2</p>'
|
||||
# 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=$'<p>line 1</p>\n\n<p>line 2</p>'
|
||||
local c2=$'<p>line 1</p>\n<p>line 2</p>'
|
||||
# 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
|
||||
|
|
Loading…
Reference in New Issue