I inherited a Wordpress site with a few years worth of Textile markup in image captions. Rather than stripping them out I'd like to use some jQuery to turn italics that have been marked up like this:
Hello this is some _italic text_ here.
to this
Hello this is some <em>italic text</em> here.
Thanks, here is what I tried, based on the answers below.
<script type="text/javascript">
jQuery().ready(function() {
jQuery("p.wp-caption-text").each(function(n) {
this.innerHTML = this.innerHTML.replace(new RegExp("_([^{]*)_"), "<i>$1</i>");
});
});
</script>
It works, but in my markup sometimes it doesn't seem to find the second _ character.
Here is a real-world example:
<p class="wp-caption-text">Left: Paul Klee, _Grosses Tier (Large Beast)_, 1928; fractional and promised gift of the Djerassi Art Trust. Right: Andrew Schoultz, _Three Caged Beasts_, 2011; Courtesy the artist and Marx & Zavattero; © Andrew Schoultz</p>
For this one, it produces this:
<p class="wp-caption-text">Left: Paul Klee, <i>Grosses Tier (Large Beast)_, 1928; fractional and promised gift of the Djerassi Art Trust. Right: Andrew Schoultz, _Three Caged Beasts</i>, 2011; Courtesy the artist and Marx & Zavattero; © Andrew Schoultz</p>
Any idea how the regexp could be modified to fix this?
Try this:
if you have a lots of text to make as intalic,you must use the "g" flag in you regexp to get all matches.