CommonMark testing started here!

Cool - thanks for thinking about image alignment, which may seem unimportant in the grand scheme of things but would be a big help to us.

Right now, my colleague is trying to display some profile pictures with biographical details attractively over here on my discourse.

Interestingly, I was able to get something close to attractive on the commonmark.js demo site:

Here’s the code I used to create that:

[<img src="https://community.namati.org/uploads/default/original/2X/4/44c8fd629b36d97fe0c6e618fc99bb84497768bd.jpg" width="170" height="125" align="left">](https://namati.org/network/member/LucyClaridge) Lucy Claridge (@LucyClaridge)  is Legal Director at Minority Rights Group International, where she manages the legal department.  Her work uses strategic litigation, advocacy and capacity building to improve access to justice for minority and indigenous communities worldwide, with a particular focus on land rights, political participation and wider anti-discrimination issues.  Casework includes the recent Ogiek land and conservation case against Kenya before the African Court of Human and Peoples' Rights.

Nah we are fine as is. I don’t want to whitelist a ton of random stuff that we don’t need, every one is a security risk in the long term.

@sam, so that works great for when markdown-it is enabled, however, when it is disabled, I now get

ember:19818 Error: Could not find module `pretty-text/engines/markdown-it/helpers` imported from `discourse/plugins/discourse-plugin-checklist/lib/discourse-markdown/checklist`
    at requireFrom (discourse-loader:128:13)
    at reify (discourse-loader:106:22)
    at mod.state (discourse-loader:163:17)
    at tryFinally (discourse-loader:30:14)
    at require (discourse-loader:162:5)
    at eval (pretty-text/engines/discourse-markdown:381:26)
    at Array.forEach ()
    at DialectHelper.setup (pretty-text/engines/discourse-markdown:379:40)
    at setup (pretty-text/engines/discourse-markdown:456:12)
    at buildOptions (pretty-text/pretty-text:59:36)

It seems to not like my importing of the helper when markdown-it is not enabled. Is there a way to avoid that error? I tried using

  if (helper.markdownIt)
  {
    const prettyTextHelper = require('pretty-text/engines/markdown-it/helpers');
    helper.registerPlugin(md => {
      const ruler = md.inline.ruler;
      ruler.push('checklist-strikethrough', prettyTextHelper.inlineRegexRule(md, {
        start: '--',
        matcher: /--(.*)--/i,
        emitter: applyStrikethrough
      }));

      ruler.push('checklist-empty-checkbox', prettyTextHelper.inlineRegexRule(md, {
        start: '[',
        matcher: /\[([\s_\-x\*]{0,1})\]/i,
        emitter: applyCheckbox
      }));
    });
  }

versus an import at the top, but that didn’t work. Otherwise, I may just have to leave this in a branch until markdown-it becomes the default (which I’m not opposed to)

Yeah… you are going to need this PR

Note you can do the strikethrough like you had with the inline regex, but checkboxes you can not. You need to apply at the end of the chain otherwise there be :dragon:

Just import the helper using:

// import like this for backwards compat, add a comment
require('pretty-text/engines/markdown-it/helpers').inlineRegexRule

I think I will clean the API up a bit so we just hang the helpers of the md object then you don’t need to import anything.

Hmm, I’m struggling getting that PR to work. I’ve pulled it in locally, kicked up the docker dev environment, but I can’t get the checkboxes to show with or without markdown-it enabled.

I’ve even completely destroyed the docker dev environment and re-initialized.

Edit:
Figured it out, this errant return; statement
https://github.com/cpradio/discourse-plugin-checklist/pull/9/commits/1ff70f501da887b1486a2d97f265e2d6a7dbf298#diff-58d619630012ba3d44eea8bdb4f2440bR114

However, there is already :dragon:: with the current implementation, given the following, it breaks

[] Item One
[*] Item Two (should be checked)
[ ] Item Three
[*] Item Four (should also be checked)

Actual output:, Items Two through Four are italized.


I’ve got that fixed, however, now with markdown-it turned off, the fix for the italize is causing checking a checkbox to not show properly (preview pane shows it properly though when you edit the post afterwards).

It is only breaking with markdown-it disabled. But for the life of me, I haven’t a clue why, as when I trace it down, it is replacing [\*] with the appropriate span tag and classes, but when it saves the post, the [\*] reappears from seemingly nowhere…

Granted, this can happen with [_] as well on new markdown-it, but that value can’t be generated by clicking the checkbox, so the user should see the issue and escape it before it is submitted. Only [*] is capable of being written based on the user clicking a box.

Updated PR to look at (which has your PR and the fixes I described above – and the issue with markdown-it disabled)
https://github.com/cpradio/discourse-plugin-checklist/pull/9

2 Likes

I see that headings have changed from ##heading to ## heading (with a space).
What happens to the old topics that use ##heading instead of ## heading after the upgrade?

We have to do a remap as describe here Replace a string in all posts ?

If you don’t rebake old posts they will keep the current generated HTML.

3 Likes

And become a time bomb, waiting to break in the future.

7 Likes

I’ve already seen a topic of mine here on Meta break. Sub-bullets now need two spaces, not one, so when someone edited a wiki post of mine my bulleted list broke.

I wonder @sam if any sort of migration script is planned?

1 Like

Very super undecided on a migration script. The concern I have is that it is possible a migration script can mess stuff up more than it will actually help.

I am semi open to making a script that fixes up bad multiline quotes (one’s that start mid line) and maybe the title thing.

Will think about it.

4 Likes

If you store bake time and switch to new engine time, you can punt on a script to deal with later, or to just highlight warnings when appropriate.

“You are editing a post that predates the current parser. Please double check that the syntax still works as expected.”

2 Likes

No, this is not needed at all. I would not bother. People can fix up the rare affected posts themselves.

2 Likes

@sam, can you think of a better way than to deal with two checked items in the checklist producing italized content without escaping the *?

I plan to mess around with the plugin a bit more this week, but I may just ditch trying to support backwards compatability and just wait for the markdown-it to be official and default. I’ve used the approach in the past, by simply tagging a prior version of the plugin and older installs can utilize that (if they are not ready to upgrade).

2 Likes

@Vitaly I have come across an interesting edge case here.

At Discourse we use “raw” html for images cause we need to specify size and sadly you can not specify size in CommonMark (which for the record makes me super :sadpanda:)

So if you have:

<img src="//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">
<img src="//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">  
<img src="//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">

It will render as:



Despite newline being enabled here. This happens cause there is no “inline” defined for the images.

I can work around with:

<img src="//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">&nbsp;
<img src="//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">  
<img src="//assets-meta-cdck-prod-meta.s3.dualstack.us-west-1.amazonaws.com/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">

 

I guess I just need a custom inline rule here that wraps and <img in an inline.

Also opened this up:

Do you need to specify any possible size or select from pre-defined set?

I think we need to split problem. Is it about:

  • sepecifying custom image size
  • line breaks between <img> tags
  • both

?

I need to specify any possible size, this becomes super critical stable layout on the page.

I guess what you are trying to determine here is if we could have a custom post processing job that injects size into the HTML and takes this decision away from the user.

My answer to this would be … maybe… If you upload retina you want to specify the smaller size so the retina screens get high fidelity and non-retina just get scaled down. It is possible we could glue this information into an EXIF tag or something and then have a post processor magic an SRCSET. But it would be a huge change.

line breaks between <img> tags

We absolutely need to deal with this cause we have tons of history, I can hack html_block.js to support this edge condition quite easily. But I also think the spec needs an adjustment here.

sepecifying custom image size

I also think the spec should deal with this, especially cause of the HiDPI concern.

In general, everything is blocked by spec. I can explain solutions i know, but all those are not ideal.

Image size can be defined:

  • via html
    • Not convenient.
  • via maruku-like syntax ({attrs} after any markdown element, see “consistend attributes syntax” thread at CM forum)
    • Require parser core update for correct work. Such deep core updates are not welcome without spec change
    • This open the road to tons of vulnerabilities without sanitizer. That’s the main reason why i don’t like this feature to be enabled by default.
    • Can be hacked via image rule replace, but that’s too dirty, because code itself is a bit complicated.
    • Not sure this will ever go to spec.
  • via alt attribute content
    • [alt text|100x200](http://....), [alt text|small](http://....)

So, i described the situation, but don’t like to take responsibility for your choice. IMHO, right now every choice is not ok. Because problem is on spec level, and i can’t push it forward. In nodeca, i decided to use alt content, but only to select between predefined sm|md|orig sizes, not to set WxH. Also, nodeca does not pretend to define de-facto standards.

About keeping breaks between <img> tags. IMHO it’s impossible to solve this problem easy on spec level. Because if you have a line with <img> tag only, it’s impossible to say, is it a raw block, or paragraph with raw inline element. I think, right now it’s better to hack html_block rule to filter out <img> tags - more easy to update in future.

5 Likes

Thanks heaps, totally understand, we are just stuck with no ideal solution here.

I really like this syntax proposal cause it is far simpler to parse and the Markdown looks much cleaner. Sure it is not as “flexible” as maruku like syntax but it is far prettier. I think we may migrate to it.

1 Like

What is the specific markdown that you have that is failing?