# text.2.wiki.awk

Last edit

Summary: text.2.wiki.awk

Changed:

< &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Converts n spaces to (n -1) &#35;nbsp; followed by a space.\\
< &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Converts literal {{{&#92;}}}240 to the character {{{&#92;}}}240 == &#92;xa0 - non breaking space.\\

to

> &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Converts n spaces to (n -1) &#38;nbsp; followed by a space.\\
> &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Converts literal &#92;240 to the character &#92;240 == &#92;xa0 - non breaking space.\\

Changed:

< &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Remember to escape | &#92;&#92; // * # == etc. eg {{{|}}}\\
<
&#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Use **{{{|}}}** to make bold; [[..|link]] use   for spaces.\\
< &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To escape text; use {{{ for .txt files or #:{{{ for .awk files\\
< &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ::{{{ for .cmd files or ;{{{ for .ini files.\\
< &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (end with the corresponding ..}}})\\

to

> {{{ #: Remember to escape | \\ // * # == etc. eg {{{|}}} }}} \\
> &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Use &#42;&#42;&#123;&#123;&#123|&#125;&#125;&#125&#42;&#42; to make bold; [[..|link]] use   for spaces.\\
> &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; To escape text; use &#123;&#123;&#123 for .txt files or #&#123;&#123;&#123 for .awk files\\
> &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or ::&#123;&#123;&#123 for .cmd files or ;&#123;&#123;&#123 for .ini files.\\
> &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (end with the corresponding ..&#125;&#125;&#125)\\

Changed:

< &#35;: test.text.2.wiki.awk.txt == http://awkpaste.blisted.org/cgi/paste.cgi?id=2874&#35;view=text\\

to

> &#35;: test.text.2.wiki.awk.txt == http://awkpaste.blisted.org/cgi/paste.cgi?id=2874&#38;view=text\\

Changed:

< **{{{ }}}**\\
< **{{{
$1 = _in_escape = t = ""; _esc1 = "{\173{"; _esc2 = "}\175}"; }}}**\\ < **{{{ _splat2 = "**"; _bs2 = "\\\\"; }}}**\\ < **{{{ _prefix = _prefix "|#|::|;|//|"; }}}**\\ < **{{{ n = split(_prefix, B, "|"); }}}**\\ to > \\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$1 = _in_escape = t = ""; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _esc1 = "{&#92;173{"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _esc2 = "}&#92;175}";\\
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_splat2 = "&#42;&#42;"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _bs2 = "&#92;&#92;&#92;&#92;";\\
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_prefix = _prefix "|#|::|;|//|";\\
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
n = split(_prefix, B, "|");\\

Changed:

< &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if((! _in_escape) &#35;&#35; (A[i] == _esc1)) &nbsp; {\\

to

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if((! _in_escape) &#38;&#38; (A[i] == _esc1)) &nbsp; {\\

Changed:

< &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; next;\\
< &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp; else &nbsp; if(_in_escape &#35;&#35; (A[i] == _esc2)) &nbsp; {\\

to

> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($0 == "") &nbsp; next;\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp; else &nbsp; if(_in_escape &#38;&#38; (A[i] == _esc2)) &nbsp; {\\ Changed: < &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; next;\\ to > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($0 == "") &nbsp; next;\\

Changed:

< &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = _splat2 _esc1 " " $0 " " _esc2 _splat2 _bs2;\\ to > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = _esc1 " "$0 " " _esc2 " " _bs2;\\

Deleted:

< **{{{ }}}**\\
< **{{{ if($0 ~ /\\\\$/) { }}}**\\
< **{{{ s = $0; }}}**\\ < **{{{ } else if($0 ~ /$/) { }}}**\\ < **{{{ s = substr($0, 1, length($0) - 1); }}}**\\ < **{{{ } else s =$0 "\\\\"; }}}**\\
< **{{{ }}}**\\
< **{{{ gsub("\&", "\\&#35;", s); }}}**\\
< **{{{ gsub("\t", " ", s); }}}**\\
< **{{{ while(gsub(" ", " \\&nbsp; ", s)) ; }}}**\\
< **{{{ #: & Special in gsub, use "\\&" }}}**\\
< **{{{ }}}**\\
< **{{{ while(gsub("\&nbsp; \&nbsp;", \ }}}**\\
< **{{{ "\\&nbsp;\\&nbsp;\\&nbsp;", s)) ; }}}**\\
< **{{{ }}}**\\
< **{{{ gsub("\\\\240", "\240", s); }}}**\\
< **{{{ #: if(s ~ /^#/) s = _esc1 "#" _esc2 substr(s, 2); }}}**\\
< **{{{ if(s ~ "^\043") sub("\043", "\\&#35;", s); }}}**\\
< **{{{ }}}**\\
< **{{{ if(s ~ /\\\\$/) { }}}**\\ < **{{{ s = substr(s, 1, length(s) - 2); }}}**\\ < **{{{ gsub("\\\\", "\\&#92;", s); }}}**\\ < **{{{ s = s "\134\134"; }}}**\\ < **{{{ } else gsub("\\\\", "\\&#92;", s); }}}**\\ < **{{{ }}}**\\ Added: > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($0 ~ /&#92;&#92;&#92;&#92;$/) &nbsp; {\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s =$0;\\
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp; else &nbsp; if($0 ~ /$/) &nbsp; {\\
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = substr($0, 1, length($0) - 1);\\
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = $0 "&#92;&#92;&#92;&#92;";\\ > \\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#38;", "&#92;&#92;&#38;#38;", s);\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;t", " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ", s);\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(gsub(" &nbsp; ", " &#92;&#92;&#38;nbsp; ", s)) &nbsp; ;\\ > &#35;: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#38; Special in gsub, use "&#92;&#92;&#38;"\\ > \\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while(gsub("&#92;&#38;nbsp; &#92;&#38;nbsp;", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#92;\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; "&#92;&#92;&#38;nbsp;&#92;&#92;&#38;nbsp;&#92;&#92;&#38;nbsp;", s)) &nbsp; ;\\ > \\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#92;&#92; ", " ", s);\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#123;&#123;&#123&#92;&#92;&#92;&#92;&#125;&#125;&#125", "&#92;&#92;", s);\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if($1 ~ "^&#92;043") &nbsp; sub("&#92;043", "&#92;&#92;&#38;#35;", s); &nbsp; #: &nbsp; the #\\
> \\
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if(s ~ /&#92;&#92;&#92;&#92;$/) &nbsp; {\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = substr(s, 1, length(s) - 2);\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#92;&#92;&#92;", "&#92;&#92;&#38;#92;", s);\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; s = s "&#92;134&#92;134"; &nbsp; #: &nbsp; the back slash\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } &nbsp; else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#92;&#92;&#92;", "&#92;&#92;&#38;#92;", s);\\ > \\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i = index(s, "[["); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = index(s, "&#92;|"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k = index(s, "]]"); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( 0 < i &#38;&#38; i < j &#38;&#38; j < k) &nbsp; s = substr(s, 1, j - 1) "&#92;377" substr(s, j + 1);\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#92;&#92;052&#92;&#92;&#92;052", "&#92;&#92;&#38;#42;&#92;&#92;&#38;#42;", s); &nbsp; #: &nbsp; &#42;&#42;\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#92;&#92;173&#92;&#92;&#92;173&#92;&#92;&#92;173", "&#92;&#92;&#38;#123;&#92;&#92;&#38;#123;&#92;&#92;&#38;#123", s); &nbsp; #: &nbsp; &#123;&#123;&#123\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#92;&#92;175&#92;&#92;&#92;175&#92;&#92;&#92;175", "&#92;&#92;&#38;#125;&#92;&#92;&#38;#125;&#92;&#92;&#38;#125", s); &nbsp; #: &nbsp; &#125;&#125;&#125\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gsub("&#92;&#92;&#92;377", "&#92;|", s);\\ Changed: < **{{{ }}}**\\ < **{{{ c = (c ? c : (_u ? _u : "%u%")) "\\gclip.exe"; }}}**\\ < **{{{ printf("%s", s) | c; }}}**\\ < \\ to > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = (c ? c : (_u ? _u : "%u%")) "&#92;&#92;gclip.exe";\\ > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%s", s) | c;\\ Changed: < **{{{ }}}**\\ < **{{{ #: regular expression metacharacters: \ ^$ . [ ] | ( ) * + ? escape with \ }}}**\\
< **{{{
#: filenames may Not contain: \ / : * ? " < > | }}}**\\
< **{{{
#: cmd.exe special: & " ^ % < > | = ( ) @ }}}**\\
< **{{{
#: start ["title"] [/min|/max] [/low|/high] [/wait] [/b] cmd }}}**\\
< **{{{
#: start /wait exefile & call echo.^%ERRORLEVEL^% }}}**\\
< **{{{
#: %u%nircmd.exe exec show|hide|min|max exefile opts }}}**\\
< **{{{
#: shexec open|print filename }}}**\\
< **{{{
#: \a \007 sp\040 !\041 "\042 #\043 $\044 %\045 &\046 }}}**\\ < **{{{ #: '\047 *\052 +\053 -\055 .\056 /\057 <\074 =\075 >\076 }}}**\\ < **{{{ #: ?\077 @\100 \\134 ^\136 \140 |\174 ~\176 ' '\240 }}}**\\ < \\ to > {{{ #: regular expression metacharacters: \ ^$ . [ ] | ( ) * + ? escape with \ }}} \\
> {{{
#: filenames may Not contain: \ / : * ? " < > | }}} \\
> {{{
#: cmd.exe special: & " ^ % < > | = ( ) @ }}} \\
> {{{
#: start ["title"] [/min|/max] [/low|/high] [/wait] [/b] cmd }}} \\
> {{{
#: start /wait exefile & call echo.^%ERRORLEVEL^% }}} \\
> {{{
#: %u%nircmd.exe exec show|hide|min|max exefile opts }}} \\
> {{{
#: shexec open|print filename }}} \\
> {{{
#: \a \007 sp\040 !\041 "\042 #\043 $\044 %\045 &\046 }}} \\ > {{{ #: '\047 *\052 +\053 -\055 .\056 /\057 <\074 =\075 >\076 }}} \\ > {{{ #: ?\077 @\100 \\134 ^\136 \140 |\174 ~\176 ' '\240 }}} \\ #: C:\#\awk\lib\text.2.wiki.awk #: 2012-09-23 13:39:45 #:rod.t_2012 #: This file is http://awk.freeshell.org/text.2.wiki.awk (g0ph3r_) #: Converts text to a format for the awk wiki: http://awk.freeshell.org #: See: http://awk.freeshell.org/How_to_edit #: Adds a \\ to end of every line to force line break #: except those ending in  or \\ (removes the ) #: Converts tabs \t to four spaces. #: Converts n spaces to (n -1) &nbsp; followed by a space. #: Converts literal \240 to the character \240 == \xa0 - non breaking space. #: Prints results to stdout and copies to the clipboard.  #: Remember to escape | \\ // * # == etc. eg {{{| }}} #: Use **{{&#123|}}&#125** to make bold; [[..?|link]] use for spaces. #: To escape text; use {{&#123 for .txt files or #{{&#123 for .awk files #: or ::{{&#123 for .cmd files or ;{{&#123 for .ini files. #: (end with the corresponding ..}}&#125) #: %gawk% --lint -f C:\#\awk\lib\text.2.wiki.awk -v _prefix="@rem |<!--" #: -v _clip=1 -v _debug=1 -- C:\#\awk\#awk_wiki\test.text.2.wiki.awk.txt #: test.text.2.wiki.awk.txt == http://awkpaste.blisted.org/cgi/paste.cgi?id=2874&#38;view=text #: insert a -v _clip=1 to copy results to the clipboard ## _____________________________________________ BEGIN {$1 = _in_escape = t = "";       _esc1 = "{\173{";       _esc2 = "}\175}";
_splat2 = "**";       _bs2 = "\\\\";
_prefix = _prefix "|#|::|;||";
n = split(_prefix, B, "|");

if(_debug)   for(i in B)   { print(_qt_(++j, "B[]", i, B[i]));   fflush(); }
for(i in B)   {
A[(B[i] _esc1)] = _esc1;
A[(B[i] _esc2)] = _esc2;
}
if(_debug)   for(i in A)   { print(_qt_(++k, "A[]", i, A[i]));   fflush(); }
}

{
for(i in A)   if(tolower($1) == i) { if((! _in_escape) && (A[i] == _esc1)) { _in_escape = 1;$1 = "";
#:                       t = t ? (t "\n" A[i] "\n") : (A[i] "\n");
if(_debug)   { print(_qt_("_in_escape:", _in_escape, t, "end"));   fflush(); }
if($0 == "") next; } else if(_in_escape && (A[i] == _esc2)) { _in_escape = "";$1 = "";
#:                       t = t ? (t "\n" A[i] "\n") : (A[i] "\n");
if(_debug)   { print(_qt_("_in_escape:", _in_escape, t, "end"));   fflush(); }
if($0 == "") next; } } if(_in_escape) { s = _esc1 " "$0 " " _esc2 " " _bs2;
t = t ? (t "\n" s) : s;
next;
}

if($0 ~ /\\\\$/)   {
s = $0; } else if($0 ~ /$/) { s = substr($0, 1, length($0) - 1); } else s =$0 "\\\\";

gsub("\&", "\\&#38;", s);
gsub("\t", "       ", s);
while(gsub("   ", " \\&nbsp; ", s))   ;
#:       & Special in gsub, use "\\&"

while(gsub("\&nbsp; \&nbsp;",               \
"\\&nbsp;\\&nbsp;\\&nbsp;", s))   ;

gsub("\\\ ", " ", s);
gsub("{{&#123\\\\}}&#125", "\\", s);
if($1 ~ "^\043") sub("\043", "\\&#35;", s); #: the # if(s ~ /\\\\$/)   {
s = substr(s, 1, length(s) - 2);
gsub("\\\\", "\\&#92;", s);
s = s "\134\134";   #:   the back slash
}   else       gsub("\\\\", "\\&#92;", s);

i = index(s, "[[");       j = index(s, "\|");       k = index(s, "]]");
if( 0 < i && i < j && j < k)   s = substr(s, 1, j - 1) "\377" substr(s, j + 1);
gsub("\\\052\\\052", "\\&#42;\\&#42;", s);   #:   **
gsub("\\\173\\\173\\\173", "\\&#123;\\&#123;\\&#123", s);   #:   {{&#123
gsub("\\\175\\\175\\\175", "\\&#125;\\&#125;\\&#125", s);   #:   }}&#125
gsub("\\\377", "\|", s);
t = t ? (t "\n" s) : s;
}

END   {
print(t);
if(_clip)   _put2clip(t);
}

function       _put2clip(s,   c)   {
c = (c ? c : (_u ? _u : "%u%")) "\\gclip.exe";
printf("%s", s) | c;
return(close(c));
}

function       _qt_(s, t, u, v,   ss)   {
ss = "1: " s;       ss = ss "\t2: " t;
ss = ss "\t3: " u;       ss = ss "\t4: " v;
return((ss ""));
}
##   _____________________________________________

 #: regular expression metacharacters: \ ^ $. [ ] | ( ) * + ? escape with \   #: filenames may Not contain: \ / : * ? " < > |   #: cmd.exe special: & " ^ % < > | = ( ) @   #: start ["title"] [/min|/max] [/low|/high] [/wait] [/b] cmd   #: start /wait exefile & call echo.^%ERRORLEVEL^%   #: %u%nircmd.exe exec show|hide|min|max exefile opts   #: shexec open|print filename   #: \a \007 sp\040 !\041 "\042 #\043$\044 %\045 &\046 
 #: '\047 *\052 +\053 -\055 .\056 /\057 <\074 =\075 >\076 
 #: ?\077 @\100 \\134 ^\136 \140 |\174 ~\176 ' '\240