[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] p tags in docs




On 19 Dec 2008, at 09:43, Scott Wilson wrote:

This looks pretty good. Main help is obviously a special case, but have you tried it with any more complicated help files?

If it works with those and there are no objections, I can add it to the OSX app and produce a patch for testing. 

Something like this:

void pTagsToDivTags(NSMutableString* html) {

NSRange styleOpen = [html rangeOfString: @"<style"];
NSRange styleClose = [html rangeOfString: @"</style>"];

if(styleClose.location != NSNotFound) {
// classes to IDs
NSRange searchRange = NSMakeRange(styleOpen.location, styleClose.location - styleOpen.location); 
NSUInteger replacements = [html replaceOccurrencesOfString:@"p.p" withString:@"#p" options:NSCaseInsensitiveSearch range:searchRange];


// now replace all <p> tags with <div>
if(replacements > 0) {
NSRange bodyOpen = [html rangeOfString: @"<body"];
NSRange bodyClose = [html rangeOfString: @"</body>"];
searchRange = NSMakeRange(bodyOpen.location, bodyClose.location - bodyOpen.location);
[html replaceOccurrencesOfString:@"<p class=" withString:@"<div id=" options:NSCaseInsensitiveSearch range:searchRange];


searchRange = NSMakeRange(bodyOpen.location, [html rangeOfString: @"</body>"].location - bodyOpen.location);
[html replaceOccurrencesOfString:@"</p>" withString:@"</div>" options:NSCaseInsensitiveSearch range:searchRange];
}
}
}