HTML - insert user-created HTML into a HTML page: escaping and discarding format - html

I have an HTML page which needs to display some HTML generated by the user on the Administration area (like a blog, for instance). The problem is that the user sometimes needs to copy-paste tables and other "garbage" content from Word/Excel to the WYSIWYG editor (that has the proper "paste from Word" function). This causes the resulting HTML code to be very dirty.
It wouldn't be a problem unless some of these pages are shown totally wrong: other divs AFTER user's HTML code are not in their supposed position, floats are not respected... etc...
I tried putting a div:
<div style="clear: both;"></div>
without success. I even tried with iFrames, but iFrames accept only external webpages (if applicable...).
The question is: is there any tag or method to put a part of an HTML code inside a webpage discarding all formatting AFTER this code?
Thank you.

To my knowledge, you simply want to end all divs. HTML is a very simple code, with very simple options. Your example doesn't work because HTML isn't that advances. You can either start a function <...> or end a function .
Ideally what you want is a piece of code that puts their work in a separate frame entirely, so as soon as the page passes their code, it goes back to the correct formatting.
Or, you could be really sloppy and put one hundred 's in, just in case.

Related

Upload Image not using erb (form) rails

I was wondering if there is a way to upload images in rails 4 not using erb. I have my html code in quotations in my model (so that i can use it as a default for when creating a page). SO I cant put erb in the quotes, cuz if i do it'll come out as the erb code and not the actual view. (i.e. the upload image form. itll come out as the actual f.image_tag instead of the actual upload button).
So I am just seeing if there another way i could implement image uploading into the quotations that wont require erb. But, uses Rails 4.
If you have plain HTML code inside the string, and just want it to be displayed, you need to call .html_safe in your view, like:
'<div id="foo">bar</div>'.html_safe()
Note that normally is a bad practice: that doesn't mean it is always bad, but it means that it is always an attention point to make sure it is the best way to do it.
If you want to do image upload without using form.image_tag, you can just put that in your view and see the generated code (Ctrl+U in Chrome), that, in this case, will be something like:
<input type="file" id="something" />
And add that to the string. Probably some finer validation and options are added too via JS, that would be a pain to add this way - one way to be to add a script tag to the html with the code.
If, however, your string already contains code like this, and you are asking way it is not working, then you need to add an eval to the caller, e.g.:
eval('form.image_tag :image')
Not that this is an even worse smell, and it should be avoided at all costs.
Maybe it would be better to add some flags in your section.rb model, and then use that in a helper or in the view render the html; for example, a has_upload? field, and then you can do something like this:
if #section.has_upload?
form.image_tag :imagem
end

How to skip <p> tag in HTML?

I'm trying to use CKeditor as Wysiwyg editor for my blog posts. It works fine, all my contents get inserted fine in DB.
However I have one problem. CKeditor inserts automatic <p> tag in the begining, which mess up my code while returning from DB.(I loose CSS stylings).
Therefore, I'm wondering is there a way to tell HTML to ignore(skip) that tag (and closing one in the end).
Thank you...
You need to change the configuration file (plugin.js) to this: config.autoParagraph = false;
Whether automatically create wrapping blocks around inline contents inside document body, this helps to ensure the integrality of the block enter mode.
http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html#.autoParagraph

Headings created inside of a template

