@@ -17,39 +17,57 @@ class HtmlUtils {
1717 if (mdData == null ) {
1818 return "" ;
1919 }
20- RegExp exp = new RegExp ("<code(([\\ s\\ S])*?)<\/ code>" );
21- Iterable <Match > tags = exp.allMatches (mdData);
2220 String mdDataCode = mdData;
23- for (Match m in tags) {
24- String match = m.group (0 ).replaceAll (new RegExp ("\n " ), "\n\r <br>" );
25- mdDataCode = mdDataCode.replaceAll (m.group (0 ), match);
26- }
21+ String regExCode = "<[\\ s]*?code[^>]*?>[\\ s\\ S]*?<[\\ s]*?\\ /[\\ s]*?code[\\ s]*?>" ;
22+ String regExPre = "<[\\ s]*?pre[^>]*?>[\\ s\\ S]*?<[\\ s]*?\\ /[\\ s]*?pre[\\ s]*?>" ;
23+
2724
28- exp = new RegExp ( "<pre(([ \\ s \\ S])*?)< \/ pre>" );
29- tags = exp. allMatches (mdDataCode );
30- for ( Match m in tags) {
31- if (m. group ( 0 ). indexOf ( "<code>" ) < 0 ) {
25+ try {
26+ RegExp exp = new RegExp (regExCode );
27+ Iterable < Match > tags = exp. allMatches (mdData);
28+ for ( Match m in tags ) {
3229 String match = m.group (0 ).replaceAll (new RegExp ("\n " ), "\n\r <br>" );
3330 mdDataCode = mdDataCode.replaceAll (m.group (0 ), match);
3431 }
32+ } catch (e) {
33+ print (e);
3534 }
36-
37- exp = new RegExp ("<pre>(([\\ s\\ S])*?)<\/ pre>" );
38- tags = exp.allMatches (mdDataCode);
39- for (Match m in tags) {
40- if (m.group (0 ).indexOf ("<code>" ) < 0 ) {
41- String match = m.group (0 ).replaceAll (new RegExp ("\n " ), "\n\r <br>" );
42- mdDataCode = mdDataCode.replaceAll (m.group (0 ), match);
35+ try {
36+ RegExp exp = new RegExp (regExPre);
37+ Iterable <Match > tags = exp.allMatches (mdDataCode);
38+ for (Match m in tags) {
39+ if (m.group (0 ).indexOf ("<code>" ) < 0 ) {
40+ String match = m.group (0 ).replaceAll (new RegExp ("\n " ), "\n\r <br>" );
41+ mdDataCode = mdDataCode.replaceAll (m.group (0 ), match);
42+ }
4343 }
44+ } catch (e) {
45+ print (e);
4446 }
4547
46- exp = new RegExp ("href=\" (.*?)\" " );
47- tags = exp.allMatches (mdDataCode);
48- for (Match m in tags) {
49- String capture = m.group (0 );
50- if (capture.indexOf ("http://" ) < 0 && capture.indexOf ("https://" ) < 0 && capture.indexOf ("#" ) != 0 ) {
51- mdDataCode = mdDataCode.replaceAll (m.group (0 ), "gsygithub://" + capture);
48+ try {
49+ RegExp exp = new RegExp ("<pre>(([\\ s\\ S])*?)<\/ pre>" );
50+ Iterable <Match > tags = exp.allMatches (mdDataCode);
51+ for (Match m in tags) {
52+ if (m.group (0 ).indexOf ("<code>" ) < 0 ) {
53+ String match = m.group (0 ).replaceAll (new RegExp ("\n " ), "\n\r <br>" );
54+ mdDataCode = mdDataCode.replaceAll (m.group (0 ), match);
55+ }
5256 }
57+ } catch (e) {
58+ print (e);
59+ }
60+ try {
61+ RegExp exp = new RegExp ("href=\" (.*?)\" " );
62+ Iterable <Match > tags = exp.allMatches (mdDataCode);
63+ for (Match m in tags) {
64+ String capture = m.group (0 );
65+ if (capture.indexOf ("http://" ) < 0 && capture.indexOf ("https://" ) < 0 && capture.indexOf ("#" ) != 0 ) {
66+ mdDataCode = mdDataCode.replaceAll (m.group (0 ), "gsygithub://" + capture);
67+ }
68+ }
69+ } catch (e) {
70+ print (e);
5371 }
5472
5573 return generateCodeHtml (mdDataCode, false , backgroundColor: backgroundColor, actionColor: GSYColors .actionBlueString, userBR: userBR);
@@ -203,7 +221,6 @@ class HtmlUtils {
203221 return builder;
204222 }
205223
206-
207224 static resolveHtmlFile (var res, String defaultLang) {
208225 if (res != null && res.result) {
209226 String startTag = "class=\" instapaper_body " ;
0 commit comments