Changeset 309

Show
Ignore:
Timestamp:
07/03/08 09:28:55 (6 months ago)
Author:
wolf
Message:

[NEW] WebEdit?: pretty-print HTML output.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cocoa/WebEdit/MyDocument.m

    r308 r309  
    2727    [webView setEditingDelegate:self]; 
    2828     
    29     [[webView mainFrame] loadHTMLString:@"<html><head><title>title</title></head><body>body</body></html>" 
     29    [[webView mainFrame] loadHTMLString:@"<html><head><title>title</title></head><body><p>body</p></body></html>" 
    3030                                baseURL:nil]; 
    3131} 
     
    3636 
    3737- (void)webViewDidChange:(NSNotification*)notification_ { 
    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    } 
    3951} 
    4052 
  • trunk/cocoa/WebEdit/user-modify.css

    r308 r309  
    11body { 
    2         color:darkgreen; 
     2        /*color:darkgreen;*/ 
    33        -webkit-user-modify:read-write; 
    44}