Jump to content

using \n


optikalefx

Recommended Posts

so i have a webpage that basically when you click a button it replaces BODY with a textnode of the innerHTML.  Basically a view source.

 

Problem is, that it shows all the HTML gumbled up.  So how could i put in line breaks?  Maybe make use of the splitText function?

Link to comment
Share on other sites

ok this is making me angry

function viewHTML() {
   var html = editDoc.body.innerHTML;
   html = html.replace(/\n/g,"");
   html = html.replace(/>/g,">\n\r");
   var view = editDoc.createTextNode(html);
   //view.style.width = editDoc.body.clientWidth;
   //view.style.height = editDoc.body.clientHeight;
   //view.innerHTML = html;
   editDoc.body.parentNode.replaceChild(view,editDoc.body);
}

 

so the replace functions do work to replace all occurences of a character. BUT id like it not to be a textarea, because im useing document.designMode as well.  so i want it to be in a DIV or something.  So i trie dthis

 

function viewHTML() {
   var html = editDoc.body.innerHTML;
   html = html.replace(/\n/g,"");
   html = html.replace(/>/g,">\n\r");
   var view = editDoc.createElement('DIV');
   view.style.width = editDoc.body.clientWidth;
   view.style.height = editDoc.body.clientHeight;
   view.innerHTML = html;
   editDoc.body.parentNode.replaceChild(view,editDoc.body);
}

 

but that just recreates the body so i escaped it

 

function viewHTML() {
   var html = editDoc.body.innerHTML;
   html = html.replace(/\n/g,"");
   html = html.replace(/>/g,">\n\r");
   var view = editDoc.createElement('DIV');
   view.style.width = editDoc.body.clientWidth;
   view.style.height = editDoc.body.clientHeight;
   view.innerHTML = escape(html);
   editDoc.body.parentNode.replaceChild(view,editDoc.body);
}

 

but that puts a ton of %20s and stuff and doesnt react to the replaces \n's an ahhhhhh

 

i just want

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.