-
Notifications
You must be signed in to change notification settings - Fork 34
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
Escaping HTML characters in fastboot #67
Comments
I'm not really sure what you are asking, can you explain? What HTML characters need escaping? |
Things like apostrophes (’) or quotes (“ and ”), etc. |
Can you give more info, possibly a demo repo or something? I'm really struggling to understand why this is an issue in your scenario... |
Basically we are pulling in content from Wordpress via graphql and dynamically set opengraph data. Something like this: afterModel(result) {
this.set('headData.ogDescription', result.post.excerpt);
this.set(
'headData.ogImage',
result.post.featuredImage && result.post.featuredImage.sourceUrl
? result.post.featuredImage.sourceUrl
: null
);
this.set('headData.ogType', 'article');
} Where |
Looks like something along the lines of import { htmlSafe } from '@ember/template';
export function decodeHtmlEntities(encodedString) {
let isFastBoot = typeof FastBoot !== 'undefined';
if (isFastBoot) {
return htmlSafe(
FastBoot.require('html-entities').AllHtmlEntities.decode(encodedString)
);
}
let doc = new DOMParser().parseFromString(encodedString, 'text/html');
return htmlSafe(doc.documentElement.textContent);
}
export default helper(([encodedString]) => decodeHtmlEntities(encodedString)); and "fastbootDependencies": [
"html-entities"
] in package.json along with the regular dependency and used as helper or function. Seems like this could be provided via fastboot service with an async import when used or something. |
In the browser I'd do something like:
and escape the opengraph text, but the
DOMParser
is not available in fastboot, what to do?The text was updated successfully, but these errors were encountered: