Open knownasilya opened 4 years ago
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 result.post.excerpt
and others have these characters escaped and when using in Twitter you see things like ’
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?