0

I'm using this in my wysiwyg to replace

< pre> Hi my name is< /pre>

with

< div id="precode">Hi my name is< /div>

This is the working code code

v=v.replace(/<pre>(.*)<\/pre>/gim,'<div id="precode">$1</div>');

This works fine unless the string contains a < br>

EDIT This is the code

if(div){div.innerHTML=this.obj.toggletext||'Spell Check'}
$('#spellcheck_words').slideToggle('slow', function() { }); 
if(this.xhtml&&!this.ie){
v=v.replace(/<strong>(.*)<\/strong>/gi,'<span style="font-weight: bold;">$1</span>');               
v=v.replace(/(<img [^>]+[^\/])>/gi,'$1/>')
v=v.replace(/<em>(.*)<\/em>/gi,'<span style="font-weight: italic;">$1</span>')
}

EDIT

2
  • 1
    You're supposed to phrase your question as a... question Commented Sep 20, 2011 at 22:16
  • Sorry, I will keep that in mind Commented Sep 20, 2011 at 22:18

3 Answers 3

4
$('pre').replaceWith('<div>'+$(this).html()+'</div>');
Sign up to request clarification or add additional context in comments.

Comments

3

use

$('pre').replaceWith('<div>'+$(this).html()+'</div>');

so html gets passed over.

Comments

2

Or:

v=v.replace(/<pre>((?:.|[\r\n])*)<\/pre>/gim,'<div id="precode">$1</div>');

Problem is not with <br/>, but with new-line characters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.