• Okay, I finally decided to let go my beloved, yet ancient, copy of Markdown Extra and let Jetpack do all the lifting. I’m suffering what seem to be the usual transition issues — some posts are appearing in their markdown jammos — but I can live with it because I don’t mind refreshing the fairly limited number of older posts that still get significant traffic.

    One issue I can’t figure out is what’s happening when I drop in a code block (in my case it’s Python). My habit is to do it with fences like this:

    `python
    Some code here
    `

    When I do that, however, I get a lot of this: colnames = ['author',.

    I’m using Syntax Highlighter Evolved, and when I deactivate it, all I get is a short code, [code lang=python] and then no actual formatting for the code block.

    Despite running WP for a decade, I'm still terrible at troubleshooting plug-ins -- I guess that's why I held onto PHP Markdown Extra for so long. It was just so reliable.

    EDIT: I forgot to add a link to the relevant post:

    http://johnlaudun.org/20170129-getting-word-frequencies-for-2000-texts/

    • This topic was modified 9 years, 4 months ago by johnlaudun.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Thanks for the report.

    Jetpack happens to use the Markdown Extra library as well, so the switch should be smooth. Let’s see if we can fix what’s happening on your site.

    One issue I can’t figure out is what’s happening when I drop in a code block (in my case it’s Python). My habit is to do it with fences like this:

    Unfortunately the forums seem to have eaten some of the code you posted here, so I’m not sure how you usually format your code snippets. When posting a Python snippet and using Syntax Highlighter Evolved, here is the expected syntax:

    
    [code language="python"]
    print("Hello World!")
    [/code]
    

    If you ever deactivate the Syntax Highlighter Evolved plugin when using this syntax, the shortcodes will be displayed as is.

    When using Markdown (and Jetpack Markdown), you can also use fenced code blocks like so:
    https://gist.githubusercontent.com/jeherve/25c8e38b63a0f42ff79263bbed3ef19e/raw/c4b9631e657333149251ccd4425425445c0a1657/python.md

    Do you think you could post the full content of one of your blog posts in a Pastebin or on Gist, and send me a link so I can check how Jetpack renders the content on my own test site?

    Thanks!

    Thread Starter johnlaudun

    (@johnlaudun)

    Sorry about that. Here’s a Gist with the markdown as I wrote it:

    https://gist.github.com/johnlaudun/e348c561607d6369cc8dde8e784e3eac

    And I went ahead and captured images with the syntax Highlighter Evolved plugin both activated and de-activated:

    http://johnlaudun.org/20170131-jetpack-markdown-troubleshooting/

    And, in fact, it was when I realized that PHP Markdown Extra had been rolled into Jetpack — yeah, I didn’t check the documentation like I should have years ago — that I felt a sort of *Doh!* moment of “why not switch to the more current implementation?”

    Sorry, you asked for the full post. Here’s the gist of it:

    https://gist.github.com/johnlaudun/d0a4306e35563f4db90526e3936ee266

    • This reply was modified 9 years, 4 months ago by johnlaudun.
    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Here is how it looks on my end when Jetpack Markdown is active, but the syntax Highlighter Evolved plugin is inactive:
    http://i.wpne.ws/ixso
    http://i.wpne.ws/ix9s

    Nothing changes when I activate the Syntax Highlighter Evolved plugin.

    Then, I tried with this post content:
    https://gist.githubusercontent.com/jeherve/57f392f9687a43f5787123b394e773c0/raw/032cc902d5c04150f0a6c64d45870197d72ddf54/content.txt

    Here is how things look like when Syntax Highlighter Evolved is active:
    http://i.wpne.ws/ixYE
    http://i.wpne.ws/ixrv

    Once I deactivate the plugin everything becomes a mess, as expected:
    http://i.wpne.ws/ixFQ

    Unfortunately I never quite get the results you got on your end. It seems that all ' signs get encoded for some reason.

    Do you use the visual editor to compose and edit your posts, or the Text editor?

    Could you try to create a new post, while both Jetpack Markdown and Syntax Highlighter Evolved are active, only using the Text Editor, and paste the content here in the editor?
    https://gist.githubusercontent.com/jeherve/57f392f9687a43f5787123b394e773c0/raw/032cc902d5c04150f0a6c64d45870197d72ddf54/content.txt

    Let me know how it goes.

    Thread Starter johnlaudun

    (@johnlaudun)

    Here’s the editor I use: http://johnlaudun.org/20170131-the-wp-editor-i-use/ (It looks just like the editing bar in these text boxes.)

    I’m glad you are also see the difficulty with the single quote mark/apostrophe. What I don’t get is why if I de-activate the syntax highlighter I get the WP short code and not the HTML for <pre> which should then generate the visual code block.

    Okay, here’s the entry’s content:

    Okay, here’s some regular prose, which isn’t explanatory at all, and then here comes a block of code:

    `python
    from stop_words import get_stop_words
    from nltk.corpus import stopwords

    mod_stop = get_stop_words(‘en’)
    nltk_stop = stopwords.words(“english”)

    print(“mod_stop is {} words, and nltk_stop is {} words”.format(len(mod_stop), len(nltk_stop)))
    `

    returns:

    `python
    mod_stop is 174 words, and nltk_stop is 153 words
    `

    And here it is live: http://johnlaudun.org/20170131-test-post-with-jp-markdown-and-syntax-highlighting-activated/

    Interesting, when I first posted this, I got a plain code block — with the apostrophe’s converted to the &#xxx; form, and when I double-checked that the syntax highlighter was active, which it was, and came back to the page, I got the plain and then, after a one-second delay, an update with the highlight.

    Okay, so I think, first, this syntax highlighter is a little wonky, and I don’t really need my code to be pretty. All I really want is for quotation marks, be they single or double, and open and close angle brackets not to get converted to their encoded form.

    • This reply was modified 9 years, 4 months ago by johnlaudun.
    Thread Starter johnlaudun

    (@johnlaudun)

    Oh, goodness, I deleted the syntax highlighter and now all I see is the short code on those posts. Is the next trouble-shooting step to deactivate Jetpack and/or re-install it? (This feels like more of a voodoo move than anything else, but, like I said, my trouble-shooting skills with WP’s PHP codebase are as close to zero as it gets.)

    Plugin Author Jeremy Herve

    (@jeherve)

    Jetpack Mechanic 🚀

    Interesting, when I first posted this, I got a plain code block — with the apostrophe’s converted to the &#xxx; form, and when I double-checked that the syntax highlighter was active, which it was, and came back to the page, I got the plain and then, after a one-second delay, an update with the highlight.

    Okay, so I think, first, this syntax highlighter is a little wonky, and I don’t really need my code to be pretty.

    This is somewhat common when using the Syntax Highlighter Plugin. It has happened to me in the past, but always when I made the mistake of using the Visual Editor instead of the Text editor.

    Since you seem to be using the Text editor, this shouldn’t be happening.

    For what it’s worth, Jetpack’s Markdown module won’t process content that’s inside a shortcode, so it won’t touch anything inside a [code] block.

    I deleted the syntax highlighter and now all I see is the short code on those posts.

    That's the expected result. Once you deactivate the plugin that manages the shortcode, there is nothing left to process the shortcode and transform them into code blocks.

    As long as you use the shortcodes in your posts, you'll need to use this plugin.

    At this point, it might be worth trying to replace all instances of [code] or [code language=python] by Markdown fenced blocks like so:
    https://gist.githubusercontent.com/jeherve/25c8e38b63a0f42ff79263bbed3ef19e/raw/c4b9631e657333149251ccd4425425445c0a1657/python.md

    Can you confirm that things work well when using this syntax?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘JP Markdown and Code Blocks’ is closed to new replies.