_html: Make Perl replacements more robust

This commit is contained in:
Stig-Ørjan Smelror 2024-02-01 11:05:17 +01:00
parent 08d20b0550
commit 03a720849d

76
qsgen2
View File

@ -803,9 +803,8 @@ function _html() {
if ${debug}; then _msg debug "_html: Converting QStags in content"; fi if ${debug}; then _msg debug "_html: Converting QStags in content"; fi
# Convert QStags to HTML using Perl # Convert QStags to HTML using Perl, excluding specific patterns
local html_content=$(perl -pe ' local html_content=$(echo "$content" | perl -0777 -pe '
next if /#link|#image|#ytvideo/;
s/(?<!\S)#BR\b/<br\/>\n/gi; s/(?<!\S)#BR\b/<br\/>\n/gi;
s/(?<!\S)#B\b/<b>/gi; s/(?<!\S)#B\b/<b>/gi;
s/(?<!\S)#EB\b/<\/b>\n/gi; s/(?<!\S)#EB\b/<\/b>\n/gi;
@ -818,51 +817,50 @@ function _html() {
s/(?<!\S)#STRONG\b/<strong>/gi; s/(?<!\S)#STRONG\b/<strong>/gi;
s/(?<!\S)#ESTRONG\b/<\/strong>/gi; s/(?<!\S)#ESTRONG\b/<\/strong>/gi;
s/(?<!\S)#EM\b/<em>/gi; s/(?<!\S)#EM\b/<em>/gi;
s/(?<!\S)#MEM\b/<\/em>/gi; s/(?<!\S)#EEM\b/<\/em>/gi;
s/(?<!\S)#DV\b/<div>/gi; s/(?<!\S)#DV\b/<div>/gi;
s/(?<!\S)#EDV\b/<\/div>\n/gi; s/(?<!\S)#EDV\b/<\/div>\n/gi;
s/(?<!\S)#SPN\b/<span>/gi; s/(?<!\S)#SPN\b/<span>/gi;
s/(?<!\S)#ESPN\b/<\/span>\n/gi; s/(?<!\S)#ESPN\b/<\/span>\n/gi;
s/(?<!\S)#UL\b/\n<ul>/gi; s/(?<!\S)#UL\b/<ul>/gi;
s/(?<!\S)#EUL\b/\n<\/ul>\n/gi; s/(?<!\S)#EUL\b/<\/ul>\n/gi;
s(?<!\S)#OL\b/\n<ol>/gi; s/(?<!\S)#OL\b/<ol>/gi;
s/(?<!\S)#EOL\b/\n<\/ol>\n/gi; s/(?<!\S)#EOL\b/<\/ol>\n/gi;
s(?<!\S)#LI\b/<li>/gi; s/(?<!\S)#LI\b/<li>/gi;
s(?<!\S)#ELI\b/<\/li>\n/gi; s/(?<!\S)#ELI\b/<\/li>\n/gi;
s(?<!\S)#U\b/<u>/gi; s/(?<!\S)#U\b/<u>/gi;
s(?<!\S)#EU\b/<\/u>/gi; s/(?<!\S)#EU\b/<\/u>/gi;
s(?<!\S)#TBL\b/<table>/gi; s/(?<!\S)#TBL\b/<table>/gi;
s(?<!\S)#ETBL\b/<\/table>\n/gi; s/(?<!\S)#ETBL\b/<\/table>\n/gi;
s(?<!\S)#TR\b/<tr>/gi; s/(?<!\S)#TR\b/<tr>/gi;
s(?<!\S)#ETR\b/<\/tr>\n/gi; s/(?<!\S)#ETR\b/<\/tr>\n/gi;
s(?<!\S)#TD\b/<td>/gi; s/(?<!\S)#TD\b/<td>/gi;
s(?<!\S)#ETD\b/<\/td>\n/gi; s/(?<!\S)#ETD\b/<\/td>\n/gi;
s(?<!\S)#TH\b/<th>/gi; s/(?<!\S)#TH\b/<th>/gi;
s(?<!\S)#ETH\b/<\/th>\n/gi; s/(?<!\S)#ETH\b/<\/th>\n/gi;
s(?<!\S)#ART\b/<article>/gi; s/(?<!\S)#ART\b/<article>/gi;
s(?<!\S)#EART\b/<\/article>\n/gi; s/(?<!\S)#EART\b/<\/article>\n/gi;
s(?<!\S)#SEC\b/<section>/gi; s/(?<!\S)#SEC\b/<section>/gi;
s(?<!\S)#ESEC\b/<\/section>\n/gi; s/(?<!\S)#ESEC\b/<\/section>\n/gi;
s(?<!\S)#ASIDE\b/<aside>/gi; s/(?<!\S)#ASIDE\b/<aside>/gi;
s(?<!\S)#EASIDE\b/<\/aside>\n/gi; s/(?<!\S)#EASIDE\b/<\/aside>\n/gi;
s(?<!\S)#NAV\b/<nav>/gi; s/(?<!\S)#NAV\b/<nav>/gi;
s(?<!\S)#ENAV\b/<\/nav>\n/gi; s/(?<!\S)#ENAV\b/<\/nav>\n/gi;
s(?<!\S)#BTN\b/<button>/gi; s/(?<!\S)#BTN\b/<button>/gi;
s(?<!\S)#EBTN\b/<\/button>\n/gi; s/(?<!\S)#EBTN\b/<\/button>\n/gi;
s(?<!\S)#SEL\b/<select>/gi; s/(?<!\S)#SEL\b/<select>/gi;
s(?<!\S)#ESEL\b/<\/select>\n/gi; s/(?<!\S)#ESEL\b/<\/select>\n/gi;
s(?<!\S)#OPT\b/<option>/gi; s/(?<!\S)#OPT\b/<option>/gi;
s(?<!\S)#EOPT\b/<\/option>\n/gi; s/(?<!\S)#EOPT\b/<\/option>\n/gi;
s/(?<!\S)\#LT\b/\&lt;/gi; s/(?<!\S)#LT\b/&lt;/gi;
s/(?<!\S)\#GT\b/\&gt;/gi; s/(?<!\S)#GT\b/&gt;/gi;
s/(?<!\S)\#NUM\b/\&num;/gi; s/(?<!\S)#NUM\b/&num;/gi;
' <<< "$content") ')
echo "${html_content}" echo "${html_content}"
} }
# Time to test the first function # Time to test the first function
#_msg std "Running function blogs" #_msg std "Running function blogs"
_blogs _blogs