I'm using asp.net and I would like to edit a newsletter using CKEditor’s inline editing capabilities and then save the newsletter to the database and send via an email.
I've seen various posts about getting the data from a single instance of the inline editor on a page.
Such as the answer by oleq to Dan Temple question on inline editing.
How do I save inline editor contents on the server?
However I would like to have a newsletter similar to the inline demo on the ckeditor site with multiple areas in different style that can be edited.
http://ckeditor.com/demo#inline
Then I guess using ajax to collate the data from each of the individual instances of the editor and save to the database.
Any help would be greatly appreciated.
Many thanks. Luke
I believe this does exactly what you are looking for:
ckeditor inline save/submit
You might need to change a few things to make it work for you. If you are writing valid HTML then I would suggest using something like Nokogiri to search and replace the contents of the page element id's instead of using regular expressions like this answer does.
Related
I am trying to display code as part of a tutorial in my squarespace blog post. I know how to insert code and save it so it displays as html or javascript but I want it to be indented and shaded similar to how code is displayed on stackoverflow. Any ideas?
Here's how the code looks now in the post:
There are a couple options to display/format code in Squarespace:
Use a Code Block with "Display Source" checked.
This will automatically format HTML, CSS or JavaScript. For other languages, it's possible to accept a compromise and select "JavaScript". For example, some Python code will look alright when formatted as JavaScript. You will, of course, want to write your code in a text/code editor outside of Squarespace and then copy/paste it into the block. This should maintain your indentation for the most part.
Use an HTML formatting tool.
Write your code in your favorite text/code editor. When you're done, you can copy/paste it into a tool like tohtml.com (there are probably others; I only found this one in answering this question), select your language, and submit it. It will then output HTML with inline styles that you can straight-up copy and paste into a code block (leaving "Display Source" UNchecked). You will of course want to save your source code for future editing, because tools such as that will format the code for display, which is not conducive to later editing.
The above suggestions assume that you have a preferred code/text editor that you use to write your code and simply want to take it from there and insert it into your Squarespace website. If you're looking to choose an editor, that's a large and opinionated topic. You'll want to search around.
I am working with some migration of content from one website to another. I am doing this using a cron.
When I try to insert data to the WYSIWYG fields the data is inserted and showing in the WYSIWYG editor, but when I check this data in the front-end, the data seems to be pure HTML. Does anybody know what type of formatting I have to apply for proper insertion of data?
Finally I found the solution for this,
I added the below code
$node->set('field_textarea_data', ['format'=>'full_html','value'=>html_entity_decode($data->data,ENT_QUOTES, 'UTF-8')]);
And this solved my issue.
Thanks all for your response.
I am a user, not a programmer, whose forthcoming new website on Plone 4 requires adding hyperlinks inside the Description field of pages and folders. This is needed to point specific words to our website Dictionary as we had been doing on EZ Publish for the last 10 years.
Our developer says this can't be done in Plone. I'm looking to help them find how to do this (they don't seem to use English-language forums).
Is there an existing add-on or existing code for this? If not, is it possible to code this in? How? If not, will it become standard in Plone 5?
<a href="http://python.org>Python</a> will not work, as the description-field is ment and used as a meta-information of an item, holding plain-text only, and doesn't allow the usage of html-elements, nor embedded Javascript. That's probably why T. K. Nguyen recommends to provide an additional rich-text-field.
But you can use reStrucuredText instead. Tell your developer to exchange the description-snippet in concerned templates to:
<div tal:define="Std modules/Products.PythonScripts/standard;
restructured_text nocall: Std/restructured_text;"
tal:content="structure python: restructured_text(context.Description())">
</div>
It will transform any word starting with 'http:' or 'https:' to a link, furthermore will also recognize mail-addresses like 'someone#plone.org' and transform them to mail-links (on click opens the user's default mail-client, if available, with the address pre-populated in the 'To'-field).
If you want to have named links, use the reStrucutredText-syntax for the input, like this:
`Check out Python`_, you'll love it.
`Write a mail`_ to someone.
.. _Python: http://www.python.org
.. _Write a mail: someone#example.org
The tricky part is to figure out, which templates are affected, but it's doable of my experience (did it with preserving line-breaks in listing-views, not reStructuredText).
Alternatively use a JS-workaround, as proposed by T. K. Nguyen. Be aware though, that it may break accessibility to some users.
It is possible to customize the description fields to be rich text (HTML) instead of plain text, but it requires a developer.
You can also use JavaScript to look at a description field and replace (for example) any string that starts with "http" with a hyperlink pointing to that URL. Your developer would have to look for examples of such JavaScript code and then would have to know how to register it on your site and then invoke it.
This describes how to do something similar, for PloneFormGen field help text (which is also plain text):
https://designinterventionsystems.com/blog/how-to-make-urls-clickable-in-ploneformgen-field-help-text
It might be easier to have your developer create a new rich-text description field and have all your content types include that new field. That, however, would require that you update the view templates for those modified content types. This is much easier with Dexterity, which ships with Plone 5 and is available for use with Plone 4.x.
imho it's a really bad idea to convert the description field to any richttext (html, rst, md) field. You need to change a hole bunch of templates to avoid html code rendered everywhere.
Example:
search
collections
content
portlets
Addons
The description is also often used as title attribute on links, in those cases you need to convert it to plain/text. And there are several more issues, where you could ran into.
As #T. Kim Nguyen wrote: Consider add a new textfield and show it, where necessary, probably implemented as a Viewlet in the below title slot.
Looking at your current site, it seems like you want this to provide a teaser for each article, which may contain links. If that is the case, then you can find other ways to do this without making the description html.
For instance, if you used collective.cover for your portal/collection pages then a Rich Text Tile would allow you to cut down the the object text to an appropriate size, but still edit it with a Rich Text editor, and keep/insert hyperlinks.
Let's say I have a simple ASP.NET MVC blog application and I want to allow readers to add comments to a blog post. If I want to prevent any type of XSS shenanigans, I could HTML encode all comments so that they become harmless when rendered. However, what if I wanted to some basic functionality like hyperlinks, bolding, italics, etc?
I know that StackOverflow uses the WMD Markdown Editor, which seems like a great choice for what I'm trying to accomplish, if not for the fact that it supports both HTML and Markdown which leaves it open to XSS attacks.
If you are not looking to use an editor you might consider OWASP's AntiSamy.
You can run an example here:
http://www.antisamy.net/
How much HTML are you going to support? Just bold/italics/the basic stuff? In that case, you can convert those to markdown syntax and then strip the rest of the HTML.
The stripping needs to be done server side, before you store it. You need to validate the input on the server as well, when checking for SQL-vulnerabilities and other unwanted stuff.
If you need to do it in the browser: http://code.google.com/p/google-caja/wiki/JsHtmlSanitizer
I'd suggest you only submit the markdown syntax. On the front end, the client can type markdown and have an HTML preview (same as SO), but only submit the markdown syntax server-side. Then you can validate it, generate the HTML, escape it and store it.
I believe that's the way most of us do it. In either case, markdown is there to alleviate anyone from writing structured HTML code and give power to those who wouldn't even know how to.
If there's something specific you'd like to do with the HTML, then you can tweak it with some CSS inheritance '.comment a { color: #F0F; }', front end JS or just traverse over the generated HTML from parsing markdown before you store it.
Why don't you use Jeff's code ? http://refactormycode.com/codes/333-sanitize-html
I'd vote for the FCKEditor but you have to do some extra steps to the returned output too.
You could use an HTML whitelist so that certain tags can still be used, but everything else is blocked.
There are tools that can do this for you. SO uses the code that Slough linked.
I'm writing a asp.net web application in which I want the users to be able to apply simple formatting to the text they enter in text areas.
One of the possibilities is to use a javascript wisywig editor (like tinymce). However, to keep the text html-clean and readible, I'd prefer that the users have to do the formatting themselves in exactly the same way as it is done in wiki's.
I can't find a free or not too expensive control on the web. Has anyone used a third party control before? any advise on this?
You can use a markdown editor like this:
http://wmd-editor.com/
Then you want to be able display the result in HTML with this:
http://aspnetresources.com/blog/markdown_announced.aspx
Essentially this is what StackOverflow does (with their customization). They discuss how they do it in their podcast.