#!/bin/bash # file: gsl__do_commons # Folder: /var/lib/gsl/scripts # By echolib # License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007 #======================================================================= # Get NEEDED DATAS from HEADERS #======================================================================= gsl__get_needed_headers() { gsl_post_type=`gsl__get_header "$gsl_marker_type" "$gsl_post"` gsl_header_title=`gsl__get_header "$gsl_marker_title" "$gsl_post"` gsl_header_slug=`gsl__get_header "$gsl_marker_slug" "$gsl_post"` gsl_header_author=`gsl__get_header "$gsl_marker_author" "$gsl_post"` gsl_header_date=`gsl__get_header "$gsl_marker_date" "$gsl_post"` gsl_header_info=`gsl__get_header "$gsl_marker_info" "$gsl_post"` gsl_header_tags=`gsl__get_header "$gsl_marker_tags" "$gsl_post"` } #====================================================================== # Check | Make in Loop from header datas $1: process $2:marker $3:file #====================================================================== gsl__do_header() { while read -r "gsl_header_content_line" do gsl__get_header_fields "$2" case "$1" in check) case "$2" in "$gsl_marker_link") gsl__check_link ;; "$gsl_marker_abbr") gsl__check_abbr ;; "$gsl_marker_file") gsl__check_file ;; "$gsl_marker_image") gsl__check_image ;; "$gsl_marker_code") gsl__check_fcode ;; esac ;; make) case "$2" in "$gsl_marker_link") gsl__make_link ;; "$gsl_marker_abbr") gsl__make_abbr ;; "$gsl_marker_image") gsl__make_image ;; esac ;; esac done < <(gsl__get_header "$2" "$3") } #====================================================================== # Do Strongs && Bolds + Get STATS | $1: Process $2:File #====================================================================== gsl__do_strongs_bolds() { case "$1" in "stats") gsl_stat_strongs=0 gsl_stat_bolds=0 ;; esac while read -r "strong" do if [[ "$strong" ]] && \ [[ `grep "$gsl_mark_strong$strong$gsl_mark_strong" "$2"` ]];then case "$1" in "stats") ((gsl_stat_strongs++)) ;; "make") # Check if in Inline-Code [[ `awk -v l="$n" 'NR == l' "$2" \ | grep -oP "(?<=$gsl_mark_code).*?(?=$gsl_mark_code)"` \ =~ "$strong" ]] \ && continue echo -ne "\r\033[2K: Converting Strong... $strong" gsl_strong="$gsl_mark_strong$strong$gsl_mark_strong" gsl_html_strong="$strong" sed -i "s|$gsl_strong|$gsl_html_strong|g" "$2" ;; esac fi done < <(grep -oP "(?<=$gsl_mark_strong).*?(?=$gsl_mark_strong)" "$2") # Bolds while IFS=: read -r "n" "bold" do if [[ "$bold" ]] && \ [[ `grep "$gsl_mark_bold$bold$gsl_mark_bold" "$2"` ]];then case "$1" in "stats") ((gsl_stat_bolds++)) echo -ne "\r\033[2K: Counting Bolds... $gsl_stat_bolds" ;; "make") gsl_bold="$gsl_mark_bold$bold$gsl_mark_bold" # Check if in Inline-Code [[ `awk -v l="$n" 'NR == l' "$2" \ | grep -oP "(?<=$gsl_mark_code).*?(?=$gsl_mark_code)"` \ =~ "$bold" ]] \ && continue echo -ne "\r\033[2K: Converting Bold... Line $n: $bold" gsl_html_bold="$bold" sed -i "s|$gsl_bold|$gsl_html_bold|g" "$2" ;; esac fi done < <(grep -oPn "(?<=$gsl_mark_bold).*?(?=$gsl_mark_bold)" "$2") case "$1" in "stats") gsl_stat_bolds=$((gsl_stat_bolds - gsl_stat_strongs)) ;; esac } #====================================================================== # Do Italics + Get STATS | $1: Process $2:File #====================================================================== gsl__do_italics() { gsl_stat_italics=0 while IFS=: read -r "n" "italic" do [[ `awk -v l="$n" 'NR == l && $1 ~ "link"' "$2"` ]] \ && continue if [[ "$italic" ]] && \ [[ `grep "$gsl_mark_italic$italic$gsl_mark_italic" "$2"` ]];then case "$1" in "stats") ((gsl_stat_italics++)) ;; "make") # Check if in Inline-Code [[ `awk -v l="$n" 'NR == l' "$2" \ | grep -oP "(?<=$gsl_mark_code).*?(?=$gsl_mark_code)"` \ =~ "$italic" ]] \ && continue this_word=` awk -v l="$n" 'NR == l' "$2" \ | grep -o "[^[:space:]]*$italic[^[:space:]]*"` case "$this_word" in "_http"*) continue ;; esac gsl_italic="$gsl_mark_italic$italic$gsl_mark_italic" gsl_html_italic="$italic" echo -ne "\r\033[2K: Converting Italic... $italic" sed -i "s|$gsl_italic|$gsl_html_italic|g" "$2" ;; esac fi done < <(grep -oPn "(?<=$gsl_mark_italic).*?(?=$gsl_mark_italic)" "$2") } #====================================================================== # Do Italics + Get STATS | $1: Process $2:File #====================================================================== gsl__do_icode() { gsl_stat_icode=0 case "$1" in "stats") gsl_mark_icode=`grep -o "$gsl_mark_code" "$2" | wc -l` gsl_stat_icode=$(( gsl_mark_icode / 2 )) ;; "make") gsl_html_icode_o="" gsl_html_icode_c="" while IFS=: read -r "n" "line" do unset gsl_icode_open for i in $(seq 1 ${#line}) do case "${line:i-1:1}" in "$gsl_mark_code") [[ "$gsl_icode_open" ]] \ && gsl_html_line+="$gsl_html_icode_c" \ && unset gsl_icode_open && continue gsl_icode_open=true gsl_html_line+="$gsl_html_icode_o" ;; *) gsl_html_line+="${line:i-1:1}" ;; esac done echo -ne "\r\033[2K: Converting inline-codes..." sed -i "${n}d" "$2" sed -i "${n}i$gsl_html_line" "$2" unset gsl_html_line done < <(grep -n "$gsl_mark_code" "$2") ;; esac }