Skip to content
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

JSON parsing error in renderElement #42

Closed
femtomc opened this issue Jun 9, 2023 · 3 comments
Closed

JSON parsing error in renderElement #42

femtomc opened this issue Jun 9, 2023 · 3 comments

Comments

@femtomc
Copy link

femtomc commented Jun 9, 2023

I'm trying to run the README example -- but I'm running into a JSON.parse error in renderElement:

image

I'm building a static site through quarto and hugo, and I've confirmed that my HTML output is what I expect -- specifically:

<pre id="hello-world-code" class="pseudocode">
  \begin{algorithmic}
  \PRINT \texttt{'hello world'}
  \end{algorithmic}
</pre>
<script>
    pseudocode.renderElement(document.getElementById("hello-world-code"));
</script>

gets inserted into my generated HTML (as I would expect). I also fetch pseudocode.js from CDN in header.

Any mistake I've made standing out?

@femtomc
Copy link
Author

femtomc commented Jun 9, 2023

If I literally just paste:

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pseudocode@latest/build/pseudocode.min.css">
<script src="https://cdn.jsdelivr.net/npm/pseudocode@latest/build/pseudocode.min.js"></script>

<pre id="hello-world-code">
    \begin{algorithmic}
    \PRINT \texttt{'hello world'}
    \end{algorithmic}
</pre>

<script>
    pseudocode.renderElement(document.getElementById("hello-world-code"));
</script>

into an HTML file, I get the same error, unfortunately.

@SaswatPadhi
Copy link
Owner

Hi @femtomc,

Thanks for reporting this. Seems like one of my recent changes is incompatible with an undefined options parameter. Setting it to empty {} works as expected. Please see https://jsfiddle.net/hy1sa537/

I am working on a fix right now.

@SaswatPadhi
Copy link
Owner

Found the issue. It's this line:

var elemOptions = JSON.parse(JSON.stringify(options));

introduced in 30f2576 to allow per-element overriding of options.

JSON.parse doesn't like empty strings 🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants