ckeditor removes new line characters from source - ckeditor

Using CKEditor 4.9.2 on a textarea, which already has content, separated by new lines (\r\n). When the CKEditor instance loaded, these new lines were removed like this:
<textarea name="message" >
row 1 text text text
row 2 text text text text text text
row 3 text text
row 4 text
row 5
</textarea>
I can't convert them to <br> tags, have to work with \r\n characters.
How can I keep the \r\n characters?

You can't preserve new line character in CKEditor, it is not regular textarea. It is displaying your content by using html elements on page and it cant work like you want.
Easy solution I can suggest would bo to replace all new lines with <br>.
editor.on( 'setData', function(event) {
event.data.dataValue = event.data.dataValue.replace( 'your regexp', '<br>' );
} );
And then after getting editor data, just replace each <br> with new line character.

Related

inDesign extract special objects form plain text paragraph

i'm trying to find a way to get only the plain text contained in a paragraph, and exclude the special objects contained in the para.
This is an example of my case.
I have this paragraph, obtained with app.activeDocument. :
paragraph , which contains 2 graphics before the plain text.
I achived this by doing:
var style = app.activeDocument.paragraphStyles.item("My Para Style");
app.findTextPreferences.appliedParagraphStyle = style;
var list = app.activeDocument.findText();
If I print the paragraph contents by list[0].paragraphs[0].contents, this is what is written: printed paragraph.
How can I extract and replace only the plain text from this paragraph leaving the first 2 objects?
Thanks
Try list[0].paragraphs[0].texts and loop through the array of texts to put it together

CKEDITOR 4 Inline mode Toolbar in LI contenteditable

In CKEDITOR 4 I'm using the inline mode
I have a BulletedList with <ul contenteditable="true">
and when I press ENTER I can't not create a new LI with a <P contentenditable="true"> children to have the toolbar for format text options.
Here the JSFIDDLE
And here the list plugin source
You cannot build your editor on <ul> element because CKEditor wasn't designed to work like that. You can find the list of editable elements by calling CKEDITOR.dtd.$editable in your console:
CKEDITOR.dtd.$editable
>>> Object {address: 1, article: 1, aside: 1, blockquote: 1, body: 1…}
You can wrap your list in div element, make it editable and strip out when retrieving data. There's a simple example of how to modify elements on editor output. You'll need to return false when your div is processed. This is it.
You can also do this with RegExp but I don't find it gentle ;)

jquery send action on focus and view lines of text

ie. we have page with many lines of text
<div class="textline" id=line1>text line or line with image no reason</div>
<div class="textline" id=line2>text line or line with image no reason</div>
<div class="textline" id=line500>text line or line with image no reason</div>
How to get last really visible lineID on the screen of visitor(not on whole page) and send this ID to server with jquery?
1) first time send - when page get focused more then 5 seconds (really viewed), need to send last visible lineID from the screen of visitor.
2) when page scrolled down need to send last visible line (think with some little timeout)
Is it possible with jquery? Any examples?
Grab the last element from a list of .textline elements.
Example:
$(".textline").last();
Or, if you want to select the last element visible on the screen in the viewport, you'll have to do something a lot more complex, like this:
$(".textline").each(function() {
var offset = $(this).offset().top - $(window).scrollTop();
if(offset <= window.innerHeight - $(this).height){
// it's the last visible line, do something with it.
// you can put a call to your server containing the
// line's current text with something like this:
// var curText = $(this).val();
}
}
this selects last .textline:
$('.textline').last().text()

Vaadin : My label ignores the carriage return character

I have an incoming text string that contains a line break ("\r").
When I output it with : System.out.println(myString), the carriage return is interpreted.
However, when I set the string as the Label's content, it ignores the carriage return.
How can I force the Label to interpret the carriage/line return (without the XHTML mode) ?
This is how you can put this text into your label:
#Override
public void init() {
Window window = new Window();
Label label = new Label("<pre>First line\rSecond line\nThird line</pre>", Label.CONTENT_XHTML);
window.addComponent(label);
setMainWindow(window);
}
The key is using Label.CONTENT_XHTML content mode and enclosing the text inside a <pre> tag.
In Vaadin 7.0 you can use ContentMode.PREFORMATTED e.g.:
String resultText = "First line\rSecond line\nThird line";
Label dateLabel = new Label( resultText, ContentMode.PREFORMATTED );
and if you want text to look sexy you can use some themes, something like:
dateLabel.setStyleName( Runo.LABEL_SMALL );
That should work and is elegant as well.
After reading The book of Vaadin, and few tests, I don't think \r can be interpreted by the Label.
Replacing \r with \n gives you two options :
Label.setContentMode(Label.CONTENT_XHTML). //But you don't want to do this
Label.setContentMode(Label.CONTENT_PREFORMATTED) //But I think it's not the display you want
Regards.
Éric

Bizarre hidden character in MVC3 Razor loop

I have a loop
<ul id="news-list" class="thumbobs-list">
#foreach (var item in Model.News) {
#Html.Partial("RenderNews/" + item.TypeString, item)
}
</ul>
that uses partials like this
#model Web.Models.DataModel.NewsItem
#{ Layout = null; }
<li class="news-item #Model.TypeString.ToLower()" id="id-#Model.Id">
<h3 class="headline">
Example News headline.
</h3>
<p class="timestamp">#Model.TimeString</p>
</li>
that works great
but when i went to style with css i encountered a hidden whitespace character that is causing an issue
in front of each partial a space, a U+FEFF, and another space causing issues with the design.
has anyone ever seen this?
You have discovered the BOM, Byte Order Mark. It's stored as the first bytes in text files to indicate the encoding.
http://en.wikipedia.org/wiki/Byte_order_mark
[EDIT]
You can open a file with Notepad and "Save As..." as ANSI. This removes the BOM (and the encoding).
// reading a text file as binary will include the BOM flag
FileStream FS = new FileStream(MapPath(#"~\Text\TestUTF8.txt"), FileMode.Open);
byte[] Data = new byte[100];
FS.Read(Data, 0, 100); // BOM is in the data
FS.Close();
// get rid of the BOM
String String1 = System.Text.Encoding.UTF8.GetString(Data);
// reading a text file as text will automatically handle it.
String String2 = File.ReadAllText(MapPath(#"~\Text\TestUTF8.txt"));
Try copying the text out and create a new partial view. Paste it into notepad and rebuild your partial to rule out this character being hidden in your partial or simply load it on the vs binary editor and look for that character. Right click and open with... Then choose binary editor.

Resources