J
Joose Niemi
I'm using a JavaScript-based HTML-editor for writing documentation and
such and I need to be able to use <PRE>-tag for SQL- and code-examples.
Inside the <PRE>-area I have to use Shift+Enter for <BR>-linebreaks.
When I save the iframe-content to a database and reload the page with
the new content, the <BR> tags inside the <PRE> have created two linebreaks.
Short example with IE. This is what I enter inside the PRE-element:
"
Important code which needs to<Shift+Enter>
have linebreaks.
"
It generates this markup:
<PRE>
Important code which needs to<BR> have line breaks.
</PRE>
After reloading I have:
<PRE>
Important code which needs to<BR>
have line breaks.
</PRE>
And the rendered end result is:
"
Important code which needs to
have linebreaks.
"
While I would obviously like to have:
"
Important code which needs to
have linebreaks.
"
Firefox behaves similarly, but it also changes all newlines to <BR>
So, in essence, this is what I would like to have:
1. Have Shift-Enter to enter \n newlines inside <PRE>-elements
2. When loading content replace all <BR> tags inside <PRE>-areas to \n
newlines
Otherwise I can't see how am I going to be able to do any code examples
using any "designmode"-editor.
I won't be able to supply a full working test URL, but I'm hoping the
code below will be enough.
<iframe src='' id='EditorContent' frameborder='0'></iframe>
The rest is simplified IE-only code, though I have this thing working on
Gecko-browsers as well. Obviously I would like to
var IE holds the result of the browser-detection code.
var MyEditor = "EditorContent";
Editor = document.frames[MyEditor].document;
Editor.designMode = "on";
Editor.attachEvent("onkeydown", KeyPress);
....
function KeyPress(Event) {
if(IE) {
if(!Event) var Event = window.event;
if(!Event) return true;
var Key = Event.keyCode;
if(Key == 13) {
var FontFormat = Editor.queryCommandValue('formatBlock');
if(FontFormat == "Formatted" && Event.shiftKey) {
// Replace the <BR>-tag with a \n newline ?
}
}
} else {
// gecko handling
}
}
Thanks for help.
such and I need to be able to use <PRE>-tag for SQL- and code-examples.
Inside the <PRE>-area I have to use Shift+Enter for <BR>-linebreaks.
When I save the iframe-content to a database and reload the page with
the new content, the <BR> tags inside the <PRE> have created two linebreaks.
Short example with IE. This is what I enter inside the PRE-element:
"
Important code which needs to<Shift+Enter>
have linebreaks.
"
It generates this markup:
<PRE>
Important code which needs to<BR> have line breaks.
</PRE>
After reloading I have:
<PRE>
Important code which needs to<BR>
have line breaks.
</PRE>
And the rendered end result is:
"
Important code which needs to
have linebreaks.
"
While I would obviously like to have:
"
Important code which needs to
have linebreaks.
"
Firefox behaves similarly, but it also changes all newlines to <BR>
So, in essence, this is what I would like to have:
1. Have Shift-Enter to enter \n newlines inside <PRE>-elements
2. When loading content replace all <BR> tags inside <PRE>-areas to \n
newlines
Otherwise I can't see how am I going to be able to do any code examples
using any "designmode"-editor.
I won't be able to supply a full working test URL, but I'm hoping the
code below will be enough.
<iframe src='' id='EditorContent' frameborder='0'></iframe>
The rest is simplified IE-only code, though I have this thing working on
Gecko-browsers as well. Obviously I would like to
var IE holds the result of the browser-detection code.
var MyEditor = "EditorContent";
Editor = document.frames[MyEditor].document;
Editor.designMode = "on";
Editor.attachEvent("onkeydown", KeyPress);
....
function KeyPress(Event) {
if(IE) {
if(!Event) var Event = window.event;
if(!Event) return true;
var Key = Event.keyCode;
if(Key == 13) {
var FontFormat = Editor.queryCommandValue('formatBlock');
if(FontFormat == "Formatted" && Event.shiftKey) {
// Replace the <BR>-tag with a \n newline ?
}
}
} else {
// gecko handling
}
}
Thanks for help.