0

I am using SyntaxHighlighter on Blogger. The problem is that an unexpected line is added to my Python code snippet.

The code is enclosed in:

<pre class="brush:bash;">
  ...
</pre>

My code is:

(venv) dm@Z580:~/workspace/venv/greeter$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from greeter import app
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dm/workspace/venv/greeter/greeter/app.py", line 7, in <module>
    from effects.dashed import add_dashes
ImportError: No module named 'effects'

What is actually rendered:

(venv) dm@Z580:~/workspace/venv/greeter$ python
Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from greeter import app
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dm/workspace/venv/greeter/greeter/app.py", line 7, in <module>
    from effects.dashed import add_dashes
ImportError: No module named 'effects'
</module></module></stdin>

So the last line </module></module></stdin> is added to the output.

Why is this happening and how to prevent this behavior?

Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64

1 Answers1

0

Ok, so I don't know why is this happening and how to prevent it. But I came up with a simple jQuery script which removes these unwanted lines.

$(window).load(function() {
    // line number regex
    var lineNumberRegex = /number\d+/;
    // </some_string> regex
    var unvantedOutputRegex = /^<\/.*>$/;

    // code for removing unvanted last lines added by SyntaxHighlighter to a Python code snippet
    // removes last lines like: </module></module></stdin>, i.e. starting with '</' and ending with '>'
    var syntaxHighlighters = $('.syntaxhighlighter');
    for (var i = 0; i < syntaxHighlighters.length; i++) {
      var syntaxHighlighter = syntaxHighlighters.eq(i);

      var lastLine = syntaxHighlighter.find('.line').last();
      var lastLineText = lastLine.text();

      if (unvantedOutputRegex.test(lastLineText)){
        var lastLineClasses = lastLine.attr('class');
        var lineToRemove = lastLineClasses.match(lineNumberRegex)[0];

        var targetLines = syntaxHighlighter.find('.' + lineToRemove);
        for (var y = 0; y < targetLines.length; y++) {
          targetLines[y].remove()
        }
      }
    };
});
Dušan Maďar
  • 9,269
  • 5
  • 49
  • 64