cfenollosa / bashblog

A single Bash script to create blogs. Download, run, write, done!
1.65k stars 226 forks source link

markdown mode seems to be broken #165

Closed DjangoReinhard closed 2 years ago

DjangoReinhard commented 3 years ago

Hi,

I just tried you script and whatever I write, it always publishes the default content generated from script. So I started the script with xtrace option and save the output to a logfile. The log shows, that a markdown-file is used for editing, but then the html-file gets parsed without generating html-content from markdown:

------------------------------------------------------------------------------
+ /usr/bin/gvim .entry-13276.md
------------------------------------------------------------------------------

+ [[ md == md ]]
++ markdown .entry-13276.md
++ out=.entry-13276.html
++ [[ -f .entry-13276.html ]]
++ /usr/bin/markdown .entry-13276.md
++ echo .entry-13276.html
+ html_from_md=.entry-13276.html
+ parse_file .entry-13276.html
+ title=
+ IFS=
+ read -r line
+ [[ -z '' ]]
++ echo '<p>Title on this line</p>'
++ sed 's/<\/*p>//g'
+ title='Title on this line'
+ [[ -n '' ]]
+ filename='Title on this line'
+ [[ -n iconv -f utf-8 -t ascii//translit | sed 's/^-*//' | tr [:upper:] [:lower:] | tr ' ' '-' | tr -dc '[:alnum:]-' ]]
++ echo 'Title on this line'
++ eval 'iconv -f utf-8 -t ascii//translit | sed '\''s/^-*//'\'' | tr [:upper:] [:lower:] | tr '\'' '\'' '\''-'\'' | tr -dc '\''[:alnum:]-'\'''
+++ sed 's/^-*//'
+++ tr ' ' -
+++ tr '[:upper:]' '[:lower:]'
+++ iconv -f utf-8 -t ascii//translit
+++ tr -dc '[:alnum:]-'
+ filename=title-on-this-line

excerpt from script is this (line 598ff):

        $EDITOR "$TMPFILE"
        if [[ $fmt == md ]]; then
            html_from_md=$(markdown "$TMPFILE")
            parse_file "$html_from_md"
            rm "$html_from_md"
        else
            parse_file "$TMPFILE" # this command sets $filename as the html processed file
        fi

testing markdown on commandline shows, that markdown prints the converted html to stdout. So I guess, markdown line is missing some content-redirection into html-file.

DjangoReinhard commented 3 years ago

Hi,

found the bug on my own. Its caused by gvim, which does not block the commandline during editing. So html-file will be generated before editing starts.

A possible fix might be, to move lines 611 + 612 up directly after the editor call (original position is commented out):

    filename=""
    while [[ $post_status != "p" && $post_status != "P" ]]; do
        [[ -n $filename ]] && rm "$filename" # Delete the generated html file, if any
        $EDITOR "$TMPFILE"
        echo -n "[P]ost this entry, [E]dit again, [D]raft for later? (p/E/d) "
        read -r post_status
        if [[ $fmt == md ]]; then
            html_from_md=$(markdown "$TMPFILE")
            parse_file "$html_from_md"
            rm "$html_from_md"
        else
            parse_file "$TMPFILE" # this command sets $filename as the html processed file
        fi

        chmod 644 "$filename"
        [[ -n $preview_url ]] || preview_url=$global_url
        echo "To preview the entry, open $preview_url/$filename in your browser"

#        echo -n "[P]ost this entry, [E]dit again, [D]raft for later? (p/E/d) "
#        read -r post_status
        if [[ $post_status == d || $post_status == D ]]; then
            mkdir -p "drafts/"
ronjakoi commented 3 years ago

Set your $EDITOR to gvim -f so the editor stays on the foreground in the shell.