Bug in SyntaxHighlighter Code block with specific Python code
-
Writing Python code in SyntaxHighlighter Code block like this:
a = b”’
starts a kind of multi-line comment, as if the highlighter confuses the ”’ (single quote – double quote – single quote) with ”’ (three single quotes).
-
Hmm, the code got mangled when posted. Hopefully it will display correctly this time.
a = b'"' -
Thanks for getting in touch!
Can you check the settings for that block and make sure you selected “Python” in the “Code Language” settings as noted here?
Screenshot: https://d.pr/i/A7Z7dX
If you do have that selected, can you let us know what post or post draft you have where it’s not working so we can take a closer look?
Thanks!
-
Can you check the settings for that block and make sure you selected “Python” in the “Code Language” settings as noted here?
Of course I did :-)
If you do have that selected, can you let us know what post or post draft you have where it’s not working so we can take a closer look?
Of course – here it is: https://mikekaganski.wordpress.com/2021/02/18/reading-from-mysql-data-with-blobs-dumped-to-csv/
-
-
Ok, I wanted to make sure before I start digging into things since it defaults to plain text. :D
I’ll take a closer look and be back in touch once I have more information. Thanks!
-
It looks like you’ve found a unique issue with your Python code! :)
The string
'"'is technically a triple quote – which in Python, acts as another way to comment out a block of code and is why everything between the first'"'on line 48 and the second'"'on line 65 is commented out.You’ll need to escape the double quote in one or both of those strings in order to break that behavior.
I tested it by changing the one on line 48 to
if ch == b'"':and that fixed the syntax highlighting upon preview. I didn’t save those changes, so you would need to make those changes yourself.I hope that helps!
-
The string
'"'is technically a triple quote – which in Python, acts as another way to comment out a block of codeNo. First of all, the triple quote is not “another way to comment out a block of code”, it is a multiline string literal (longstring). In Python, developers often (mis)use the standalone string literals (both conventional single-line and such multiline) for comments, but that does not make such use the primary meaning of this construct.
Second, the only valid “triple quote” is three identical quotes: e.g., three single quotes
''', or three doublequotes""". No mix is allowed there. So no, the workaround you suggest is not a fix of the bug that actually exists in the highlighter.I hope that helps ;-) My intention actually is inform you to let you make the feature better :-)
-
(and if the longstring starts with triple singlequotes, it must also end with triple singlequotes.)
-
Fair enough! I’m not a programmer – just someone who Googled Python syntax and tested it. :)
Our blocks are on a public GitHub repo and I didn’t see any open issue related to this particular bug where we’re treating single quotes and double quotes as interchangeable quotes. Could you please open up a new issue for the development team here so they can get that fixed up? You can do so here:
https://github.com/Automattic/wp-calypso/issues/new/choose
You’ll be updated when they have a chance to review the request as well, so you’ll be the first to know when it’s fixed.
Thanks again for letting us know!
-
- The topic ‘Bug in SyntaxHighlighter Code block with specific Python code’ is closed to new replies.