question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inline script in the editor has problems with ==

See original GitHub issue

Put this in the editor (Ghost v0.6.4)

<script>
var x = 0;
if ( x === 0 ) {
    alert("yay");
}
</script>

then publish.

View the blog post in a web browser. Would expect an alert box saying ‘yay’. However, we get a javascript error.

Inspecting the rendered HTML/JS code and we see

<script>
var x = 0;
if ( x <mark>= 0 ) {
    alert("yay");
}
</script>

It looks like some macro replacement magic is taking place, replacing any == characters with <mark>.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
xDEADC0DEcommented, Apr 22, 2017

I have the same issue on Ghost Pro, the only way to avoid the problem is to add <pre> tags before and after the <script> tags.

1reaction
emersonkeenancommented, Feb 9, 2016

@intositeme The work around I’m using is to modify showdown-ghost v0.3.6 to escape <script> blocks before applying highlighting. Assuming you are using Ghost v0.7.6 simply replace node_modules\showdown-ghost\src\extensions\highlight.js with the following and restart Ghost:

/* jshint node:true, browser:true, -W044 */

// Adds highlight syntax as per RedCarpet:
//
// https://github.com/vmg/redcarpet
//
// This is ==highlighted==. It looks like this: <mark>highlighted</mark>

(function () {
    var highlight = function () {
        return [
            {
                type: 'html',
                filter: function (text) {
                    var highlightRegex = /(=){2}([\s\S]+?)(=){2}/gim,
                        extractions = {},
                        hashID = 0;

                    function hashId() {
                        return hashID += 1;
                    }

                    // Extract pre|code|script blocks
                    text = text.replace(/<(pre|code|script)>[\s\S]*?<\/(\1)>/gim, function (x) {
                        var hash = hashId();
                        extractions[hash] = x;
                        return '{gfm-js-extract-' + hash + '}';
                    }, 'm');

                    text = text.replace(highlightRegex, function (match, n, content) {
                        // Check the content isn't just an `=`
                        if (!/^=+$/.test(content)) {
                            return '<mark>' + content + '</mark>';
                        }

                        return match;
                    });

                    // Replace extractions
                    text = text.replace(/\{gfm-js-extract-([0-9]+)\}/gm, function (x, y) {
                        return extractions[y];
                    });

                    return text;
                }
            }
        ];
    };

    // Client-side export
    if (typeof window !== 'undefined' && window.Showdown && window.Showdown.extensions) {
        window.Showdown.extensions.highlight = highlight;
    }
    // Server-side export
    if (typeof module !== 'undefined') {
        module.exports = highlight;
    }
}());
Read more comments on GitHub >

github_iconTop Results From Across the Web

inline task script editor has problems with spaces - Jira Atlassian
notice strange A character and notice that cursor is moved by two characters to the left, this is also wrong, cursor is at...
Read more >
PH07336: INLINE SCRIPT EDITOR IS NOT LOADING ... - IBM
Steps to reproduce â ‹ 1) Go to Manage Artifact Templates 2) Copy the template the "Default manual test script template" 3) In...
Read more >
[Bug] HTML language does not recognize inline ... - GitHub
Inline code is recognized as JavaScript, is syntax highlighted, and editing/navigation does not raise exceptions.
Read more >
Logic App (Standard) inline script window is too small
We have issues using the script editor for actions like "Execute ... 1 of blog post titled Logic App (Standard) inline script window...
Read more >
javascript - Why Should I Avoid Inline Scripting?
Performance-wise, you don't always have better performances when putting JavaScript in a separate file. Usually, we are tempted to consider that ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found