Bug in Markdown plugin where it won't work with URLs that have a + in them (like course About links)

@fghaas, I couldn’t find a way to contact you via github about the GitHub - citynetwork/markdown-xblock: An XBlock enabling Open edX course authors to maintain content in Markdown. plugin. It seems if I put in a URL like
[test](https://test.com/courses/course-v1:Org+Class+Version/about)
When I click through the link, it shows up as broken. But if I paste the link in, it works just fine. I think this has something to do with the + being encoded as %20. Because I saw other things on the internet suggesting that sometimes Markdown doesn’t like encoding like this (e.g. Links in markdown are broken if url contains encoded parameters · Issue #79474 · microsoft/vscode · GitHub)

Can you let me know if this is a known issue and I just need to upgrade or something?

I couldn’t find a way to contact you via github

Oh, sorry about that! Looks like since that XBlock’s repo started life as a fork of another one, GitHub didn’t enable issues for that repo from that get-go. I’ve enabled the Issues tab now.

By the way: @mrtmm is doing the bulk of the functional work on that XBlock; my commits are just scaffolding and tests and docs. :slight_smile:

Back to your question, I think Discourse is actually eating the link you posted, so I can’t really comment on what’s breaking for you. So try the following suggestion, and if after that things still aren’t working for you, then please do go ahead and post an issue on GitHub and we’ll take it from there: could it be that you’re getting burned by the default safe_mode setting (replace), and what you want is escape? We recently added a discussion of the safe_mode setting to the README; you might want to take a quick peek at that.

Please let me know if that information is helpful. Thank you!

My bad, you’re right, discourse was interpreting the link as Markdown and I didn’t realize it. I fixed it to fully show up.

So, I’d like to give that a try, but I’m using Tutor and unfortunately I don’t know how to set multi-line configurations in Tutor like XBLOCK_SETTINGS seems to be. Someone else was mentioning the same question here, so I’m just watching it and waiting for an answer:

All right, I can confirm this issue. If you’re curious, here’s the PR that adds the unit tests for this scenario:

As far as I can tell there’s not much that the XBlock can do about it, as this behavior is buried rather deep within the Markdown processor that the XBlock uses. However, you have two options to work around this issue:

  1. Disable safe_mode. Not recommended, unless you have a pressing need for inline HTML in Markdown for some other reason.
  2. Leave safe_mode enabled, and URL-encode your links. This is what I’d recommend in your case. For example, use
    [link text](https://test.com/courses/course-v1%3AOrg%2BClass%2BVersion/about)
    
    instead of
    [link text](https://test.com/courses/course-v1:Org+Class+Version/about)
    

Please let me know if that information is helpful. Thank you!

I’ll give URL encoding of links a try. Though it appears to me that the markdown plugin itself is URL encoding things when I mouse over them. But if that doesn’t work, I’ll try changing the settings, now that that post above explained how to do multi-line settings.

FYI, information on how to include course links is now included in the Usage notes section of the package documentation:

I confirmed that replacing + with %2B works (thought the other instructors are definitely going to complain about having to do that :-/. So if there was some way to make it just work that’d be great. But this is an acceptable workaround for now.)

The way to make it “just work” is to disable safe mode, with all the additional implications that that has. I wouldn’t recommend that though, and if I were in your shoes I’d much prefer the URL-encoded approach.

Hello Florian (and @mrtmm since I see she was the last one to commit to the repo.) Now that Tutor’s the default Open edX install method, can you provide some guidance on how to disable safe_mode in tutor? I tried the following:

name: disable_markdown_safemode
version: 0.1.0
patches:
  openedx-lms-common-settings: |
    XBLOCK_SETTINGS["markdown"] = {
    "safe_mode": False
    }

to no avail :frowning:

I think /home/tutor/.local/share/tutor/env/apps/openedx/config/lms.env.json is where ultimately the tutor plugins get injected into, but there’s no grep hits for XBLOCK_SETTINGS in there, so I assume my syntax is way off…

Hi @Rohan! You were very close, I believe this should work:

name: disable_markdown_safemode
version: 0.1.0
patches:
  openedx-common-settings: |
    XBLOCK_SETTINGS["markdown"] = {
      'safe_mode': False
    }

1 Like

This works! Thank You!

1 Like