CKEditor - how to save and display html code in rich text - html

I had html textarea's with plain text, there are html code samples stored in MySQL.
I changed textarea's to ckeditor class. All is fine, but all html code blocks are not displayed now in rich text mode.
I've tried to use <pre> and <code> tags, but they are don't work.
Also I tried insertpre plugin, and it doesn't help.
Is there a way to display/save html code in CKEditor? How to ignore html tags in the block like on this site with Code Sample button?
My example.(Sorry, have no permissions to post images yet).
Textarea field:
<textarea class="ckeditor" name = "description" >Text</textarea>
I'm pasting code using "Insertpre" addon:
<table border="1">
<tr>
<td>100</td>
</tr>
</table>
At once I see correct picture.
After form submit I get variable:
$description=$_POST['description']; and put it to database.
In database I see next value for this variable:
<pre class="prettyprint">
<table border="1">
<tr>
<td>100</td>
</tr>
</table></pre>
html form which displays data from base:
<textarea class="ckeditor" name = "description" ><?php echo $description ?></textarea>
When I open this form, I see empty code block, all html code is outside of pre-block, and I see a real table instead of html tags.
If I click on “Source” button , I see the same – table tags are not inside “pre” tags:
<pre class="prettyprint">
</pre>
<table border="1">
<tbody>
<tr>
<td>100</td>
</tr>
</tbody>
</table>
As I understand, code saved in database in correct format, so problem somewhere in the output or in CKEditor behavior...
Update: Found workaround:
After long search I found similar problem in this topic: http://ckeditor.com/forums/CKEditor-3.x/html-code-pre-tags-problem
Described workaround helped me: if I make output with htmlspecialchars php function it works good:
<textarea class="ckeditor" name = "description" ><?php echo htmlspecialchars($description) ?></textarea>
I'm not sure is it a workaround or correct solution - after this all tags inserted in rich mode are displayed even without "pre" block. If yes - it should be in CKEditor FAQ, because this is very confusing.

May be I'm late. But it will be good to share a solution that worked for me for the same problem so it might help someone.
I was having a similar problem with ckeditor, I saved the user inputs in my table and when I wanted to display the saved html in ckeditor instance it would simply ignore the html and display nothing.
So I inspected the html on my console and found that it has \r\n. So I just removed them and when I served it back to the ckeditor after escaping the html, it worked.
Here is my ruby code:
html = "<p>Content comes here</p>\r\n"
In my view
CKEDITOR.instaces.my_editor.setData("#{raw(html.gsub('\r\n',''))}")
And it worked. Hope that helps.

Related

HTML whitespace issue

My web application has started creating nodes for all the whitespace in my html file.
This code:
<td hidden>
<input type="text" hidden name="lines[{{$i}}][id]" id="lines[{{$i}}][id]"
value="{{$line->id}}">
</td>
is resulting in the td node having 3 children, two texts and the input.
Please see this image:
There I have console.log'd the element. I am not aware of how I have caused this to happen? I am using the PhpStorm IDE. I do not know what terms I would search in google to find an answer either.
edit: it seems to be the indenting. Is the web browser supposed to render indenting?
Thank you,

HTML - Either browser or handlebars is removing / ignoring a <table><tr><td> tag

I have a table class that I use to vertically centralise text in a span or div. I am using Handlebars in Node to render several templates server side, I have used this method on several partials in my web project, with no problems.
However in one particular partial / area of markup, either the browser or Handlebars is ignoring or removing the table, tr and td tags, showing only the text that is inside the tags.
In the past when this has happened it was because my tags were incorrect. However I have cross checked this code with my other markup where the table tags do show (in other partials), so I can't see where the problem is, and I can't find any suitable online topic about this (it is probably something really obvious that will make me look like a dummy).
I have tried in Chrome and Edge. I have also tried saving the markup snippet in a .html file (as opposed to a .hbs file) and opening that in the browser, and by doing this it does show the table tags. The consequence of this error is that I am unable to vertically align the text in the span. I am not sure if the markup is invalid according to the browser or Handlebars, but I am not using any {{Handlebars}} tags here so it shouldn't warrant the table tags to be invalid.
Markup:
<div class="lp-menuselector" title="View summary of Individual Learning Plan and evidence pack">
<div class="lp-menuselector-iconholder">
<img src="icons/icon_lp-overview.svg"/>
</div>
<span class="lp-menuselector-textholder">
<table class="tablecellleftalign">
<tr>
<td>
ILP Overview
</td>
</tr>
</table>
</span>
</div>
Output markup shown in Chrome Developer Tools / Elements:
<span class="lp-menuselector-textholder">
ILP Overview
</span>
Topic Closed:
After I restarted my computer and restarted the Node application, this error no longer occurs. Glitches in the matrix.

