Getting the content of paragraph in tinymce - tinymce

Is it possible to get the content of a clicked paragraph in tinymce? If yes, how?
For ex: I have paragraph as shown below
I will use '|' to denote cursor
<p>123</p>
<p>45|6</p>
<p>789</p>
I should get output as
<p>456</p>
Any help would be appreciated.....

I believe this will do what you want:
tinymce.activeEditor.selection.getNode()
Take a look at this TinyMCE Fiddle for an example of how you might do this: http://fiddle.tinymce.com/xAfaab

Related

How to display newline in TimelineItem control's text property?

We have a SAPUI5 timeline control, where we are showing the comments coming from server.
The issue is, if the comments contain a newline \n, then the Timeline control is not able to display the text in newline. Instead, it introduces space wherever \n is present.
We have tried formatting \n to unicode character also but that also didn't worked. Timeline control aggregates TimelineItem.
The control we are using is: https://ui5.sap.com/#/api/sap.suite.ui.commons.TimelineItem
Code snippet can be found at:
https://jsbin.com/kuluyehilu/edit?html,output
I inspected your example and came up with the following solution.
Since the text is embedded in a <span>, all unnecessary whitespace will be trimmed. What you can do is telling the span (via CSS) that it should display the whitespace anyway.
If you don't have a CSS file in your project yet, create one. Then add the following lines
div.sapSuiteUiCommonsTimelineItemShellBody>span {
white-space: pre;
}
This should do the trick.
JSBin: https://jsbin.com/feladeneso/1/edit?html,output
If you inspect the rendered element, you will see it actually put in the break:
<span id="__item0-realtext">x
y</span>
...but did not convert it to a <br/> tag. You cannot add the tag yourself since it will be escaped, either. Maybe you can try to override the renderer, and convert any line breaks to html breaks

tinymce removes line breaks so all text is in a continuous chunk with no paragraphs

I'm using TinyMce textarea editor and have a problem. As you probably know Tinymce transforms a standard html textarea into a rich text editor.
On our 'edit listing' page we call up some text from our db for the user to edit (previously in a standard textarea, now in the tinymce textarea.
Previously the standard textarea would preserve linebreaks and the user would get several paragraphs of text in the text area, now with tinyMCE they get a huge chunk of text with no linebreaks. (I have pasted an example of an entry in our db below - as you can see it has line breaks in it by tinymce seems to be ignoring them when it displays them in the editor).
Just to clarify my issue is now that tinymce is stripping something when I submit the form, it's that when I pull text (that contains line breaks) from the db and populate the tinymce textarea with that data (for the user to edit) in the tinymce textarea - the text appears (in the tinymce textarea) as one massive chunk of text with my paragraphs (whereas in a standard textarea it is nicely formatted with linebreaks)
Any help on how to resolve this would be greatly appreciated - do I need to use some sort of populate() type function to put the text in, or maybe I need to replace all the linebreaks with a different special character that tinyMCE will recognise as a line break and preserve?..
Thanks in advance.
Nick
example from db:
Here is line one
Here is line two
And here is line three
Which appears in tinymce as:
Here is line one Here is line two And here is line three
I faced a similar a problem, a while back and had questions just like yours. Also I finally ended up on SE just like you.
Anyway, I think I have the solution to your problem. If you are using PHP as your server side language, then you should use nl2br() PHP function.
Suppose you have stored your content fetched from the database in a php variable. Something like this:
$content = $row['content'];
Now when displaying it on to your screen, use the nl2br() function.
echo nl2br("<p>".$content."<p>");
Now, this part inside () depends on how you want to output the data. And I will leave it to you to figure that part out.
Hope this helps.

Stop nicEdit from creating <p> tags?

I have nicEdit implemented in the backend for uploading news items, and in the frontend each newsitem has a square in front of the beginning of the text body (image attached). This only occurs in the first paragraph of the text.
Due to the paragraph tags added by nicEdit, the text is displayed on a different line than the square. I have searched in the nicEdit docs and in previously answered questions on here but could not find a solution. Is there any way to change the paragraph formatting in nicEdit to use br at the end of a paragraph instead of having it wrap the text with p tags? Or if not, to have Nicdit automatically add the square to the beginning of each text?
Thank you in advance for any help!!
http://i.stack.imgur.com/dxxtu.png
Edit: Turns out the p tags were not caused by the nicedit but by the users copy-pasting the articles. I have used this to remove formatting from pasted text, but the tags are still there (it seems to only remove font properties).
As a temporary fix I have added the square to the nicedit wysiwyg as initial text, so that it is sent to the db along with the rest of the text and inside the same paragraph.
I realized there's a line in the code you modified that specifies all the unwanted tags. You should add the paragraph there.
Search for
/* remove undwanted tags */
newSnippet = newSnippet.replace(/<(div|span|style|meta|link){1}.*?>/gi,'');
in the nicEditorInstance class, and change it to
/* remove undwanted tags */
newSnippet = newSnippet.replace(/<(div|p|span|style|meta|link){1}.*?>/gi,'');
Notice the "p" has been added. That will prevent nicEdit to wrap the paragraphs in tags.

How to bold / unbold tablix text with an expression?

I have an expression in a textbox of a tablix control:
="Rectification: " + Fields!MoreInfo.Value
What I would like to do is have the word 'Rectification:' in bold and the rest of the text unbolded. Unfortunately I've no idea how to do this.
I've tried the following (as per a suggestion from Google):
="<b>Rectification:</b> " + Fields!MoreInfo.Value
However this shows the tags in their literal form. It also appears that expressions on the bold context apply to the entire textbox and cannot apply to only some parts of it.
I believe you'll need to use placeholders to accomplish this.
Here's an excellent tutorial.

TinyMCE code highlighter select code to apply code highlight

I am looking for a tinymce code highlighting plugin that is easy for users to use.I want the users to highlight the code to code highlight and with a click of a button,the code is highlighted,like how stackoverflow does it,without resulting to
I'm sorry just a little confused?
Are you wanting search results to be highlighted when a user goes to a page from a search if so this is not TinyMCE it's Server side when you get the text from the database do a search and replace on the text with a background coloured span
E.G [PHP]
// with this example i'm assuming that you link to the post from search is in a get variable called searchTerm if you url_encode it you need to url_decode it.
$highlight = $_GET['searchTerm']; // section
$text = "this is a section of text"
$text = str_replace($highlight, "<span style='background-color:#666;'>$highlight</span>");
echo $text
If not can you clarify what you looking for?