Javascript in script tag in shortcode wrapped in html tags

This bug is interesting, because the shortcode works 29 times and fails 1 time, and yet the frontmatter for the failing post, and the json file it uses, both verify as valid.

The error is distinct however, and some of you guys responding to forums probably know exactly what’s happening.

The shortcode in question is pretty simple, it opens some html, passes some parameters from frontmatter into scope, inserts a script tag with JavaScript, where those variables are passed into JavaScript variables, then closes the html.

The script tag creates a few elements, passes some info into them (, then inserts them into the dom, where they are picked up later when modules parse to have their info extracted.

The problem is that in one of the posts html is injected into the script tag.
Much of the JavaScript is wrapped in paragraph tags, <p></p>.

As you might expect, the JavaScript throws an Uncaught SyntaxError: Unexpected token '<' .

Any insights into what the problem might be, and why it only happens on one of the posts?

Does this mean it consistently works for 29 of the same content files, and consistently fails with the same content file?

If so, can you share the markdown for the one failing markdown file?

It’s a false negative, i.e. not the bug it was thought to be.

The same content with the ‘var_year’ placeholder removed from the title renders correctly. That was the only post from that type that used the year swapping apparatus, which is anyway not the most appropriate code.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.