How to insert single quotes with redactor.js? - json

I'm building a little custom plugin with redactor 8.2.2 to customize links.
This is an example of what I'm trying to achieve :
var insertText = "<a href='#target' data-rel='{\"key\":\"value\"}'>text</a>";
/* later in the code... */
this.execCommand('insertHtml', insertText);
I end up with this code in the editor :
text
which is finally saved with double quotes in the database, leading to further troubles:
text
Is there a way to force single quotes?
I also tried to use insertHtmlAdvanced, but no link is inserted.
EDIT__
It seems that the problem is not the way insertText is formated. Whatever the format is, double quotes are added if the data-rel attribute presents its value between single quotes.
Therefore, the solution might be to find a workaround for the insertHtml command, or to post-process the inserted code.
EDIT___
According to Imperavi support, JSON should not be used with data-*. I finally found a workaround by deleting any quotes in the JSON string, and adding them later before parsing the data-rel value. However, I guess this is not the most efficient and nicest solution....

Use this:
this.execCommand('insertHtml', insertText.replace(/'/g, "\\'"));

Related

How to detect HTML in clipboard data using Qt

I have a rich text editor I'm working on where I need to parse and clean data from the clipboard when appropriate. Whenever the text being pasted contains HTML, I will clean it up and update the text field with the correct html.
However, when there is no html in the clipboard, there is no need for me to run the html cleaning tool.
My first thought was to use Regex and check for any html tag in there, but I'm not sure this is the best solution for this problem as it can cause more headaches in the long run with false positives, etc.
My question is, how can I detect some HTML in the clipboard?
Is there a an elegant way to solve this problem without having to resort to Regex?
may be one of these functions:
bool QDomDocument::setContent(...)
This function reads the XML document from the string text, returning true if the content was successfully parsed; otherwise returns false. Since text is already a Unicode string, no encoding detection is done
Addition for a clipboard's mixed data:
// get a html data from a junk
QString htmlText = cliboardString.section("</html>", -2, 0,QString::SectionIncludeTrailingSep)
.section("<html", 1,-1,String::SectionIncludeLeadingSep);
// check for a validness, correctness etc.
if( !htmlText.isEmpty() ) {
QDomDocument::setContent(htmlText,...
}

extracting double quotes from html tags with a regex

I'm extracting some content from a website with this pattern:
([^+]+)
and it outputs
< img src=""http://www."" border=""0""/>
with double quotes. What is wrong with my query?
your problem only makes sense if you modify your regexp.
but first of all, beware:
in general, what you try to achieve is not feasible using regexes. they are the inappropriate tool to do it. you will not come up with a solution 100% correct using regexes.
having said this, try to replace ([^+]+) with (([^<!--]+([^<]|<[^!]|<![^-]|<!-[^-]))+). note that this regex assumes the following:
there are no html comments inside the message portion
there are no strings containing html comment openings inside the message portion
the message portion is a valid html fragment
(otherwise it would match eg. <!-<!-- / message -->)
you have been warned.
btw, the dquote doubling must be a standard escape mechanism of the imacro environment.

How to store html characters in mysql and display them correctly

Not sure if I am asking this correctly. But I am using a Jquery HTML Editor cleditor so that the users can load html text. When I insert this into my db(mysql) and want to display the outcome it takes out any html characters it had like: <p>, <span>, and so on. So when I go view it, it shows like this:
class=\"noticia_texto\">jlasdfklsfklaf
which obviously it's not readable. Help please? Should I be using anything at the time of inserting or displaying or both? Also my datatype is set to Blob.
MySQL does NOT strip html tags. If they're being removed upon insertion (or retrieval), then it's something in your code doing it, not MySQL.
Given that the quotes in your snippet are escaped, you've almost certainly got magic_quotes enabled, and/or a home-brew SQL escaping function run amok.

How to stop Dreamweaver from converting " double quotes to "?

I need to use double quotes inside a tag
How to stop Dreamweaver from converting " double quotes to " ?
I need the original " and not " but as soon as I add the " quote via Design view, it shows " in design view, but in code view its "
I need the " double quote to remain the same in both Design and Code view.
The reason is that i need the double quote "" in a tag such as {mytag category="news"}
I need the exact tag as {mytag category="news"} but dreamweaver is changing the double quotes in the Code view to " so this is what i am getting in the Code view
{mytag category="news"}
ISSUE :: SOLVED
There is no way to achieve this.
In HTML
foo='"'
and
foo='"'
are equivalent. If you need one of those two syntaxes over the other, then you are not dealing with HTML and shouldn't be using an HTML editor to produce your content.
foo="""
… on the other hand, is an error and you should have even less reason to want that.
I was able to disable this quote-pairing as follows :
Quit Dreamweaver.
Edit the text file: ~/Library/Application Support/Adobe/Dreamweaver CC 2017/en_US/Configuration/Brackets/brackets.json
Add the following line within the body: "closeBrackets": false,
Save the text file and relaunch Dreamweaver.
It should no longer auto-complete quote pairs.
Some people have reported they needed to make this change to the same-named file within the application folder as shown below, but I had no such file on my UK installation:
Applications\Adobe\Dreamweaver CC 2017\en_US\Configuration\Brackets\brackets.json
Found the answer
I just changed the DOCTYPE from XHTML to HTML5
And it worked fine, it did not convert the double quotes to its entity.
This solves the issue for me, for now.

How can I remove or escape new line-carriage returns within an XML string in XSL?

I've got an ASP multiline textbox that saves user defined text to a database. When I retrieve the data, I serialize it into xml and then run it through an XSL transform to output my HTML.
Within my transform, I am passing the textbox defined data into a javascript function via an onclick event of an element.
The problem I'm running into...when a user enters a carriage return into the textbox and saves it to the database, a javascript error is generated on page load.
I'm using .NET's XslCompiledTransform to do the transform. There is a property on XmlDocument called PreserveWhiteSpace, default is false, that can be set to strip out white space in the XML. This solves the problem of not allowing a user to enter breaking text, however, the client wants to preserve the formatting of the text that they enter if at all possible.
From what I know, .NET XslCompiledTransform transforms carriage returns-new line into
. I believe these are the characters that are breaking the javascript.
My first thought was to strip out the carriage returns within the xsl prior to passing the string into the javascript function, but I've not been able to figure out what characters to "search" the string for.
I guess another question is what characters get stored in SQL for carriage returns from within an ASP.NET textbox control?
Looking directly at the data in the database, SQL seems to display the character as "non-displayable" characters or (2 empty boxes).
Has anyone had any experience with this type of thing?
I was able to do this in the code behind to get my desired results:
using (StringWriter sWriter = new StringWriter())
{
xTrans.Transform(xDoc, xslArgs, sWriter);
return sWriter.ToString().Replace("
", "\\r\\n");
}
One other thing that I've stumbled across...
Initially, I wanted to find a solution to this problem that did not require a "compiled" code change, ie. a way to do this within xsl aka "a short term fix".
I tried this first and was not successful...
<xsl:variable name="comment" select="normalize-space(.\Comment)" />
This essentially did nothing and I was still receiving the javascript error.
Eventually, I tried this...
<div onclick="Show('{normalize-space($comment)}'"></div>
The second actually worked in stripping out the white space, thus, the javascript error was avoided. This wasn't a complete solution for my requirements because it only solved the issue of the javascript error, however, it would effectively prevent the user from "breaking" the page.
For that reason, it could suffice as a short term solution.