-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to not espace quotes. #269
Comments
Agreed, this is a big problem for us with assemble. We use handlebars and marked.js together, and since marked.js alters templates, it's preventing us from adding marked.js as a default converter. The problem is that by escaping quotes, marked converts |
Yes, that's exactly the same problem I'm having. And it's with Handlebars no less. Have you forked and fixed or simply chosen a different markdown converter? |
No, we just continue to use helpers for converting markdown, specifically so that we don't have to deal with the support issues related to this. However, before this continues to sound like like I'm complaining about marked, I really like this lib and use it quite extensively. We just don't have the time to support the issues related to including marked as a default converter. However, we're refactoring assemble, and I want to have assemble convert markdown natively after that. So hopefully we can get this hammered out. |
@chjj would you be open to someone helping out with this project? If so, I'd like to throw my hat in. |
I just ran into this as well. Any progress? |
+1 same thing |
any progress? @chjj |
I just had this same issue using Marked with React, which escapes everything by default. I'm not 100% on the implications of this, but the React docs (http://facebook.github.io/react/docs/jsx-gotchas.html#html-entities) suggest using unicode characters to avoid escaping issues. Could Marked's escape() function (https://github.com/chjj/marked/blob/master/lib/marked.js#L1076) be modified to do replacements with unicode characters instead? For example, This seems to work ok for me on first inspection, but I'm not confident about the affects of this, and other things like browser support. Anyone else care to weigh in? |
Just ran into this. 👍 |
Related: #529 |
The code in question seems to be here: https://github.com/chjj/marked/blob/master/lib/marked.js#L685 Shouldn't we have something like this? if (this.options.sanitize)
out += this.renderer.text(escape(this.smartypants(cap[0])));
else
out += this.renderer.text(this.smartypants(cap[0])); |
I know I'm late to the party, but I just hit this as well doing something similar with Handlebars + marked and thought I'd throw in my +1. |
+1 Faced the same issue (Handlebars + marked) @cri5ti, your suggestion fixes my issue. Thanks! |
+1 Same issue for me as well. |
+1 Also ran into this. How is everyone working around this issue? Just applying @cri5ti code change after npm install? |
+1 it's works for me. |
If someone would like to submit a PR with passing tests that will help move the issue along. |
You can copy and paste const escapeTest = /[&<>]/;
const escapeReplace = /[&<>]/g;
const replacements =
{
'&': '&',
'<': '<',
'>': '>'
};
const escapeTestNoEncode = /(?:[<>]|&(?!#?\w+;))/;
const escapeReplaceNoEncode = /(?:[<>]|&(?!#?\w+;))/g; My commit differs just by refactoring the |
ls there a way to do this in the current version? |
You can create a custom extension to render markdown differently const handlebarsTag = {
name: 'handlebarsTag',
level: 'inline', // This is an inline-level tokenizer
start(src) { return src.indexOf('{{'); }, // Hint to Marked.js to stop and check for a match
tokenizer(src, tokens) {
const rule = /^\{\{.*?\}\}+/; // Regex for the complete token, anchor to string start
const match = rule.exec(src);
if (match) {
return { // Token to generate
type: 'handlebarsTag', // Should match "name" above
raw: match[0], // Text to consume from the source
text: match[0] // Additional custom properties
};
}
},
renderer(token) {
return token.text;
}
};
marked.use({extensions: [handlebarsTag]}); |
@UziTech I don't think that is working, I tried your sample and I still get |
My example only prevents escaping between |
It may be obvious (and obviously having this solved in the library itself would be better) but personally I found it easiest to just do:
|
An example custom extension based on @UziTech's example for anyone wanting to prevent escaping const singleQuote = {
name: "singleQuote",
level: "inline", // This is an inline-level tokenizer
start(src) {
return src.indexOf("'");
}, // Hint to Marked.js to stop and check for a match
tokenizer(src, tokens) {
const rule = /^'/; // Regex for the complete token, anchor to string start
const match = rule.exec(src);
if (match) {
return {
// Token to generate
type: "singleQuote", // Should match "name" above
raw: match[0], // Text to consume from the source
text: match[0], // Additional custom properties
};
}
},
renderer(token) {
return token.text;
},
};
marked.use({ extensions: [singleQuote] }); |
Getting blocked on this now too, but I am only tokenizing markdown, never rendering it. It's not really clear at what point the escaping happens, but seems like it would ideally happen later in the process when rendering is about to happen, |
@devbytyler this should be fixed in the next major version by #3495 Sometimes escaping currently is happening during tokenization. |
I stumbled upon an issue that's giving me problems because marked is escaping double and single quotes in all situations and there's no option to change it.
https://github.com/chjj/marked/blob/master/lib/marked.js#L999-L1000
I'm no markdown expert, but I'm converting a project to node that previously used Ruby's rdiscount, which does not escape quotes. I do not see any reason (from an HTML perspective) to force escaping of quotes, so I think it makes sense to add an option to prevent this behavior.
If this is something you'd consider, I'd be happy to submit a pull request. Just let me know.
The text was updated successfully, but these errors were encountered: