Adding '$example$' to the markdown truncates the AMP output before the second $ causing broken browser rendering through missing closing tags.

Testing
`'$example$'` asdf
123
'$example.The HTML output is clearly malformed. the trailing $' is removed and the rest of the helper output is added to the bottom of the post with the final section duplicated:

This results in the browser injecting lots of extra <code></code> tags to try and deal with the malformed HTML.
Removing the SafeString call so that handlebars outputs the raw string appears to show that there's a nested async helper issue:
<div class="kg-card-markdown">
<p>Testing</p>
<p>
<code>'$example__aSyNcId_<_ZziCMbqm__#x27;</code>
asdf
</p>
<p>123</p>
</div>
Narrowing the troublesome content down it appears to be caused by a trailing $ or $' in any element. This can be demonstrated with simply putting $ as the only markdown content in a post.
Seems the problem is at https://github.com/TryGhost/Ghost/blob/c186347f0ca8d21136e804758e2ec4d719ec890b/core/server/apps/amp/lib/helpers/amp_content.js#L193 . ampHTML if logged, prints the code fine to the console. But when we pass it to the sanitizeHtml function, it breaks. Don't know if we missed something in options passed to the sanitizeHtml. Please correct me if I am wrong. Taking a look at this.
@lunaticmonk I think you're on the right track. That's where I saw this glitch happening too. I couldn't find a solution within the sanitize-html module tho. Would be super nice, if you'd find a solution here 馃
My guess it is a markdown issue as even the non-amp page adds the end code block in the wrong place. I am taking a look at this as well.
I was wrong it looks like the mobiledoc issue as this is what gets posted to the server: "mobiledoc": {
"version": "0.3.1",
"atoms": [],
"cards": [
[
"code",
{
"code": "'$example$'asdfg\n\n123"
}
]
],
"markups": [],
"sections": [
[
10,
0
],
[
1,
"p",
[]
]
]
} Notice code seems to be nested. Will keep digging deeper.
Ok never mind on all of that was using the wrong editor type. Fixed and now looking at the sanitize html code.
Ok on the hunt farther down as this might be a handlebars issue as the output from everything in amp_content.js is <p><code>'$example$'</code> asdf</p><p>123</p> which looks correct.
Ok this is a bug in express-hbs it uses Javascript string replace which has special string syntax. (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter)
Working on the fix now by moving it to a function replace. This line https://github.com/barc/express-hbs/blob/master/lib/hbs.js#L500 needs to be this res = res.replace(id, function() { return values[id]; });
Opened an issue in express-hds to solve this issue: https://github.com/barc/express-hbs/issues/144
Opened a PR. https://github.com/barc/express-hbs/pull/149
Once it is merged and published in a new version we can open a PR to update the version in this repo.
The PR was merged! 馃帀
Still waiting for the permissions to publish the merge and then we can make sure this fixes this issue by testing out the new version here.
This bug is known and understood, it is expected to be fixed by the update to express-hbs, which has an open PR #10288. Currently waiting on a bug check/fix before merging.
Re-opening because we had to revert the express-hbs bump. See https://github.com/TryGhost/Ghost/issues/10643 for further details.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
@allouis as https://github.com/TryGhost/Ghost/pull/10750 landed in master this issue can be now closed?
Most helpful comment
Opened a PR. https://github.com/barc/express-hbs/pull/149
Once it is merged and published in a new version we can open a PR to update the version in this repo.