Skip to content

Instantly share code, notes, and snippets.

@karlwhite
Created March 15, 2016 14:12
Show Gist options
  • Save karlwhite/d5d7b70bd8676edb01c0 to your computer and use it in GitHub Desktop.
Save karlwhite/d5d7b70bd8676edb01c0 to your computer and use it in GitHub Desktop.
// Fix table-cells
NSArray *cells = [document nodesMatchingSelector:@"td"];
for (HTMLElement *cell in cells) {
NSString *align = [[cell attributes] objectForKey:@"align"];
// Replace center aligned cells with a centered span
if ( align && [align isEqualToString:@"center"] ) {
NSString *newContent = [[cell serializedFragment] stringByReplacingOccurrencesOfString:[cell innerHTML] withString:[NSString stringWithFormat:@"<span style=\"text-align:center\">%@</span>", [cell innerHTML]]];
htmlString = [htmlString stringByReplacingOccurrencesOfString:[cell serializedFragment] withString:newContent];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment