Fix for missing Bold and Italic styling!
-
I have finally found some time to have a good look at this – as it was starting to become a real issue that i was loosing the bold and italic styling.
So i have inspected the code and got my head around how the bold and italic tags ‘should’ be applied. After reading through all the documentation i could find i noticed in the changelog that the latest version of the bold and italic support was added in 0.4-beta. The function (dtwp_extract_styles) that does this is found at lines 10-37 of extend-clean.php. However i noticed that this function is not being called in the latest 1.1v!
So i have implemented a quick and dirty fix which seems to be working for me well! There is probably a much more elegant solution but with my extremely limited php experience i am more than happy i was able to get it working by myself :-).
To do this i have merged some of the extend-clean.php code into the main docs-to-wp.php code.
The dtwp_extract_styles function is looking to the stylesheet that comes from google for a selector that is applying the property font-weight:bold to work out the class name any then use the correct class name to wrap the relevant span content with a strong tag. And the same for italic.
So the function needs to have the unmodified raw markup passed to it. In the docs-to-wp.php this is available as the $raw variable. So swapping out the old $content variable for $raw in the dtwp_extract_styles function seems to have done the trick ??
I have inserted the following code into the docs-to-wp.php at line 120 (at the start of the _cleanDoc function):
//PHP doesn't honor lazy matches very well, apparently, so add newlines $raw = str_replace( '}', "}\r\n", $raw ); preg_match_all( '#.c(?P<digit>\d+){(.*?)font-weight:bold(.*?)}#', $raw, $boldmatches ); preg_match_all('#.c(?P<digit>\d+){(.*?)font-style:italic(.*?)}#', $raw, $italicmatches); if( !empty( $boldmatches[ 'digit' ] ) ) { foreach( $boldmatches[ 'digit' ] as $boldclass ) { $raw = preg_replace( '#<span class="(.*?)c' . $boldclass . '(.*?)">(.*?)</span>#s', '<span class="$1c' . $boldclass . '$2"><strong>$3</strong></span>', $raw ); } } if( !empty( $italicmatches[ 'digit' ] ) ) { foreach( $italicmatches[ 'digit' ] as $italicclass ) { $raw = preg_replace( '#<span class="(.*?)c' . $italicclass . '(.*?)">(.*?)</span>#s', '<span class="$1c' . $italicclass . '$2"><em>$3</em>', $raw ); } }
I hope this is useful for anyone else who is missing the bold and italic styling.
Matt
- The topic ‘Fix for missing Bold and Italic styling!’ is closed to new replies.