diff --git a/contrib/mobile/iOS/Onelab/AboutViewController.mm b/contrib/mobile/iOS/Onelab/AboutViewController.mm index 42f0836cd7451f5a34d58047783bebc40c813a2f..5091e2359a54f2aee1e2cdc9fe5a20cc6696c211 100644 --- a/contrib/mobile/iOS/Onelab/AboutViewController.mm +++ b/contrib/mobile/iOS/Onelab/AboutViewController.mm @@ -40,7 +40,17 @@ NSData *fileData = [NSData dataWithContentsOfFile:self.fileToEdit]; NSString* aStr = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; if(!aStr) aStr = [[NSString alloc] initWithData:fileData encoding:NSASCIIStringEncoding]; - [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<html><body><pre contenteditable=\"true\">%@</pre></body></html>", aStr] baseURL:[[NSBundle mainBundle] bundleURL]]; + if(aStr){ + aStr = [aStr stringByReplacingOccurrencesOfString:@"<" + withString:@"<"]; + aStr = [aStr stringByReplacingOccurrencesOfString:@">" + withString:@">"]; + } + + // custom microlight.js for basic syntax highlighting + const char *js = "!function(a,b){\"function\"==typeof define&&define.amd?define([\"exports\"],b):b(\"undefined\"!=typeof exports?exports:a.microlight={})}(this,function(a){var k,l,m,b=window,c=document,d=\"appendChild\",e=\"test\",g=\"opacity:.\",n=function(a){for(l=c.getElementsByClassName(a||\"microlight\"),k=0;m=l[k++];){var n,o,r,s,t,f=m.textContent,h=0,i=f[0],j=1,p=m.innerHTML=\"\",q=0,u=/(\\d*\\, \\d*\\, \\d*)(, ([.\\d]*))?/g.exec(b.getComputedStyle(m).color);for(\"px rgba(\"+u[1]+\",\",u[3]||1;o=n,n=q<7&&\"\\\\\"==n?1:j;){if(j=i,i=f[++h],s=p.length>1,!j||q>8&&\"\\n\"==j||[/\\S/[e](j),1,1,!/[$\\w]/[e](j),(\"/\"==n||\"\\n\"==n)&&s,\'\"\'==n&&s,\"\'\"==n&&s,f[h-4]+o+n==\"-->\",o+n==\"*/\"][q])for(p&&(m[d](t=c.createElement(\"span\")).setAttribute(\"style\",[\"\",\"font-weight:bold;color:#00c;\",g+6,\"color: #a08;\"+g+8,\"font-style:italic;color: #b00;\"+g+8][q?q<3?2:q>6?4:q>3?3:+/^(If|Else|ElseIf|EndIf|Include|For|EndFor|Include|Macro|Return)$/[e](p):0]),t[d](c.createTextNode(p))),r=q&&q<7?q:r,p=\"\",q=11;![1,/[\\/{}[(\\-+*=<>:;|\\\\.,?!&@~]/[e](j),/[\\])]/[e](j),/[$\\w]/[e](j),\"/\"==j&&r<2&&\"<\"!=n,\'\"\'==j,\"\'\"==j,j+i+f[h+1]+f[h+2]==\"<!--\",j+i==\"/*\",j+i==\"//\",j+i==\"//\"][--q];);p+=j}}};a.reset=n,\"complete\"==c.readyState?n():b.addEventListener(\"load\",function(){n()},0)});"; + + [self.aboutView loadHTMLString:[NSString stringWithFormat:@"<html><head><script>%s</script></head><body><pre contenteditable=\"true\" class=microlight>%@</pre></body></html>", js, aStr] baseURL:[[NSBundle mainBundle] bundleURL]]; UIBarButtonItem *save = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveFile)]; [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects: save, nil]]; }