TinyMCE code highlighter select code to apply code highlight - tinymce

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?

Related

Add HTML but not in text mode of TinyMCE

I have a big text and like to highlight words that are trademarks. So within this big CDATA node I need to grab for multiple words like "ACME Soda Chips" and make them red.
currently I do something like this in a TinyMCE plugin:
// almost ...
var foo = editor.getContent();
foo.replace('ACME Soda Chips', '<span class="douh">ACME Soda Chips</span>');
editor.setContent(foo);
My problem now is, that such HTML is displayed in Text-Mode (where you see the content as plain HTML) and also submitted therefor stored to the database.
But what I like to have is:
Highlight a word in the visual mode
Do not store my surrounding span somehow
Optional: Do not show that I used a span and CSS-class to highlight things.
Hint:
I may completely do this wrong - please help.
I read some other plugins and honestly I don't understand what they do.
Imagine the whole text as one single big CDATA part but I like to highlight a specific set out of it.

from sql, php generating msWord need to show a carriage return?

My PHP generates a Word document, but it will not render carriage returns. My CKEditor translates a carriage return into either,
<br>, or <div>asdf</div>
When the Word document is created, it will display those HTML tags, so I strip them out. What replacement code, character, ascii, or tag can I use so that when the page is rendered, it shows the text like it did in the Editor?
Current example - if you have the text "Don't jump off the" [then hit Enter, so that the next word is below it]...
"cliff." Instead, currently, that gets saved into SQL as:
Don't jump off the <br>cliff.
Don't jump off the <div>cliff</div>.
...depending on which browser is used. In the msWord output, any tags left in the content [exceptions to strip_tags function] get displayed literally in msWord. Or, if I replace the tags with ASCII 
 it displays that literally, too. Not sure if this helps, but this is defined at the top of my php report_generator.php file:
require_once '/var/www/PhpWord/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
include "/var/www/ncpcphp/NCPC_PHP_Functions.php";
DEFINE("WRITEtoFDOCS", "NO");
DEFINE("FDOCSDIRECTORY", "Contract Attachments");
DEFINE("MIMETYPE","application/vnd.openxmlformats-officedocument.wordprocessingml.document" );
Help - what can I use to cause the output to show the carriage return?
Thank you, Cindy. Your answer is a piece of the solution. My CKEditor saves carriage returns as either
<br>, <br />, or <div></div>
depending on which browser is used Chrome[div] or Firefox[br] - that goes into my msSQL. Yet, if my editor has turned-on an "Enter filter" [keycode-13] in order to prevent someone from enter-editing a [[Placeholder]] (ckeditor read-onlyplugin) then saved editor text strips out the Enter. So, I did this: kept in the enter filter because it is necessary, then after the text carriage returns are saved as br's or div's, when I run my report generator, I replace
<br>, <br />, and <div></div>
with "\n" like you said. Then I explode the text variable like this:
$show_cad = explode("\n", $show_cad);
foreach($show_cad as $line) {
$section->addText(htmlspecialchars($line));
}
The code in the editor needed to filter out the Enters only when Enter is pressed in the [[Placeholder]] plug in is more complex, and I got largely from CKEditor themselves. They request that I do not post their full solutions, but if you like I could show you pieces of it. Basically, I had to register the Placeholder widget. Then when Enter is pressed, it checks if the context is with Placeholder. If so, filter the Enter [then it disappears from the saved editor text], but if Enter is pressed elsewhere, it gets saved and used properly.
Thank you for your help!

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.

Add Variable Hyperlink in Mail Merge in Word 2013