Extract information from web page throughExcel vba

I have the following html code
<tr>
<td class="fontblue" style="height: 17px">
Primary Industry Code
</td>
<td class="fontlightblue" style="height: 17px" colspan="4">
<span id="ucOrganisationDetail_lblVPrimarySector">
FMP CB:Miscellaneous Manufacturing
</span>
</td>
</tr>
I would like to extract the text FMP-CB Miscellaneous Manufacturing using getelementbyID option in vba. can anyone please help me
I tried using the below vba code but nothing is working
objIE.Document.getElementByID("ucOrganisationDetail_lblVPrimarySector").Value
Try the following:
objIE.Document.getElementByID("ucOrganisationDetail_lblVPrimarySector").innerHTML
You want .innerText as mentioned in comments I see.
.innerText
Sets or returns a String that represents the text between the start
and end tags of a specified object without any associated HTML.
expression.innerText
expression Required. An expression that returns one of the objects
in the Applies To list.
You could use
objIE.Document.getElementById("ucOrganisationDetail_lblVPrimarySector").innerText
or a CSS selector which says the same thing of:
objIE.Document.querySelector("#ucOrganisationDetail_lblVPrimarySector").innerText
The element is correctly selected as you can see with:

Form Within A Form & Table Not Appearing

I have a form within a table which is within another form. My problem is that the embedded form tag is not appearing - the input and iframe appears, but the form tags do not appear. The table and outer form appear. What's wrong?
<form>
<table id=\"mytableid\">
<tr class=\"form_row\">
<td align=\"right\">
Upload Photo:
</td>
<td align=\"left\">
<form action=\"/myuploadpath\" method=\"post\" enctype=\"multipart/form-data\" target=\"upload_target\" id=\"photo_url_upload_form\" name=\"venue_photo_url_upload_form\">
<input type=\"file\" name=\"photo_url\" id=\"photo_url\" size=\"40\" />
<iframe id=\"upload_target\" name=\"upload_target\" src=\"#\" style=\"width:0;height:0;border:0px solid #fff;\"></iframe>
</form>
</td>
</tr>
</table>
</form>
Putting a form inside another form is not valid HTML. When this happens each browser will do different things with the markup. Some ignore parts, some break, etc. Either way you shouldn't do this.
Edit
If you are using tables for layout purposes, you technically shouldn't be. They are only meant for tabular data. You should use divs/spans and CSS to create the look you want on your site. A great place to learn about this stuff is W3C Schools.
I assume you're using something like Firebug or the Chrome DOM Inspector to look at your DOM tree and you can't see the inner <form>. These tools inspect the DOM itself, not the HTML source. That is, they show you what the browser has interpreted from your HTML. The problem in this case is that nesting a <form> within another <form> is invalid, and hence the browser has ignored it and continued parsing the rest of the document.
Obviously, the fix is to ditch that outer form since it's not doing anything. If you have it there for styling purposes, perhaps use a <div> with a class.

Eclipse html: Doesn't indent on some tags

For some reason, Eclipse seems to think that e.g. <div> and <td> tags aren't indenting-worthy.
Ctrl+Shift+F indents the following HTML as such:
<div>
<div>
<table>
<tr>
<td>test<br />
test2
<h1>test 2</h1>
<div>testing<br />
test2</div>
<table>
<tr>
<td>
<h1>again</h1>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
Anyone have any idea of how to turn this logic off (I want all tags to indent!), or customize it?
Window > Preferences > Web > HTML Files > Editors.
Remove what you want to indent of the "Inline Elements" field.
This solved for me.
Hope its better now.
I'll give you an example of how to do it in Aptana. Since it's based on Eclipse - it will be more or less the same:
Window > Preferences > Aptana (or Eclipse) > Editors > HTML > Formatting > To edit, save the profile as a new one, and Edit > New lines > Everything in here should be self explanatory.
A sample screenshot: http://img10.imageshack.us/img10/6643/aptanaeclipse.jpg
In case you struggle to find a menu item, just do a filter search on the top left of the Preferences dialog window.
I would suggest you look at html tidy, which is a commandline tool. If you're running linux, then fire up your package manager and search for 'tidy', it will be there. If windows, then see this page: http://tidy.sourceforge.net/#binaries
Typical tidy command from bash/DOS prompt:
tidy -im index.html
This will (-i) indent the code and (-m) modify the input file (rather than spitting it on the console). It will also list any warning or errors related to the DOCTYPE you've got in your header.
After you've run the command, eclipse should notify you that you're code has been updated and prompt you to refresh the window with the updated code.