tinymce code inserting, can't get it to work - tinymce

I enabled codesample plugin https://www.tinymce.com/docs/plugins/codesample/
and to test it I entered just head tag like this
and it displays like this in the editor
when I save this to database it gets saved like this:
<pre class="language-markup"><code><head></code></pre>
When I reload the page all i get is this in the editor
<pre> </pre>
Database still looks like
<pre class="language-markup"><code><head></code></pre>
but there is no head tag visible in the editor. Any ideas why?

When placing raw HTML into a <textarea> you need to properly escape the HTML code that you are placing in the <textarea>. As you are not doing that the browser (and by proxy TinyMCE) is "cleaning up" the invalid markup as best as it can.
You can either:
Properly escape the HTML
Use the setContent() API to load your HTML
into TinyMCE (as opposed to injecting the HTML into the <textarea>)
I would personally suggest the second option above as it completely eliminates the vagaries of injecting HTML into a <textarea>.
If you want to try the first solution I listed above you might do something like this if you were using PHP
<?php
$content = "This string contains the TM symbol: ™";
print "<textarea>". htmlentities($content) ."</textarea>";
?>
Every language I have used has some equivalent to htmlentities().

Related

keycloak translation / message with link should open in new Tab

I would like to have a translation in my messages_en.properties containing a link, which opens in a new tab. Is there a way to do this?
I already tried to add
<a target="_blank" href="http://example.com">Example</a>
and
<a href="#" onclick='window.open("http://example.com");return false;'>Example</a>
without success.
Thanks in advance
Most likely your HTML isn't working because of kcSanitize in the template file. Wherever HTML messages are allowed, Keycloak's FreeMarker templates will also wrap the text with this method which:
Allows sanitizing of html that uses Freemarker ?no_esc. This way, html
can be allowed but it is still cleaned up for safety. Tags and
attributes deemed unsafe will be stripped out.
The no_esc allows HTML to render (by not being escaped) but the kcSanitize strips unsafe tags and attributes first. In my testing, I found that "target" and "onclick" are stripped out.
One way that works but that I wouldn't recommend for safety is removing the kcSanitize() around where your message displays in the corresponding .ftl file.
Another idea is adding an id or class to the element in your .properties file and using custom Javascript to set the target="_blank" attribute.

Netbeans: Syntax Highlighting -- multiple languages per file

The majority of the pages I author contain both HTML and PHP. It would appear that in Netbeans you can have syntax highlighting for one or the other by setting the associated file types.
Coming from Notepad++, I've always taken for granted the fact that I could use php, css, html, javascript all in one file and retain syntax highlighting for all of them.
Is this possible in Netbeans?
I think the answer here is that Netbeans DOES support multiple language, but it will only get it right if there's something hinting at the "inner" language. When I exit PHP with ?> NetBeans tends to format what comes before the next <?php as HTML automatically. Not sure if that is working for you. Maybe you were trying to get highlighting in a string like $output = "<some><html";. I think you can imagine why that second one wouldn't work.
For JS, for example, it seems to look for the <script type="text/javascript">, and stuff inside gets the JS highlighting even if the file type is PHP.
This other question has a great solution for "tricking" Netbeans into rendering your JS output by PHP into being formatted, even when your code doesn't have a <script type="text/javascript"> tag.

How do I simply embed HTML into a layout/template in Lift?

