CommonMark testing started here!

Yeah, you have to use cookAsync from now on, will check in a deprecation message there.

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/text.js.es6#L26-L33

So your new code would be something like:

  let props = {
     raw: new_raw,
     edit_reason: 'checklist change',  
  };

  cookAsync(new_raw).then(cooked => {
      props.cooked = cooked.string;  
      viewPost.save(props);
  });
      

3 Likes

Will image alignment be made possible with commonmark?

Not much progress in the CommonMark world thereā€¦

But ā€¦ since we already only use HTML based image metadata, whitelisting a few classes is super easy in a plugin.

@codinghorror I wonder if we should just whitelist a few here out of the box?

2 Likes

We are back to no open bugs per:

https://github.com/discourse/discourse/commit/6f09df0deb33e9fd2f761020ec11e90ef6d832a6

and

https://github.com/discourse/discourse/commit/436b894f7ace3627bc3ef504a6c2c94329f2d4ab

4 Likes

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

https://github.com/cpradio/discourse-plugin-checklist/pull/9

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

?