# CommonMark testing started here!

**URL:** https://meta.discourse.org/t/commonmark-testing-started-here/65121
**Category:** Feature
**Created:** [2017年六月26日 12:44 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121 "2017-06-26T12:44:40Z")
**Posts on this page:** 20
**Page:** 4

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年七月7日 17:10 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/69 "2017-07-07T17:10:48Z")

</div>

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](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:

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

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

```

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [2017年七月7日 17:15 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/70 "2017-07-07T17:15:40Z")

</div>

Will [image alignment](https://meta.discourse.org/t/image-alignment/15408) be made possible with commonmark?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年七月7日 17:19 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/71 "2017-07-07T17:19:47Z")

</div>

Not much progress in the CommonMark world there…

> **[Consistent attribute syntax](https://talk.commonmark.org/t/consistent-attribute-syntax/272)**
>
> Eventually, the spec should specify a consistent way to add attributes to at least the following elements: headers, images, code blocks (and maybe even tables, block quotes and inline code and quotes). The most important attributes are certainly...

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?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年七月7日 17:26 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/72 "2017-07-07T17:26:21Z")

</div>

We are back to no open bugs per:

[https://github.com/discourse/discourse/commit/6f09df0deb33e9fd2f761020ec11e90ef6d832a6](https://github.com/discourse/discourse/commit/6f09df0deb33e9fd2f761020ec11e90ef6d832a6)

and

[https://github.com/discourse/discourse/commit/436b894f7ace3627bc3ef504a6c2c94329f2d4ab](https://github.com/discourse/discourse/commit/436b894f7ace3627bc3ef504a6c2c94329f2d4ab)

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [2017年七月7日 18:34 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/73 "2017-07-07T18:34:12Z")

</div>

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](https://community.namati.org/t/webinar-the-ogiek-victory-a-closer-look-at-strategic-litigation-for-land-rights-august-2nd/37251?u=tobiaseigen) on my discourse.

Interestingly, I was able to get something close to attractive on the [commonmark.js demo site](http://spec.commonmark.org/dingus/):

 ![](https://global.discourse-cdn.com/meta/original/3X/8/8/88ac1be27ddbf8cf43c59a7320c15f29c85b731e.jpg)

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.

```

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2017年七月7日 20:21 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/74 "2017-07-07T20:21:42Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2017年七月7日 21:21 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/75 "2017-07-07T21:21:34Z")

</div>

@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

```plaintext
  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)

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年七月7日 21:25 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/76 "2017-07-07T21:25:17Z")

</div>

Yeah… you are going to need this PR

[https://github.com/cpradio/discourse-plugin-checklist/pull/9](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 🐉

Just import the helper using:

```plaintext
// 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.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2017年七月7日 23:46 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/77 "2017-07-07T23:46:30Z")

</div>

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](https://github.com/cpradio/discourse-plugin-checklist/pull/9/commits/1ff70f501da887b1486a2d97f265e2d6a7dbf298#diff-58d619630012ba3d44eea8bdb4f2440bR114)

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

```plaintext
[] 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).

 ![](https://global.discourse-cdn.com/meta/original/3X/4/5/45f39bffbf7d1308a9b8ba61cad9df9b3de52357.png)

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](https://github.com/cpradio/discourse-plugin-checklist/pull/9)

---

<div class="post-metadata">

### Author: ![dax](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dax/32/244677_2.png) [@dax](https://meta.discourse.org/u/dax)
#### Post date: [2017年七月8日 10:02 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/78 "2017-07-08T10:02:19Z")

</div>

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](https://meta.discourse.org/t/replace-a-string-in-all-posts/48729) ?

---

<div class="post-metadata">

### Author: ![Falco](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/falco/32/179432_2.png) [@Falco](https://meta.discourse.org/u/Falco)
#### Post date: [2017年七月8日 20:18 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/79 "2017-07-08T20:18:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2017年七月8日 21:25 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/80 "2017-07-08T21:25:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [2017年七月8日 21:52 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/81 "2017-07-08T21:52:05Z")

</div>

> [@elijah](#):
>
> waiting to break in the future.

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?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年七月9日 00:58 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/82 "2017-07-09T00:58:37Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![elijah](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/elijah/32/104055_2.png) [@elijah](https://meta.discourse.org/u/elijah)
#### Post date: [2017年七月9日 01:17 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/83 "2017-07-09T01:17:39Z")

</div>

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.”

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2017年七月9日 03:28 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/84 "2017-07-09T03:28:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [2017年七月9日 22:59 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/86 "2017-07-09T22:59:57Z")

</div>

@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).

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [2017年七月10日 13:58 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/87 "2017-07-10T13:58:12Z")

</div>

@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:

```plaintext
<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">
<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">  
<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">

```

It will render as:

 ![](https://global.discourse-cdn.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png)  
 ![](https://global.discourse-cdn.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png)  
 ![](https://global.discourse-cdn.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png)

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

I can work around with:

```plaintext
<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">&nbsp;
<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">  
<img src="//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png" width="202" height="148">

```

 ![](https://global.discourse-cdn.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png)&nbsp;  
 ![](https://global.discourse-cdn.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png)  
 ![](https://global.discourse-cdn.com/meta/original/3X/4/4/44982d8594abd49582092a61252ed655a578dad7.png)

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

Also opened this up:

> **[Newline and IMG tags](https://talk.commonmark.org/t/newline-and-img-tags/2511)**
>
> Given that we still have no way of specifying image size in CommonMark we are stuck using tags in Discourse. Trouble is, it is terribly hard to format multiple images on lines by themselves, this is so bad that I feel I need to divert from spec...

---

<div class="post-metadata">

### Author: ![Vitaly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vitaly/32/120475_2.png) [@Vitaly](https://meta.discourse.org/u/Vitaly)
#### Post date: [2017年七月10日 14:31 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/88 "2017-07-10T14:31:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Vitaly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vitaly/32/120475_2.png) [@Vitaly](https://meta.discourse.org/u/Vitaly)
#### Post date: [2017年七月10日 14:37 UTC](https://meta.discourse.org/t/commonmark-testing-started-here/65121/89 "2017-07-10T14:37:41Z")

</div>

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

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

?

[上一頁](https://meta.discourse.org/t/commonmark-testing-started-here/65121.md?page=3)

[下一頁](https://meta.discourse.org/t/commonmark-testing-started-here/65121.md?page=5)
