Added Block-Code Converter from file ; marker _code:X

This commit is contained in:
Cyrille L 2022-03-05 19:25:04 +01:00
parent 5bb8298d67
commit df5ad8cf4e
2 changed files with 67 additions and 100 deletions

View File

@ -91,7 +91,7 @@ gsl_log_c_file="Content File"
gsl_mo_p='(' gsl_mo_p='('
gsl_mc_p=')' gsl_mc_p=')'
gsl_mark_image='_image' gsl_mark_image='_image'
gsl_mark_code='_code' gsl_mark_fcode='_code'
gsl_mark_title='#' gsl_mark_title='#'
gsl_mark_bold='\*' gsl_mark_bold='\*'
gsl_mark_strong='\*\*' gsl_mark_strong='\*\*'

View File

@ -36,10 +36,7 @@ gsl_ct=0 && gsl__make_titles_div_open
gsl_ct=0 && gsl__make_titles_div_close gsl_ct=0 && gsl__make_titles_div_close
gsl__do_header "make" "$gsl_marker_image" "$gsl_post" gsl__do_header "make" "$gsl_marker_image" "$gsl_post"
gsl__make_paragraphs gsl__make_paragraphs
gsl__make_fcode
#echo -ne "\r\033[2K: Searching and converting Block-Codes..."
#gsl__check_bcodes
gsl__check_cites gsl__check_cites
gsl__make_a11y gsl__make_a11y
echo -ne "\r\033[2K" echo -ne "\r\033[2K"
@ -91,6 +88,46 @@ gsl__post_content_only
# Converters # Converters
# --------------------------------- # ---------------------------------
#======================================================================= #=======================================================================
#======================================================================
# Replace gsl_mark_fcode
#======================================================================
gsl__make_fcode() {
while IFS=: read -r "line" "mark" "nbr"
do
# Get File
gsl_file_fcode=`
grep "${gsl_marker_code}$nbr" "$gsl_post" \
| awk -F" : " '{print $2}'`
echo -ne "\r\033[2K: Converting Block-Codes... $gsl_file_fcode"
gsl_css_class="${gsl_site_css}_block-code"
# Create tmp file from block-code, adding span for line numbers in css
gsl_file_bcode=`mktemp`
while read -r "gsl_bcode_line"
do
echo "<span>$gsl_bcode_line</span>" >> "$gsl_file_bcode"
done < <(cat "$gsl_dir_domain_files/$gsl_file_fcode")
gsl_file_tmp_code=`mktemp`
printf '%s %s\n%b\n%s\n' \
"<pre class=\"$gsl_css_class" \
"${gsl_css_class}-$gsl_post_header_field_1\">" \
"$(cat "$gsl_file_bcode")" \
"</pre>" \
> "$gsl_file_tmp_code"
# Replace in tmp post and delete mark
sed -i "${line}r $gsl_file_tmp_code" "$gsl_tmp_post"
sed -i "${line}d" "$gsl_tmp_post"
rm -f "$gsl_file_tmp_code"
rm -f "$gsl_file_bcode"
done < <(grep -n "$gsl_mark_fcode" "$gsl_tmp_post")
}
#====================================================================== #======================================================================
# From gsl__do_header: Make Link # From gsl__do_header: Make Link
#====================================================================== #======================================================================
@ -131,67 +168,6 @@ gsl_html_long="<abbr title=\"$gsl_post_hf_2\">$gsl_post_hf_1</abbr>"
sed -i "s|$gsl_post_hf_1|$gsl_html_long|" "$gsl_tmp_post" sed -i "s|$gsl_post_hf_1|$gsl_html_long|" "$gsl_tmp_post"
} }
#=======================================================================
# Find BLOCK-CODES
#=======================================================================
gsl__check_bcodes() {
gsl_lines_nbr=(`
gsl__get_mark_content_line \
"$gsl_mark_code" \
"$gsl_tmp_post"`)
! [[ "$gsl_lines_nbr" ]] \
&& return
for i in `seq 1 ${#gsl_lines_nbr[@]}`
do
gsl__make_bcode
done
}
#=======================================================================
# Find BLOCKQUOTES
#=======================================================================
gsl__check_cites() {
echo -ne "\r\033[2K: Searching and converting Citations..."
unset gsl_lines_nbr
gsl_lines_nbr=(`
gsl__get_mark_content_line \
"$gsl_mark_blockquote" \
"$gsl_tmp_post"`)
gsl_lines_nbr=(${gsl_lines_nbr[0]} ${gsl_lines_nbr[1]})
! [[ "$gsl_lines_nbr" ]] \
&& return
for i in `seq 1 ${#gsl_lines_nbr[@]}`
do
if [[ "$gsl_cite_start" ]];then
unset gsl_cite_start
gsl_cite_line_stop=${gsl_lines_nbr[(($i-1))]}
gsl__make_cite
else
gsl_cite_start=true
gsl_cite_line_start=${gsl_lines_nbr[(($i-1))]}
fi
done
gsl__check_cites
}
#=======================================================================
# -----------------------------------------------
# Convert To HTML in duplicated CONTENT Post File
# -----------------------------------------------
#=======================================================================
#======================================================================= #=======================================================================
# Find and convert Titles #1-6 # Find and convert Titles #1-6
#======================================================================= #=======================================================================
@ -321,47 +297,38 @@ do
done < <(cat -n "$gsl_tmp_post") done < <(cat -n "$gsl_tmp_post")
} }
#-----------------------------------------------------------------------
#======================================================================= #=======================================================================
# Replace gsl_mark_code # Find BLOCKQUOTES
#======================================================================= #=======================================================================
gsl__make_bcode() { gsl__check_cites() {
# Get mark line nbr echo -ne "\r\033[2K: Searching and converting Citations..."
gsl_line_nbr=`
unset gsl_lines_nbr
gsl_lines_nbr=(`
gsl__get_mark_content_line \ gsl__get_mark_content_line \
"$gsl_mark_code" \ "$gsl_mark_blockquote" \
"$gsl_tmp_post" | head -1` "$gsl_tmp_post"`)
gsl_lines_nbr=(${gsl_lines_nbr[0]} ${gsl_lines_nbr[1]})
#---------
# Convert
#---------
gsl_css_class="${gsl_site_css}_block-code"
gsl_header_content_line=`gsl__get_header "$gsl_marker_code" "$gsl_post"`
gsl_file_tmp_code=`mktemp`
# Set gsl_post_header_field_1 gsl_post_header_field_2 ! [[ "$gsl_lines_nbr" ]] \
gsl__get_header_fields "$gsl_marker_code" && return
# Create tmp file from block-code, adding span to get number lines in css for i in `seq 1 ${#gsl_lines_nbr[@]}`
gsl_file_bcode=`mktemp` do
while read -r "gsl_bcode_line" if [[ "$gsl_cite_start" ]];then
do unset gsl_cite_start
echo "<span>$gsl_bcode_line</span>" >> "$gsl_file_bcode" gsl_cite_line_stop=${gsl_lines_nbr[(($i-1))]}
done < <(cat "$gsl_dir_domain_files/$gsl_post_header_field_2") gsl__make_cite
else
printf '%s %s\n%b\n%s\n' \ gsl_cite_start=true
"<pre class=\"$gsl_css_class" \ gsl_cite_line_start=${gsl_lines_nbr[(($i-1))]}
"${gsl_css_class}-$gsl_post_header_field_1\">" \ fi
"$(cat "$gsl_file_bcode")" \ done
"</pre>" \ gsl__check_cites
> "$gsl_file_tmp_code"
sed -i "${gsl_line_nbr}r $gsl_file_tmp_code" "$gsl_tmp_post"
sed -i "${gsl_line_nbr}d" "$gsl_tmp_post"
rm -f "$gsl_file_tmp_code"
rm -f "$gsl_file_bcode"
} }
#-----------------------------------------------------------------------
#======================================================================= #=======================================================================
# Replace and Convert this blockquote # Replace and Convert this blockquote
#======================================================================= #=======================================================================