| 38 | | [htmlSourceView setString:[(DOMHTMLElement*)[[[webView mainFrame] DOMDocument] documentElement] outerHTML]]; |
|---|
| | 38 | NSString *unformattedHTML = [(DOMHTMLElement*)[[[webView mainFrame] DOMDocument] documentElement] outerHTML]; |
|---|
| | 39 | |
|---|
| | 40 | unformattedHTML = [unformattedHTML stringByReplacingOccurrencesOfString:@"<br>" withString:@"<br/>"]; // This line saves us from having to do NSXMLDocumentTidyHTML. |
|---|
| | 41 | |
|---|
| | 42 | NSError *error = nil; |
|---|
| | 43 | NSXMLDocument *xmlDoc = [[[NSXMLDocument alloc] initWithXMLString:unformattedHTML options:0 error:&error] autorelease]; |
|---|
| | 44 | if (xmlDoc) { |
|---|
| | 45 | [xmlDoc setDocumentContentKind:NSXMLDocumentHTMLKind]; |
|---|
| | 46 | NSString *formattedHTML = [xmlDoc XMLStringWithOptions:NSXMLNodePrettyPrint]; |
|---|
| | 47 | [htmlSourceView setString:[formattedHTML substringFromIndex:1]]; |
|---|
| | 48 | } else { |
|---|
| | 49 | [htmlSourceView setString:[NSString stringWithFormat:@"ERROR\n%@\n\nSOURCE\n%@", error, unformattedHTML]]; |
|---|
| | 50 | } |
|---|