How do I set the formatting of tinyMCE? - html

I am using the wysiwyg editor TinyMCE and I have stripped out most of the functions to create a simpler version. However, I need the make the formatting as basic as possible as well, e.g., instead of <p> tags i need to use <br /> tags. Also, I would like it to not convert ' in ’ as I will be using the output in Flash.
The only editing tools still left in it are bold, italic, underline and link/unlink.

You can enforce the use of <br> with the configuration option force_br_newlines and you can define the encoding with the configuration option entity_encoding.
entity_encoding: "raw"
force_br_newlines: true,

Related

write_html() method in fpdf not using font/encoding specified

I'm creating a PDF with a large collection of quotes that I've imported into python with docx2python, using html=True so that they have some tags. I've done some processing to them so they only really have the bold, italics, underline, or break tags. I've sorted them and am trying to write them onto a PDF using the fpdf library, specifically the pdf.write_html(quote) method. The trouble comes with several special characters I have, so I am hoping to encode the PDF to UTF-8. To write with .write_html(), I had to create a new class as shown in their readthedocs under the .write_html() method at the very bottom of the left hand side:
from fpdf import FPDF, HTMLMixin
class htmlFPDF(FPDF, HTMLMixin):
pass
pdf = htmlFPDF()
pdf.add_page()
#set the overall PDF to utf-8 to preserve special characters
pdf.set_doc_option('core_fonts_encoding', 'utf-8')
pdf.write_html(quote) #[![a section of quote giving trouble with quotations][2]][2]
The list of quotes that I have going into the pdf all appear with their special characters and the html tags (<u> or <i>) in the debugger, but after the .write_html() step they then show up in the pdf file with mojibake, even before being saved, as seen through debugger. An example being "dayâ€ÂTMs demands", when it should be "day's demands" (the apostrophe is curled clockwise in the quote, but this textbox doesn't support).
I've tried updating the font I use by
pdf.add_font('NotoSans', '', 'NotoSans-Regular.ttf', uni=True)
pdf.set_font('NotoSans', '', size=12)
added after the .add_page() method, but this doesn't change the current font (or fix mojibake) on the PDF unless I use the more common .write(text_height, quote) method, which renders the underline/italicize tags into the PDF as text. The .write() method does preserve the special characters. I'm not trying to change the font really, but make sure that what's written onto the PDF preserves the special characters instead of mojibake them.
I've also attempted some .encode/.decode action before going into the .write_html(), as well as attempted some methods from the ftfy library. And tried adding '' to the start of each quote to no effect.
If anyone has ideas for a way to iterate through each line on the PDF that'd be terrific, since then I could use ftfy to fix the mojibake. But ideally, it would be some other html tag at the start of each quote or a way to change the font/encoding of the .write_html() method, maybe in the class declaration?
Or if I'm at a dead-end and should just split each quote on '<', use if statements to detect underlines, italicize, etc., and use the .write() method after all.
Extract docx to html works really bad with docx2python. I do this few month ago. I recommend PyDocX. docx2python are good for docx file content extracting, not converting it into a html.

CKeditor rich text editor displaying html tags in browser

I've just installed CKeditor rich text WYSIWYG editor on a site I'm building and it seems to be working ok except for the fact that it inserts text into my mysql database as encoded html rather than regular html and then when the browser outputs this text it converts the encoded data into regular html that then displays in the browser showing the html tags and none of the styling!?
eg I type:
"This is text"
into the editor and it then inserts
<p>This is text</p>
into the database. Then when the page is called the browser converts the above and outouts the following on the page:
<p>This is text</p>
obviously I just want "This is text" to display on the page.
Does anyone know why this is happening/how to solve it please?
Any suggestions would be most welcome.
Cheers
If you don't want CKEditor to create paragraphs for you, set config.autoParagraph to false. Additionally you may want to change enter key behaviour with config.enterMode set to CKEDITOR.ENTER_BR.
And regarding disappearing styles...
EDIT: OK, it seems I missed your point.
So your website is displaying HTML markup instead of HTML while rendering out what you typed?
Then the problem is your server side rather than CKEditor. You can verify in your console that CKEDITOR.instances.yourInstance.getData() yields the correct, unescaped HTML:
<p>This is text</p> // Right!
If it is so, and I strongly believe it is, CKEditor's just fine and this is your server app that is converting special chars into entities (i.e. like PHP htmlspecialchars) while saving to database. You didn't mention what kind of framework/language you use there, so I can just tell you that it is to secure user input to prevent cross-site scripting, breaking layouts etc. and all popular frameworks allow you to disable that feature for a particular field. Simply refer to documentation.
Modern templating languages tend to autoescape html input. For example, in DTL it would be displayed correctly in the template by simply using
{{ object.field_name|safe }}
This is a desired action, since user input is considered untrusted and may be considered malicious.
The browser is not parsing HTML, so on the page displaying (or in the php file) try using {! !} instead of {{ }}.
If you are using laravel, then you should use {!! $variable !!}.
For Laravel 7, 8, and 9 - foreaxample if there is a varable called- $student
and student varable holds "This is Text" in paragraph you must call the varable using singla culy brace front and back, inside two

Using TinyMCE as a text editor

TinyMCE is used in one of my projects as it was meant to be used; a WYSIWYG HTML editor.
I created a number of plug-ins for it that inserts certain fragments of text into the HTML and all is working fine. The plug-ins use TinyMCE's createMenuButton to create a menu button and tinyMCE.activeEditor.execCommand('mceInsertContent', ...) to do the inserting.
Now I need to add an editor for plain text in the same project. The text-only editor would also need to be able to insert those same fragments of text into plain <textarea> or <input type="text"> inputs.
Rather than duplicating code, I'd like to re-use the plug-ins written for TinyMCE.
Is there any way to either use TinyMCE as a plain text editor or use just the individual plug-ins?
I'm using TinyMCE 3 and can't upgrade to 4 due to missing essential features.
You could use the editor "as is", but strip the html tags afterwards.

Regular Expression to Retrieve text between two html tags with Visual Studio's search-replace feature

I'm trying to use Visual Studio's search-replace function to remove tags that don't do anything. The intent is to simplify some HTML before I paste it into a SharePoint page.
This is what I'm using in the Find box \<font\>{~(.*\<font\>.*)}\</font\>
And the Replace box has \1
However, the expression comes up with no matches, even though I have plenty of places like this <font> xxxx </font> within the HTML. I could move the .* outside the paranthesis, but then the expression matches most of the line where I have multiple sets of font tags - some which actually do something.
I'm thinking this would be much easier if the IDE used the same regular expression engine as the languages for which it is the primary development tool.
I just had to review the documentation for VS 2010. Using a minimal match # was all I needed: \<font\>{.#}\</font\>.
I was trying to replace all span tags with div tags. I was able to solve a similar problem by using the following RegEx in the picture. I had to escape both the > and < and the class attribute double quotes.
\<span class=\"label\"\>{.#}\</span\>
<div class="label">\1<\div>

Rich text editor for AS3

Is there any rich text editor available that can generate "AS3 Compatible" codes?
I want to add this to the web admin, where user can set the font size and color of the text and it should generate as3 compatible code like:
<p><font size="12" color="#000000">Welcome to</font> <font size="30" color="#ffffff">My Website</font></p>
I used the CKEditor, but it generates like this:
<p><span style="font-size:12px; color:#000000">Welcome to</span></p>
I am assigning this value in my textfield with txt.htmlText.
If there is not any such text editor available, is there any way to render the above "span style" in the as3 textfield?
Although you say that you've been using CKEditor, it seems that you haven't configured it correctly.
Check this sample: http://nightly.ckeditor.com/latest/ckeditor/_samples/output_for_flash.html
As nowadays CSS is common practice, I guess it'll be hard to find an editor that will spit old style html. Flash only supports a handful of html tags. So you might want to use the CKEditor output, strip the style part, scour it for tags that flash would support and inject those back into the html.
[edit] I found something related here