I am just starting out with Scala and Lift and I apologize ahead of time about this pretty basic question but how do I "import" or rather embed HTML file into a layout/template?
Basically I have a bunch of layouts and each of them has hard coded footer. I want to extract footer into a separate HTML and then reference it back in all layout files.
Check out the "starting" template for Lift: https://github.com/lift/lift_25_sbt/
In Lift Basic https://github.com/lift/lift_25_sbt/tree/master/scala_210/lift_basic you can see an example of a footer that can be put around many other HTML-s: https://github.com/lift/lift_25_sbt/blob/master/scala_210/lift_basic/src/main/webapp/templates-hidden/default.html
To use this footer, you access it like in https://github.com/lift/lift_25_sbt/blob/master/scala_210/lift_basic/src/main/webapp/index.html :
<div id="main" class="lift:surround?with=default;at=content">
Another link to read about this: http://simply.liftweb.net/index-3.3.html#toc-Subsection-3.3.3
BTW, starting with the lift_basic github template is a good idea anyway.
If you are just looking to pull in an HTML file, like a footer, you can use the embed snippet, as specified here.
So, if you have a file in the root of your webapp named footer.html, you can embed it with this code:
<div data-lift="embed?what=/footer"></div>
The templating engine will also allow you to use other directives like surround if you want to insert content at a particular point in the middle of an existing HTML file.

jQuery Tmpl removes TR tag content when not wrapped by TABLE tag

Upon migrating my old web interface with extensive use of jQuery Tmpl, some of my templates have ceased to work. Further investigation shows that the templates not working are the ones starting and ending with TR tags (i.e. table rows getting appended to an existing table). The source text just gets removed by the jQuery Tmpl script! If I use the TR tags in a broader context like wrapped in a table etc everything works just fine, but as soon as they are used in an isolated template, they get wiped out.
working example:
<script id="workingTemplate" type="text/x-jQuery-tmpl" >
<table>
<tr><td>this works</td></tr>
</table>
</script>
not working example:
<script id="notWorkingTemplate" type="text/x-jQuery-tmpl" >
<tr><td>this does not work</td></tr>
</script>
The first example renders the full HTML code when checking with Firebug, the latter renders an empty SCRIPT tag.
The difference between the old and the new web interface that could in any way be related to the templating is a change from jQuery 1.5.2 to 1.8.2. I haven't tried running anything below 1.7.2 since this is where the .on() function got added, and the new framework has an extensive use of this method.
Are there any workarounds for this problems except the most obvious (= changing templating framework to something still maintained)?
EDIT:
When loading the template from a string, the content stays intact,
$.template( "tableRowTemplate",'<tr><td>this works</td></tr>');
$.tmpl("tableRowTemplate", data).appendTo('TABLE#mytable TBODY');
but is unfortunately no good for me since my templates are a tad more complicated than the examples (server side dynamics etc...). It does give some hints though. Obviously, it is the initialization of jQuery Tmpl that removes the content if it does not comply with something to me unknown. Maybe jQuery.fn.domManip?

GWT : How to Read Hidden Box value?

I Have a hidden box in my HTML. How I can get it value in my GWT when onModuleLoad??
the hidden box will content a value pass from another page. Now I can see the hidden box content the value but I fail to get the value in my GWT onModuleLoad.
HTML page:
<%
String sSessionID=request.getParameter("NA_SessionID");
if(sSessionID==null)
session.setAttribute("NetAdminSession",(String)session.getAttribute("NetAdminSession"));
else
session.setAttribute("NetAdminSession",sSessionID);
%>
<form name=frmMain method=post>
<input type=hidden name=NA_SessionID name=NA_SessionID value="<%=(String)session.getAttribute("NetAdminSession")%>"></input>
</form>
You can access any element in the DOM by using the GWT DOM Class. For example, if your hidden box has the id "NetAdminSession", you may use the following to access the hidden box...
DOM.getElementById("NetAdminSession");
To: Geoffrey Wiseman
my HTML file is in the GWT HTML.. but I change it to JSP file instead of HTML
To: prometheus
Thanks you information, I will give it a try now.
I'm not sure what your overall approach/architecture is, but it might also be helpful to look into some of the new features added in GWT 2.0. Specifically, Declarative Layout with UIBinder. With this you can actually construct your user interface with declarative XML instead of using pure Java. I would steer away from creating too much of your UI in the actual HTML file since it will be easier to control those UI elements if you construct them in your GWT code. You can still stick to good MVC principles if you break your classes/code up the right way.