diff --git a/etc/gsl/gsl.conf b/etc/gsl/gsl.conf
index fb46f29..25a2d2a 100644
--- a/etc/gsl/gsl.conf
+++ b/etc/gsl/gsl.conf
@@ -89,26 +89,17 @@ gsl_log_c_file="Content File"
# Set CONTENT POST markers
#-----------------------------------------------------------------------
gsl_mo_p='('
-gsl_mo_link='\[_'
-gsl_mo_em='/_'
-gsl_mo_bold='\*_'
-gsl_mo_strong='\*\*_'
-gsl_mo_code='¤_'
-gsl_mo_file='<_'
-
gsl_mc_p=')'
-gsl_mc_link='_\]'
-gsl_mc_em='_/'
-gsl_mc_bold='_\*'
-gsl_mc_strong='_\*\*'
-gsl_mc_code='_¤'
-gsl_mc_file='_>'
-
gsl_mark_image='_image_'
gsl_mark_code='_code_'
gsl_mark_title='#'
+gsl_mark_bold='\*'
+gsl_mark_strong='\*\*'
+gsl_mark_italic='\/'
+gsl_mark_code="¤"
gsl_mark_list='='
+
gsl_mark_blockquote='---'
gsl_mark_blockquote_cite='_cite :'
gsl_mark_blockquote_year='_year :'
@@ -116,45 +107,6 @@ gsl_mark_blockquote_link='_link :'
gsl_mark_blockquote_book='_book :'
gsl_mark_blockquote_lang='_lang :'
-#-----------------------------------------------------------------------
-# Set for Stats
-#-----------------------------------------------------------------------
-gsl_o_markers=(
-$gsl_mo_link
-$gsl_mo_em
-$gsl_mo_strong
-$gsl_mo_bold
-$gsl_mo_code
-$gsl_mo_file
-)
-
-gsl_c_markers=(
-$gsl_mc_link
-$gsl_mc_em
-$gsl_mc_strong
-$gsl_mc_bold
-$gsl_mc_code
-$gsl_mc_file
-)
-
-gsl_i_markers=(
-"Content link"
-"Content italic"
-"Content strong"
-"Content bold"
-"Content code"
-"Content file"
-)
-
-gsl_u_markers=(
-'[_ _]'
-'/_ _/'
-'**_ _**'
-'*_ _*'
-'¤_ _¤'
-'<_ _>'
-)
-
#-----------------------------------------------------------------------
# Set HEADERS markers
#-----------------------------------------------------------------------
@@ -173,3 +125,6 @@ gsl_marker_image='image: '
gsl_marker_abbr='abbr: '
gsl_marker_link='link: '
gsl_marker_file='file: '
+
+# Delimiters to seet for sed in case exists in inline-code
+gsl_d=(\, \. \? \% \# \- \: \^ \/ \_ \| )
diff --git a/var/lib/gsl/README.md b/var/lib/gsl/README.md
index bc4e32c..deca4ea 100644
--- a/var/lib/gsl/README.md
+++ b/var/lib/gsl/README.md
@@ -167,8 +167,9 @@ For ABBRs, just write SHORT in your content
```
# Paragraphs
At begining of new line, open with ( and close with )
-(
-This is a paragraph
+Set till 3 different classes with ( 1 ( 2 ( 3
+( 2
+This is a paragraph with class 2
)
# Register in Header. link: My Great Link : URL : Alt text
@@ -194,10 +195,10 @@ this border**line** content
...
# Write in ITALIC
-/_this em text_/
+/this em text/
# Inline-code (¤ = alt-gr + $ on FR keyboard)
-¤_push()_¤
+¤push()¤
# Simple Blockquote
---
diff --git a/var/lib/gsl/helps/gsl_help_write_post b/var/lib/gsl/helps/gsl_help_write_post
index b0e0e49..b385433 100644
--- a/var/lib/gsl/helps/gsl_help_write_post
+++ b/var/lib/gsl/helps/gsl_help_write_post
@@ -52,12 +52,14 @@ For ABBRs, just write SHORT in your content
```
# Paragraphs
At begining of new line, open with ( and close with )
-(
-This is a paragraph
+Set till 3 different classes with ( 1 ( 2 ( 3
+( 2
+This is a paragraph with class 2
)
-# Register in Header. link: My Great link : URL : Alt text
+# Register in Header. link: My Great Link : URL : Alt text
_My Great Link
+_My Great Link+ # Open in new tab
# Register in Header. file: My Great file : FILENAME : ALT-TEXT
__My Great file
@@ -68,17 +70,20 @@ __image:1
# Block-Code File: Register in Header. code: 1 : FILENAME : Alt Text
__code:1
-# Write in ITALIC
-/_this em text_/
-
# Write in STRONG
-**_this strong content_**
+**this strong content**
+this un**believe**able content
+this border**line** content
# BOLD
-*_this bold content_*
+*this bold content*
+...
+
+# Write in ITALIC
+/this em text/
# Inline-code (¤ = alt-gr + $ on FR keyboard)
-¤_push()_¤
+¤push()¤
# Simple Blockquote
---
diff --git a/var/lib/gsl/scripts/gsl__do_commons b/var/lib/gsl/scripts/gsl__do_commons
index e97799f..ebdf22d 100644
--- a/var/lib/gsl/scripts/gsl__do_commons
+++ b/var/lib/gsl/scripts/gsl__do_commons
@@ -54,3 +54,154 @@ do
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
+ ;;
+
+ "make")
+ echo -ne "\r\033[2K: Convrting Strongs & Bolds..."
+ ;;
+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")
+ echo -ne "\r\033[2K: Convrting 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
+echo -ne "\r\033[2K: Counting Bolds..."
+while read -r "bold"
+do
+ if [[ "$bold" ]] && \
+ [[ `grep "$gsl_mark_bold$bold$gsl_mark_bold" "$2"` ]];then
+
+ case "$1" in
+ "stats")
+ ((gsl_stat_bolds++))
+ ;;
+ "make")
+ echo -ne "\r\033[2K: Convrting Bold... $bold"
+ gsl_bold="$gsl_mark_bold$bold$gsl_mark_bold"
+ gsl_html_bold="$bold"
+ sed -i "s|$gsl_bold|$gsl_html_bold|g" "$2"
+ ;;
+ esac
+
+ fi
+done < <(grep -oP "(?<=$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() {
+case "$1" in
+ "stats")
+ gsl_stat_italics=0
+ ;;
+
+ "make")
+ echo -ne "\r\033[2K: Convrting Italics..."
+ ;;
+esac
+
+echo -ne "\r\033[2K: Counting Italics..."
+while read -r "italic"
+do
+ if [[ "$italic" ]] && \
+ [[ `grep "$gsl_mark_italic$italic$gsl_mark_italic" "$2"` ]];then
+
+ case "$1" in
+ "stats")
+ ((gsl_stat_italics++))
+ ;;
+ "make")
+ echo -ne "\r\033[2K: Convrting Italic... $italic"
+ gsl_italic="$gsl_mark_italic$italic$gsl_mark_italic"
+ gsl_html_italic="$italic"
+ sed -i "s|$gsl_italic|$gsl_html_italic|g" "$2"
+ ;;
+
+ esac
+ fi
+done < <(grep -oP "(?<=$gsl_mark_italic).*?(?=$gsl_mark_italic)" "$2")
+}
+
+#======================================================================
+# Do Italics + Get STATS | $1: Process $2:File
+#======================================================================
+gsl__do_icode() {
+case "$1" in
+ "stats")
+ gsl_stat_icodes=0
+ ;;
+
+ "make")
+ gsl_html_icode_o=""
+ echo -ne "\r\033[2K: Convrting Inline-Codes..."
+ ;;
+esac
+
+echo -ne "\r\033[2K: Counting Inline-Codes..."
+while read -r "icode"
+do
+ if [[ "$icode" ]] && \
+ [[ `grep "$gsl_mark_code$icode$gsl_mark_code" "$2"` ]];then
+
+ case "$1" in
+ "stats")
+ ((gsl_stat_icodes++))
+ ;;
+ "make")
+ echo -ne "\r\033[2K: Convrting Inline-Code... $icode"
+ gsl_icode="$gsl_mark_code$icode$gsl_mark_code"
+ gsl_html_icode="$gsl_html_icode_o$icode
"
+
+ for d in "${gsl_d[@]}"
+ do
+ case "$icode" in
+ *"$d"*)
+ continue
+ ;;
+ *)
+ sed -i "s${d}${gsl_icode}${d}${gsl_html_icode}${d}" "$2"
+ break
+ ;;
+ esac
+ done
+
+ ;;
+ esac
+
+ fi
+done < <(grep -oP "(?<=$gsl_mark_code).*?(?=$gsl_mark_code)" "$2")
+}
diff --git a/var/lib/gsl/scripts/gsl__page_creator b/var/lib/gsl/scripts/gsl__page_creator
index 92eac2f..16976ef 100644
--- a/var/lib/gsl/scripts/gsl__page_creator
+++ b/var/lib/gsl/scripts/gsl__page_creator
@@ -10,6 +10,16 @@
# --------------------------------------------------
#-----------------------------------------------------------------------
+#-----------------------------------------------------------------------
+# MAIN
+#-----------------------------------------------------------------------
+gsl__page_creator() {
+gsl__page_prepare_datas
+gsl__check_templates
+gsl__html_meta_head
+gsl__page_create
+}
+
#-----------------------------------------------------------------------
# Get Datas for Post/Page
#-----------------------------------------------------------------------
@@ -43,16 +53,6 @@ esac
gsl_uri_site_logo="$gsl_uri/templates/$gsl_site_logo"
}
-#-----------------------------------------------------------------------
-# MAIN
-#-----------------------------------------------------------------------
-gsl__page_creator() {
-gsl__page_prepare_datas
-gsl__check_templates
-gsl__html_meta_head
-gsl__page_create
-}
-
#-----------------------------------------------------------------------
# Check if Post / Pages exists in server
#-----------------------------------------------------------------------
diff --git a/var/lib/gsl/scripts/gsl__post_checkers b/var/lib/gsl/scripts/gsl__post_checkers
index 1ad984b..bdcb446 100644
--- a/var/lib/gsl/scripts/gsl__post_checkers
+++ b/var/lib/gsl/scripts/gsl__post_checkers
@@ -4,33 +4,35 @@
# By echolib
# License: GNU AFFERO GENERAL PUBLIC LICENSE Version 3, 19 November 2007
-#-----------------------------------------------------------------------
+#----------------------------------------------------------------------
# --------------------------------------------------
# From: gsl__loop_posts | MAIN checkers from modules
# --------------------------------------------------
-#-----------------------------------------------------------------------
+#----------------------------------------------------------------------
gsl__all_checkers() {
clear
unset gsl_check_done
gsl__check_h1 || return
+gsl__post_content_only
+
gsl__get_needed_headers
gsl__check_type
gsl__check_headers
-gsl__check_paragraphs
-gsl__check_blockquote
+gsl__check_paragraphs "$gsl_tmp_post"
+gsl__check_blockquote "$gsl_tmp_post"
gsl__do_header check "$gsl_marker_link" "$gsl_post"
gsl__do_header check "$gsl_marker_abbr" "$gsl_post"
gsl__do_header check "$gsl_marker_file" "$gsl_post"
gsl__do_header check "$gsl_marker_image" "$gsl_post"
gsl__do_header check "$gsl_marker_code" "$gsl_post"
+gsl__stat_words "$gsl_tmp_post"
+gsl__do_strongs_bolds stats "$gsl_tmp_post"
+gsl__do_italics stats "$gsl_tmp_post"
+gsl__do_icode stats "$gsl_tmp_post"
-#echo -ne "\r\033[2K: Searching for Content MARKERS..."
-#gsl__post_check_markers
-
-#echo -ne "\r\033[2K: Searching for some STATS..."
-#gsl__post_check_stats
+rm -f "$gsl_tmp_post"
echo -ne "\r\033[2K"
@@ -38,14 +40,14 @@ echo -ne "\r\033[2K"
gsl__db_line_post
}
-#-----------------------------------------------------------------------
+#----------------------------------------------------------------------
# -------------------------------------------------
# Modules checkers
# -------------------------------------------------
-#-----------------------------------------------------------------------
-#=======================================================================
+#----------------------------------------------------------------------
+#======================================================================
# Check Post for begining content
-#=======================================================================
+#======================================================================
gsl__check_h1() {
echo -ne ": Searching for #1..."
@@ -65,9 +67,9 @@ if ! [[ "$gsl_post_begin" ]];then
fi
}
-#=======================================================================
+#======================================================================
# Check/Set Post Type
-#=======================================================================
+#======================================================================
gsl__check_type() {
echo -ne "\r\033[2K: Searching for Post TYPE..."
@@ -93,24 +95,22 @@ case "$gsl_post_type" in
esac
}
-#=======================================================================
-# Check for paragraphs ( and )
-#=======================================================================
+#======================================================================
+# Check for paragraphs ( and ) | $1: File
+#======================================================================
gsl__check_paragraphs() {
echo -ne "\r\033[2K: Searching for Paragraphs..."
gsl_post_p_open=`
-awk -v line="$gsl_post_begin" \
- -v op="$gsl_mo_p" \
- 'NR > line && $1 == op' \
- "$gsl_post" \
+awk -v op="$gsl_mo_p" \
+ '$1 == op' \
+ "$1" \
| wc -l`
gsl_post_p_close=`
-awk -v line="$gsl_post_begin" \
- -v cp="$gsl_mc_p" \
- 'NR > line && $1 == cp' \
- "$gsl_post" \
+awk -v cp="$gsl_mc_p" \
+ '$1 == cp' \
+ "$1" \
| wc -l`
if (( "$gsl_post_p_open" == 0 ));then
@@ -144,17 +144,16 @@ else
fi
}
-#=======================================================================
-# Check for blockquotes: ---
-#=======================================================================
+#======================================================================
+# Check for blockquotes: --- | $1: File
+#======================================================================
gsl__check_blockquote() {
echo -ne "\r\033[2K: Searching for BLOCKQUOTEs..."
gsl_post_blockquotes_nbr=`
-awk -v line="$gsl_post_begin" \
- -v bq="$gsl_mark_blockquote" \
- 'NR > line && $1 == bq' \
- "$gsl_post" \
+awk -v bq="$gsl_mark_blockquote" \
+ '$1 == bq' \
+ "$1" \
| wc -l`
gsl_post_blockquotes_nbr_r=$(( $gsl_post_blockquotes_nbr % 2 ))
@@ -439,21 +438,19 @@ else
fi
}
+#======================================================================
+# Stat: Count words
+#======================================================================
+gsl__stat_words() {
+echo -ne "\r\033[2K: Counting Words..."
+gsl_stat_words=`cat "$1" | wc -w`
+gsl_stat_words=$(( $gsl_stat_words - 2*$gsl_stat_p ))
+}
-
-
-
-
-
-
-
-
-
-
-#=======================================================================
+#======================================================================
# Check Post for MISSING & VALID Content HEADERS
-#=======================================================================
+#======================================================================
gsl__check_headers() {
echo -ne "\r\033[2K: Searching HEADERS..."
#--------------------------------
@@ -559,92 +556,3 @@ if ! [[ "$gsl_slug_err" ]];then
fi
}
-
-#=======================================================================
-# Check and count MARKERS content (Strong, links...)
-#=======================================================================
-gsl__post_check_markers() {
-gsl_markers_nbr=$(( ${#gsl_o_markers[@]} - 1 ))
-gsl_post_stat_m=(0 0 0 0 0 0)
-
-while read -r "gsl_post_line"
-do
- gsl_line_nbr=`awk -F":" '{print $1}' <<< $gsl_post_line`
-
- for gsl_i in `seq 0 $gsl_markers_nbr`
- do
- if [[ "$gsl_post_line" =~ ${gsl_o_markers[gsl_i]} ]];then
- # Open Marker by Type
- gsl_o=`
- grep -o "${gsl_o_markers[gsl_i]}" \
- <<< $gsl_post_line \
- | wc -l`
- # Close Marker by Type
- gsl_c=`
- grep -o "${gsl_c_markers[gsl_i]}" \
- <<< $gsl_post_line \
- | wc -l`
-
- # Strong Vs Bold | 2= **_ / 3= *_ in array
- if (( $gsl_i == 2 ));then
- gsl_oS=$gsl_o # Open Strong marker nbr
- gsl_cS=$gsl_c # Close Strong marker nbr
-
- elif (( $gsl_i == 3 ));then
- # Count difference from Strong
- if (( $gsl_oS ));then
- gsl_o=$(( $gsl_o - $gsl_oS ))
- unset gsl_oS
- fi
- if (( $gsl_cS ));then
- gsl_c=$(( $gsl_c - $gsl_cS ))
- unset gsl_cS
- fi
- fi
-
- # Compare
- if ! (( $gsl_o == $gsl_c ));then
- gsl__logs_print \
- "$gsl_log_e" \
- "Post" \
- "${gsl_i_markers[gsl_i]}" \
- "Line:$gsl_line_nbr > Mismatch ${gsl_u_markers[gsl_i]}" \
- "${PWD}/$gsl_post"
- gsl_checker_err=true
- else
- gsl_post_stat_m[gsl_i]=$(( gsl_post_stat_m[gsl_i] + gsl_o ))
- fi
- fi
- done
-done < <(awk -v line="$gsl_post_begin" \
- 'NR >= line {print NR":",$0}' \
- "$gsl_post")
-
-gsl_post_stat_mdb=${gsl_post_stat_m[@]}
-
-# Show Counts in logs
-for gsl_i in `seq 0 $gsl_markers_nbr`
-do
- if (( ${gsl_post_stat_m[gsl_i]} >= 1 ));then
- gsl__logs_print \
- "$gsl_log_i" \
- "Post" \
- "${gsl_i_markers[gsl_i]}" \
- "NBR=${gsl_post_stat_m[gsl_i]} > ${gsl_u_markers[gsl_i]}" \
- "${PWD}/$gsl_post"
- fi
-done
-}
-
-#=======================================================================
-# Check for more STATS
-#=======================================================================
-gsl__post_check_stats() {
-gsl_stat_words=`
-awk -v l="$gsl_post_begin" \
- 'NR >= l' \
- "$gsl_post" \
- | wc -w`
-
-gsl_stat_words=$(( $gsl_stat_words - 2*$gsl_stat_p ))
-}
diff --git a/var/lib/gsl/scripts/gsl__post_makers b/var/lib/gsl/scripts/gsl__post_makers
index db620b0..73aac7f 100644
--- a/var/lib/gsl/scripts/gsl__post_makers
+++ b/var/lib/gsl/scripts/gsl__post_makers
@@ -17,22 +17,16 @@ gsl__all_makers() {
clear
unset gsl_check_done
gsl__prepare_makers
-gsl__make_strongs
-gsl__make_bolds
+gsl__do_italics make "$gsl_tmp_post"
gsl__do_header make "$gsl_marker_link" "$gsl_tmp_post"
gsl__do_header make "$gsl_marker_abbr" "$gsl_tmp_post"
gsl__make_titles
-
gsl_ct=0 && gsl__make_titles_div_open
gsl_ct=0 && gsl__make_titles_div_close
-
-#echo -ne "\r\033[2K: Searching and converting lists..."
-#gsl__make_lists
-echo -ne "\r\033[2K: Searching and converting Paragraphs..."
+gsl__do_strongs_bolds make "$gsl_tmp_post"
gsl__make_paragraphs
+gsl__do_icode make "$gsl_tmp_post"
-#echo -ne "\r\033[2K: Searching and converting Inline-Codes..."
-#gsl__make_inline_codes
#echo -ne "\r\033[2K: Searching and converting Block-Codes..."
#gsl__check_bcodes
@@ -44,8 +38,7 @@ echo -ne "\r\033[2K"
rm -f "$gsl_tmp_post"
# Create HTML Page using gsl_a11y_post
-clear
-cat "$gsl_a11y_post"
+# cat "$gsl_a11y_post"
gsl__page_creator
# No more Needed a11y post
@@ -88,14 +81,8 @@ gsl__get_needed_headers
# Get extra Headers DATAS
gsl_header_images=`gsl__get_header "$gsl_marker_image" "$gsl_post"`
+gsl__post_content_only
-# Create TMP file from CONTENT
-gsl_tmp_post=`mktemp`
-awk -v l="$gsl_post_begin" \
- 'NR >= l' \
- "$gsl_post" \
- > "$gsl_tmp_post"
-
# Code readability a11y
gsl_a11y_post=`mktemp`
}
@@ -149,92 +136,9 @@ gsl_make_sb_show() {
echo -ne "\r\033[2K: Converting... Line:$gsl_line_nbr $gsl_html_word"
sed -i "s|$gsl_word_replace|$gsl_html_word|" "$gsl_tmp_post"
unset ${!gsl_word@} ${!gsl_html@}
- }
-#======================================================================
-# From gsl__all_header: Make Strongs
-#======================================================================
-gsl__make_strongs() {
-while read -r "gsl_line_nbr" "gsl_word"
-do
- case "$gsl_word" in
- # STRONG
- "**"*"**"*|*"**"*"**"*)
- gsl_word=${gsl_word#*'**'}
- gsl_word=${gsl_word%'**'*}
- gsl_word_replace='\*\*'"$gsl_word"'\*\*'
- gsl_html_word="$gsl_word"
- gsl_make_sb_show
- ;;
-
- "**"*"**")
- gsl_html_word="${gsl_word//'**'/}"
- gsl_word_replace='\*\*'"$gsl_word"'\*\*'
- gsl_make_sb_show
- ;;
-
- "**"*)
- gsl_word=${gsl_word#'**'*}
- gsl_html_word="$gsl_word"
- gsl_word_replace='\*\*'"$gsl_word"
- gsl_make_sb_show
- ;;
-
- *"**")
- gsl_word=${gsl_word%'**'*}
- gsl_html_word="${gsl_word//'**'/}"
- gsl_word_replace="$gsl_word"'\*\*'
- gsl_make_sb_show
- ;;
-
- *)
- continue
- ;;
- esac
-done < <(awk '{for(i=1;i<=NF;i++) {print NR, $i}}' "$gsl_tmp_post")
}
-#======================================================================
-# From gsl__all_header: Make Bolds
-#======================================================================
-gsl__make_bolds() {
-while read -r "gsl_line_nbr" "gsl_word"
-do
- case "$gsl_word" in
- # STRONG
- "*"*"*"*|*"*"*"*"*)
- gsl_word=${gsl_word#*'*'}
- gsl_word=${gsl_word%'*'*}
- gsl_word_replace='\*'"$gsl_word"'\*'
- gsl_html_word="$gsl_word"
- gsl_make_sb_show
- ;;
- "*"*"*")
- gsl_html_word="${gsl_word//'*'/}"
- gsl_word_replace='\*'"$gsl_word"'\*'
- gsl_make_sb_show
- ;;
-
- "*"*)
- gsl_word=${gsl_word#'*'*}
- gsl_html_word="$gsl_word"
- gsl_word_replace='\*'"$gsl_word"
- gsl_make_sb_show
- ;;
-
- *"*")
- gsl_word=${gsl_word%'*'*}
- gsl_html_word="${gsl_word//'*'/}"
- gsl_word_replace="$gsl_word"'\*'
- gsl_make_sb_show
- ;;
-
- *)
- continue
- ;;
- esac
-done < <(awk '{for(i=1;i<=NF;i++) {print NR, $i}}' "$gsl_tmp_post")
-}
@@ -396,6 +300,8 @@ gsl_html_par_o2="
" gsl_html_par_o3="
" gsl_html_par_c="
" +echo -ne "\r\033[2K: Searching and converting Paragraphs..." + while read -r "gsl_content_line_nbr" "gsl_content_line" do case "$gsl_content_line" in diff --git a/var/lib/gsl/scripts/gsl__post_manager b/var/lib/gsl/scripts/gsl__post_manager index 6914d79..656d576 100644 --- a/var/lib/gsl/scripts/gsl__post_manager +++ b/var/lib/gsl/scripts/gsl__post_manager @@ -111,9 +111,9 @@ gsl_nbr_posts=`ls -1 *.gsl 2>/dev/null | wc -l` && exit 1 } -#======================================================================= +#====================================================================== # Check if Post has same Hash -#======================================================================= +#====================================================================== gsl__post_compare_hash() { gsl__db_post_hash @@ -173,165 +173,13 @@ case "$gsl_process" in esac } -#----------------------------------------------------------------------- -# -------------- -# Tools for Post -# -------------- -#----------------------------------------------------------------------- - -#======================================================================= -# Get Post Hash -#======================================================================= -gsl__post_hash_size() { -gsl_post_csum=`cksum "$gsl_post"` -gsl_post_hash=`awk '{print $1}' <<< "$gsl_post_csum"` -gsl_post_size=`awk '{print $2}' <<< "$gsl_post_csum"` -} - -#======================================================================= -# Get line nbr from Post... $1: TERM | $2: File -#======================================================================= -gsl__get_line() { -awk -v s="$1" \ - 'match($0,s) {print NR}' \ - "$2" -} - -#======================================================================= -# Get everything after the marker... $1: marker | $2: File -#======================================================================= -gsl__get_header() { -awk -F"$1" -v marker="$1" -v l="$gsl_post_begin" \ - 'NR < l && $0 ~ marker {print $2}' \ - "$2" 2>/dev/null -} - -#======================================================================= -# Get line nbr from CONTENT Post... $1: TERM | $2: File -#======================================================================= -gsl__get_content_line() { -awk -v l="$gsl_post_begin" -v s="$1" \ - 'NR >= l && $0 ~ s {print NR}' \ - "$2" || return -} - -#======================================================================= -# Get CONTENT Post with markers... $1: Open Marker | $2: Close Marker -#======================================================================= -gsl__get_content_with_markers() { -gsl__get_content_finder \ - -o "$1" \ - -b "$gsl_post_header_field_1" \ - -c "$2" \ - -f "$gsl_post" \ - | tail -1 \ - || return -} - -#======================================================================= -# Get CONTENT with marks | ! find from ONE line content -#======================================================================= -gsl__get_content_finder() { -# Get [OPTs] -while (( "$#" )) - do - case "$1" in - -o) mk_o="$2" ;; # Open marker - -c) mk_c="$2" ;; # Close Marker - -b) mk_b="$2" ;; # Between markers - -f) file="$2" ;; # In whole file - -v) ivar="$2" ;; # In variable - -n) line="n" ;; # Give found line number - esac - shift -done - -! [[ "$file" ]] && ! [[ "$ivar" ]] && return 1 -! [[ "$mk_o" ]] && ! [[ "$mk_c" ]] && return 1 -! [[ "$mk_b" ]] && mk_b='.*' - -if [[ "$file" ]];then - grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" "$file" && return -elif [[ "$ivar" ]];then - grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" <<< "$ivar" && return -fi -} - -#======================================================================= -# Get NEEDED HEADERS | $1 VAR CONTENT $2 LOG Proc $3 LOG Act -#======================================================================= -gsl__check_needed_headers() { -! [[ "$1" ]] \ - && gsl__logs_print \ - "$gsl_log_e" \ - "Post" \ - "Header $2" \ - "Missing: $3" \ - "${PWD}/$gsl_post" \ - && gsl_checker_err=true -} - -#======================================================================= -# Get fields from variable... $1: field | $2: variable -#======================================================================= -gsl__get_header_field() { -awk -F" : " -v f="$1" \ - 'NFS=f {print $NFS}' \ - <<< "$2" -} - -#======================================================================= -# Get HEADER Fields + line nbr $1:marker -#======================================================================= -gsl__get_header_fields() { -gsl_post_hf_1=`gsl__get_header_field 1 "$gsl_header_content_line"` -gsl_post_hf_2=`gsl__get_header_field 2 "$gsl_header_content_line"` -gsl_post_hf_3=`gsl__get_header_field 3 "$gsl_header_content_line"` -gsl_post_hf_l=`gsl__get_line "$1$gsl_post_hf_1" "$gsl_post"` -} - -#======================================================================= -# Check NEEDED Fields from HEADER -#======================================================================= -gsl__check_header_fields() { -if ! [[ "$gsl_post_hf_1" ]] || \ - ! [[ "$gsl_post_hf_2" ]];then - - gsl__logs_print \ - "$gsl_log_e" \ - "$1" \ - "$2" \ - "Line:$gsl_post_hf_l > $3" \ - "${PWD}/$gsl_post" - gsl_checker_err=true - return -fi -} - -#======================================================================= -# Check OPTIONAL Field 3 from HEADER -#======================================================================= -gsl__check_header_field3() { -if ! [[ "$gsl_post_header_field_3" ]];then - case "$3" in - "$gsl_marker_image") - gsl__logs_print \ - "$gsl_log_e" \ - "$1" \ - "$2" \ - "Line:$gsl_post_hf_l > No ALT TEXT !" \ - "${PWD}/$gsl_post" - gsl_checker_err=true - ;; - *) - gsl__logs_print \ - "$gsl_log_w" \ - "$1" \ - "$2" \ - "Line:$gsl_post_hf_l > No Alt Text ?" \ - "${PWD}/$gsl_post" - gsl_checker_war=true - ;; - esac -fi +#====================================================================== +# Create TMP file > Get Content Post Only (after #1) +#====================================================================== +gsl__post_content_only() { +gsl_tmp_post=`mktemp` +awk -v l="$gsl_post_begin" \ + 'NR >= l' \ + "$gsl_post" \ + > "$gsl_tmp_post" } diff --git a/var/lib/gsl/scripts/gsl__tools b/var/lib/gsl/scripts/gsl__tools index f40da9e..340dc79 100644 --- a/var/lib/gsl/scripts/gsl__tools +++ b/var/lib/gsl/scripts/gsl__tools @@ -108,3 +108,166 @@ do fi done } + +#----------------------------------------------------------------------- +# -------------- +# Tools for Post +# -------------- +#----------------------------------------------------------------------- + +#======================================================================= +# Get Post Hash +#======================================================================= +gsl__post_hash_size() { +gsl_post_csum=`cksum "$gsl_post"` +gsl_post_hash=`awk '{print $1}' <<< "$gsl_post_csum"` +gsl_post_size=`awk '{print $2}' <<< "$gsl_post_csum"` +} + +#======================================================================= +# Get line nbr from Post... $1: TERM | $2: File +#======================================================================= +gsl__get_line() { +awk -v s="$1" \ + 'match($0,s) {print NR}' \ + "$2" +} + +#======================================================================= +# Get everything after the marker... $1: marker | $2: File +#======================================================================= +gsl__get_header() { +awk -F"$1" -v marker="$1" -v l="$gsl_post_begin" \ + 'NR < l && $0 ~ marker {print $2}' \ + "$2" 2>/dev/null +} + +#======================================================================= +# Get line nbr from CONTENT Post... $1: TERM | $2: File +#======================================================================= +gsl__get_content_line() { +awk -v l="$gsl_post_begin" -v s="$1" \ + 'NR >= l && $0 ~ s {print NR}' \ + "$2" || return +} + +#======================================================================= +# Get CONTENT Post with markers... $1: Open Marker | $2: Close Marker +#======================================================================= +gsl__get_content_with_markers() { +gsl__get_content_finder \ + -o "$1" \ + -b "$gsl_post_header_field_1" \ + -c "$2" \ + -f "$gsl_post" \ + | tail -1 \ + || return +} + +#======================================================================= +# Get CONTENT with marks | ! find from ONE line content +#======================================================================= +gsl__get_content_finder() { +# Get [OPTs] +while (( "$#" )) + do + case "$1" in + -o) mk_o="$2" ;; # Open marker + -c) mk_c="$2" ;; # Close Marker + -b) mk_b="$2" ;; # Between markers + -f) file="$2" ;; # In whole file + -v) ivar="$2" ;; # In variable + -n) line="n" ;; # Give found line number + esac + shift +done + +! [[ "$file" ]] && ! [[ "$ivar" ]] && return 1 +! [[ "$mk_o" ]] && ! [[ "$mk_c" ]] && return 1 +! [[ "$mk_b" ]] && mk_b='.*' + +if [[ "$file" ]];then + grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" "$file" && return +elif [[ "$ivar" ]];then + grep -oP$line "(?<=$mk_o)$mk_b?(?=$mk_c)" <<< "$ivar" && return +fi +} + +#======================================================================= +# Get NEEDED HEADERS | $1 VAR CONTENT $2 LOG Proc $3 LOG Act +#======================================================================= +gsl__check_needed_headers() { +! [[ "$1" ]] \ + && gsl__logs_print \ + "$gsl_log_e" \ + "Post" \ + "Header $2" \ + "Missing: $3" \ + "${PWD}/$gsl_post" \ + && gsl_checker_err=true +} + +#======================================================================= +# Get fields from variable... $1: field | $2: variable +#======================================================================= +gsl__get_header_field() { +awk -F" : " -v f="$1" \ + 'NFS=f {print $NFS}' \ + <<< "$2" +} + +#======================================================================= +# Get HEADER Fields + line nbr $1:marker +#======================================================================= +gsl__get_header_fields() { +gsl_post_hf_1=`gsl__get_header_field 1 "$gsl_header_content_line"` +gsl_post_hf_2=`gsl__get_header_field 2 "$gsl_header_content_line"` +gsl_post_hf_3=`gsl__get_header_field 3 "$gsl_header_content_line"` +gsl_post_hf_l=`gsl__get_line "$1$gsl_post_hf_1" "$gsl_post"` +} + +#======================================================================= +# Check NEEDED Fields from HEADER +#======================================================================= +gsl__check_header_fields() { +if ! [[ "$gsl_post_hf_1" ]] || \ + ! [[ "$gsl_post_hf_2" ]];then + + gsl__logs_print \ + "$gsl_log_e" \ + "$1" \ + "$2" \ + "Line:$gsl_post_hf_l > $3" \ + "${PWD}/$gsl_post" + gsl_checker_err=true + return +fi +} + +#======================================================================= +# Check OPTIONAL Field 3 from HEADER +#======================================================================= +gsl__check_header_field3() { +if ! [[ "$gsl_post_header_field_3" ]];then + case "$3" in + "$gsl_marker_image") + gsl__logs_print \ + "$gsl_log_e" \ + "$1" \ + "$2" \ + "Line:$gsl_post_hf_l > No ALT TEXT !" \ + "${PWD}/$gsl_post" + gsl_checker_err=true + ;; + *) + gsl__logs_print \ + "$gsl_log_w" \ + "$1" \ + "$2" \ + "Line:$gsl_post_hf_l > No Alt Text ?" \ + "${PWD}/$gsl_post" + gsl_checker_war=true + ;; + esac +fi +}