I have a number of templates that create headings based on a formula. I am wondering if there is anyway to create an "edit" link that will take you directly to that section? The way that it currently works, the edit link takes you to editing the template itself. Could I possibly create a customized link that would keep you on the page and take you to right part?
Here is some sample code to help clear things up...
Template:Head:
==={{{1}}}===
This is a heading titled "{{{1}}}"
Test Page:
=Section 1=
{{head|1.1}}
{{head|1.2}}
{{head|1.3}}
=Section 2=
{{head|2.1}}
{{head|2.2}}
{{head|2.3}}
At the moment, if I want to edit the information for template "2.3", I have to edit all of section 2. (Note that for this example, that isn't a big deal. For the actual templates I am working with on my site, the templates have dozens of parameters and there are sometimes 10 or more in a section.)
Bottom line, is there way to create a custom edit link inside of the {{head}} template that would take you directly to editing the templates call on the page "Test Page"? Hope that makes sense.
Edit: Is there perhaps a way to make use of "anchor" tags? Can anchors be passed in to the URL?
To restate your problem, when you transclude a section heading the header isn't treated as being part of the destination page, so the edit link takes you back to the source. So you need a separate container for the template in order to edit it individually, and a complete section is the smallest editable container.
The only way I can think of doing this is using subpages (or virtual subpages if you don't have that ennabled in this namespace, doesn't change anything). So instead of placing {{head|1.1}} on MyPage, put it on MyPage/Subpage1 and then transclude that into MyPage in the usual way ({{:MyPage/Subpage1}}).
{{head}} can then include a custom edit link to the template input by using HTML heading tags (<h2> is equal to ==, etc.) to suppress the standard edit link and then use one of these templates (probably {{ed right}}) to create a custom edit link pointing to MyPage/Subpage1.
The way to create anchors in Mediawiki, by the way, is to use a <span id="name"/> tag, but that doesn't create a container that can be edited (or at least, not that I've been able to work out through URL tinkering).
I'm pretty sure there's no way to do that. As far as MediaWiki's section editing feature is concerned, the only thing that begins a new section is a line of the form:
=== Some text here ===
with the number of = signs determining the level of the heading. There's no way to get MediaWiki to let you edit any segment of the document that doesn't begin and end with such a line (or the beginning or end of the page).
Well, OK, I'm sure you technically could do it with an extension, in the sense that you can do anything with a MediaWiki extension. All you'd need to do is provide some way (e.g. a special parameter in an edit URL) for to user to indicate "I want to edit this template", then extract the template from the wikitext, present it to the user for editing, and write the result back into the page text over the original.
The tricky part will be extracting the template from the page source. (Finding and replacing templates on a page is a fairly common task for MediaWiki bot writers, so you might want to look for ideas there.) Whatever method you end up using for that, there will probably be edge cases where you need to give up and tell the user "Sorry, but I can't figure out how that template is transcluded here."

HTML page title: localization and empty title

2 questions about a better way of solving the problem:
1) is there is a way to make HTML page title looking different for different locales of the client-side code except for javascript?
I.e. write HTML page title which is shown in the browser's tab in corresponding language.
I know I can use javascript for this, but may be there is another way?
2)I set my HTML page header with javascript (it is a different case). But there is a delay before the script will run. Is there is a way to set HTML page header to empty line before javascript evaluates?
If I remove tag I get the page URL.
If I use empty tag - same thing.
I have to use &nbsp content inside which looks a bit ugly.
Some other options?
I don't see any other means but JavaScript on the client side for this, sorry.
For the delay: try using an inline javascript to change the page title right on top of the page before any other scripts are loaded or executed, but after the page title has been set. This should keep the delay to an absolute minimum.
To the first:
Except Javascript, the only Way i know would be PHP, but using Javascript is a lot better and
easier.
To the second:
arkascha's Post is the answer

Random quote in HTML using CodeIgniter

I am getting random quotes in my HTML (see image below), and I can't for the life of me figure out how to get rid of them. I have traced it right back to my model and there are now quotes there. I have also compressed all my code and there are still quotes.
Any one had this bug???
Here's my PHP code
<ul><?php foreach ($account_media as $value) : ?><li class="span2"></li>​<?php endforeach; ?></ul>
I am using CodeIgniter
UPDATE: ok this is from a while ago but thought i would update you all with my solution. DO NOT COPY AND PASTE FROM JSFIDDLE really hard to debug (paste code into text editor save as plain text and then delete the old code and replace with plain text version)
Why are you using Inspect Element instead of View Source? What does View Source show?
Quotes might appear as an indication for empty in element inspection. Or in your case, it might show that <li> tags are non-blocks and are separated.
And please, people, read/write it right, I'm so sick of seeing ignitOrs. It's CodeIgnit E r. And I don't point it out just because I'm some correct terminology freak, but because it makes your questions be parsed incorrectly by search engines.
The space between <li> elements is a css issue, refer to this article: Remove Spacing between li
Chrome does this normally. It is nothing to be worried about.
View the source in the future for an absolute rendering of your HTML instead of inspecting the elements.
See screenshot below.