I'm trying to add a hyperlink to a mail merge field. So something like this:
{HYPERLINK "{MERGEFIELD "Links" }"}
So I create a field like this.
{ MERGEFIELD Links }
And the above works (it displays different links for different recipients).
However, when I go to Edit Field, and then attempt to add HYPERLINK to { MERGEFIELD Links}, Word will not allow me. Meaning that when I type HYPERLINK followed by a space, the "variable" field is gone. Instead of word displaying...
LINK
it displays...
{HYPERLINK "{MERGEFIELD "Links" }"}
even after I press "update field". So Word is not letting me enter HYPERLINK for some reason.
How do I solve this?
From the Microsoft Web Site,
On the Insert menu, click Field (under Quick Parts in later office versions).
In the Field names list, click Hyperlink,
and then click OK. The text Error! Hyperlink reference not valid
appears in the document.
Press ALT+F9 to open the { HYPERLINK \* MERGEFORMAT } field code.
Put the insertion point after HYPERLINK and then add a space.
On the Insert menu, click Field. In the Field names list, click MergeField. In the Field name text box, type the name of the data source field that contains the hyperlink, and then click OK. For example, if the name of the data source field is "Address1," the field code appears as follows: { HYPERLINK { MERGEFIELD "Address1" } \* MERGEFORMAT }
Press ALT+F9 to close the field code. You now have Error! Hyperlink reference not valid text.
Put the insertion point at some arbitrary place in the middle of the Error! Hyperlink reference not valid text, and insert the text you want to appear. If you would like a merge field, insert that from the "Insert Merge Field" option on the menu.
Delete the remaining text of Error! ... before and after the text you want to keep.
Note: If your merge field only contains an identifier, with the URL to be provided as a static part of the merge document, this can work also. On Step 5, you will need to insert the URL text as well as the MergeField, for example:
{ HYPERLINK "https://www.myurl.com/EditForm.aspx?ID={ MERGEFIELD ID }" \* MERGEFORMAT }
I also have been struggling with this. What I found to be the key is creating the document from SCRATCH and not saving it before executing the mail merge. Here are the steps I used:
open a new document and click on the step by step mail merge wizard; add your generic text.
To add the variable hyperlink go to insert>quick parts>fields
select hyperlink on the left and click okay
Use alt + F9 to see the hyperlink field code
Type “” and between them insert your merged field so that {HYPERLINK \* MERGEFORMAT} -> becomes {HYPERLINK"{MERGEFIELD"Constructed_URL"}"\*MERGEFORMAT}
Press ALT+F9 to hide the field code
Click in the text "Error! Hyperlink reference not valid" and replace with something generic like click here.
Complete the mail merge BEFORE you save the document.
Hope this helps and good luck!
Start with the process here:
http://support.microsoft.com/kb/912679
However, like user1867326 indicated, the hyperlink (which should be variable with the mail merge) is converted into a static link when the Word file is reopened.
A solution that seems to work is adding a bookmark within the hyperlink field code immediatly after the mergefield.
{ HYPERLINK { MERGEFIELD "Link" } \* MERGEFORMAT }
Click between the } and \ and go to INSERT > Bookmark, give it a name, and this seems to prevent Word from replacing the mergefield with a static hyperlink.
This answer is adapted and hopefully clarified from the clever solution described here:
Mailmerge dynamic hyperlink fields lost after save/reload of document - Word 2010
This is what worked for me for an email mail merge with variable hyperlinks that all display the same text. I am using Office 2016 Word.
Put the insertion point where you would like the link display text to be in the document.
On the Insert menu, click Quick Parts, and select Field.
In the Field Names list, click Hyperlink, and then click OK. The text Error! Hyperlink reference not valid appears in the document.
Press ALT+F9 to open the { HYPERLINK * MERGEFORMAT } field code. 5. Put the insertion point after HYPERLINK.
On the Insert menu, click Quick Parts, and select Field. In the Field Names list, click MergeField.
In the Field name text box, type the name of the data source field that contains the hyperlink, and then click OK. For example, if the name of the data source field is "Address1," the field code appears as follows: { HYPERLINK { MERGEFIELD Address1 } * MERGEFORMAT }
Press ALT+F9 to close the field code. You now have Error! Hyperlink reference not valid text.
Put the insertion point just before the period in ‘Error! Hyperlink reference not valid text.’ and delete all the text except for the period. Write in the link display text. Make sure not to delete the period (this is important).
To check that the hyperlinks are mapping, right click on the link display text and click edit hyperlink. You will see the correct link in the address field for each record.
I like to style the period text color to white so it looks invisible.
I have had limited success with the other suggestions - basically, Word is buggy in this area. There is a simple alternative - indeed the only alternative AKAIK if you want the hyperlink to vary AND the text that is displayed to vary too (not an unreasonable requirement).
Note that this only works for DOCUMENT MERGES, not for EMAIL MERGES, since it relies on processesing the output document.
The trick is to add a place marker (text that serves as an ID) wherever you want a hyperlink. Insert this via a regular mergefield. In your table of source data, you need columns
place marker, text_for_display, hyperlink
You then need to put your source data into Excel (if that isn't where you have it already) and put this formula
="Set Rng = ActiveDocument.Content: Rng.Find.Execute FindText:="""&[place marker]&""": ActiveDocument.Hyperlinks.Add Anchor:=Rng, Address:="""&[hyperlink]&""", TextToDisplay:="""&[text_for_display]&""""
into a blank column in the first row, and fill down.
You need to amend [place marker],[hyperlink] and [text_for_display] to the appropriate cell references.
If the [hyperlink] includes a query string, you may find you want to build it using a formula, based on other data in the source.
The resulting formulae can then be pasted into a macro and run on the output document.
You may then want to use the "Robbins/Mayor" macro http://www.wordbanter.com/showthread.php?t=18346 to split the generated documents.
I got this working thanks to this thread, but then it stopped working and I figured out why so I thought I'd say thanks by posting what I discovered here.
The issue is that word has a special type of curly brace. Copying the code text from this thread may not work for that reason. To get the curly braces Word wants, I used Fn + Command + F9 on my Mac running Catalina and Office 365. Apparently some Mac users may find Command + F9 works -- just test to find out. I'm sure Windows has a similar keystroke set. I found the Mac solution in this post.
Also, the syntax that works for me is: { HYPERLINK { MERGEFIELD "url" } * MERGEFORMAT } where "url" is the label of the column with the link in my Excel file. Note the position of the quotes. This differs from other posts here (I tried the other combinations) but I wouldn't be surprised if the syntax may vary across Word versions and operating systems.
To get this method to work in Mac Office 365 (Big Sur), you need to know about the Toggle Field Codes in the context menu. The shortcut above to replicate the Alt-F9 behavior will create a new field, instead of allowing you to edit the field that exists.
At these steps:
Press ALT+F9 to open the { HYPERLINK * MERGEFORMAT } field code.
OR
Press ALT+F9 to close the field code. You now have Error! Hyperlink reference not valid text.
Instead of the keyboard shortcut, right click on the error message and select Toggle Field Codes from the context menu.
Answer worked great for me with this adjustment! Thank you!

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.