Część, mam mały problem, męczę się od 2 dni.
Doszedłem do kodu:
tresc='tekst z pola pre...';
t = tresc.replace(/<\//g,'<⁄');
t = t.replace(/\/>/g,'⁄>');
t = t.replace(/</g,'<');
t = t.replace(/>/g,'>');
nt = t.replace(/<⁄(\!DOCTYPE|\!doctype|acronym|address|applet|basefont|blockquote|button|caption|colgroup|fieldset|frame|frameset|iframe|isindex|label|legend|noframes|noscript|object|optgroup|option|param|script|select|strike|strong|textarea|center|input|tbody|table|style|title|tfoot|thead|small|samp|meta|menu|link|html|head|form|font|code|cite|body|base|area|abbr|span|pre|col|del|dfn|dir|div|img|ins|kbd|map|sub|sup|var|bdo|big|dd|dl|dt|em|h1|h2|h3|h4|h5|h6|hr|td|ol|li|th|tr|tt|ul|br|a|b|p|i|q|s|u)>/ig,"<span class=ex1><⁄$1></span>");
nt = nt.replace(/<(\!DOCTYPE|\!doctype|acronym|address|applet|basefont|blockquote|button|caption|colgroup|fieldset|frame|frameset|iframe|isindex|label|legend|noframes|noscript|object|optgroup|option|param|script|select|strike|strong|textarea|center|input|tbody|table|style|title|tfoot|thead|small|samp|meta|menu|link|html|head|form|font|code|cite|body|base|area|abbr|span|pre|col|del|dfn|dir|div|img|ins|kbd|map|sub|sup|var|bdo|big|dd|dl|dt|em|h1|h2|h3|h4|h5|h6|hr|td|ol|li|th|tr|tt|ul|br|a|b|p|i|q|s|u)>/ig,"<span class=ex1><$1></span>");
nt = nt.replace(/<(\!DOCTYPE|\!doctype|acronym|address|applet|basefont|blockquote|button|caption|colgroup|fieldset|frame|frameset|iframe|isindex|label|legend|noframes|noscript|object|optgroup|option|param|script|select|strike|strong|textarea|center|input|tbody|table|style|title|tfoot|thead|small|samp|meta|menu|link|html|head|form|font|code|cite|body|base|area|abbr|span|pre|col|del|dfn|dir|div|img|ins|kbd|map|sub|sup|var|bdo|big|dd|dl|dt|em|h1|h2|h3|h4|h5|h6|hr|td|ol|li|th|tr|tt|ul|br|a|b|p|i|q|s|u)([^<]*)>/ig,"<span class=ex1>_<$1</span>$2<span class=ex1>>_</span>"); //([^>]*)
nt = nt.replace(/([^ ]+)\="([^ ]+)"/g,"<span class=ex2>$1</span>=<span class=ex3>\"$2\"</span>");
nt = nt.replace(/([^ ]+)\="(.+)"/g,"<span class=ex2>$1</span>=<span class=ex3>\"$2\"</span>");
nt = nt.replace(/<\!--(.*)-->/g,"<span class=ex5><!--$1--></span>");
Na początku zamieniam <,> oraz /
Następnie Zamieniam wszystkie znaczniki html-a.
Problem: czasami omija znak >
np: <p style="color: black">Tekst</p__>__
Następnym błędem jest kolorowanie tekstu komentarzu, gdy jest w jednej lini dobrze koloruje, a gdy jest w kilku linijkach nie koloruje.
Zna się ktoś na wyrażeniach? Proszę o pomoc.