@@ -17,15 +17,19 @@ class HtmlUtils {
1717 if (mdData == null ) {
1818 return "" ;
1919 }
20- RegExp exp = new RegExp ("<code(([\s \S ])*?)<\/ code>" );
20+ RegExp exp = new RegExp ("<code(([\\ s \ \ S])*?)<\/ code>" );
2121 Iterable <Match > tags = exp.allMatches (mdData);
2222 String mdDataCode = mdData;
23+ print ("---------------------`--------------------------" );
24+ print (tags);
2325 for (Match m in tags) {
26+ print (m.group (0 ));
2427 String match = m.group (0 ).replaceAll (new RegExp ("\n " ), "\n\r <br>" );
28+ print (match);
2529 mdDataCode = mdDataCode.replaceAll (m.group (0 ), match);
2630 }
2731
28- exp = new RegExp ("<pre(([\s \S ])*?)<\/ pre>" );
32+ exp = new RegExp ("<pre(([\\ s \ \ S])*?)<\/ pre>" );
2933 tags = exp.allMatches (mdDataCode);
3034 for (Match m in tags) {
3135 if (m.group (0 ).indexOf ("<code>" ) < 0 ) {
@@ -34,7 +38,7 @@ class HtmlUtils {
3438 }
3539 }
3640
37- exp = new RegExp ("<pre>(([\s \S ])*?)<\/ pre>" );
41+ exp = new RegExp ("<pre>(([\\ s \ \ S])*?)<\/ pre>" );
3842 tags = exp.allMatches (mdDataCode);
3943 for (Match m in tags) {
4044 if (m.group (0 ).indexOf ("<code>" ) < 0 ) {
@@ -202,4 +206,49 @@ class HtmlUtils {
202206 }
203207 return builder;
204208 }
209+
210+
211+ static resolveHtmlFile (var res, String defaultLang) {
212+ if (res != null && res.result) {
213+ String startTag = "class=\" instapaper_body " ;
214+ int startLang = res.data.indexOf (startTag);
215+ int endLang = res.data.indexOf ("\" data-path=\" " );
216+ String lang;
217+ if (startLang >= 0 && endLang >= 0 ) {
218+ String tmpLang = res.data.substring (startLang + startTag.length, endLang);
219+ if (tmpLang != null ) {
220+ lang = formName (tmpLang.toLowerCase ());
221+ }
222+ }
223+ if (lang == null ) {
224+ lang = defaultLang;
225+ }
226+ if ('markdown' == lang) {
227+ return generateHtml (res.data, backgroundColor: GSYColors .miWhiteString);
228+ } else {
229+ return generateCode2HTml (res.data, backgroundColor: GSYColors .webDraculaBackgroundColorString, lang: lang);
230+ }
231+ } else {
232+ return "<h1>" + "Not Support" + "</h1>" ;
233+ }
234+ }
235+
236+ static formName (name) {
237+ switch (name) {
238+ case 'sh' :
239+ return 'shell' ;
240+ case 'js' :
241+ return 'javascript' ;
242+ case 'kt' :
243+ return 'kotlin' ;
244+ case 'c' :
245+ case 'cpp' :
246+ return 'cpp' ;
247+ case 'md' :
248+ return 'markdown' ;
249+ case 'html' :
250+ return 'xml' ;
251+ }
252+ return name;
253+ }
205254}
0 commit comments