# “插入日期”渲染在与 HTML 混合时可能会失效

**URL:** <https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959>\
**Category:** Bug\
**Created:** [2018年六月28日 15:20 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959 "2018-06-28T15:20:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)\
**Post date:** [2018年六月28日 15:20 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/1 "2018-06-28T15:20:47Z")

</div>

Continuing the discussion from [Date selector in Topic Timer](https://meta.discourse.org/t/date-selector-in-topic-timer/90335/4):

> [@j.jaffeux](#):
>
> You can try to “insert date” in the composer gear icon

## Problem

 ![2018-06-28-170215](https://global.discourse-cdn.com/meta/original/3X/d/f/dfb1ea3828865d05e5bb1fbb68d4ca63b1e0c50f.png)

I tried to reproduce here, using multiple dates, and inserting code fences blocks, but it didn’t reproduce until  
[https://try.discourse.org/t/testing-insert-date-bug/1130/2](https://try.discourse.org/t/testing-insert-date-bug/1130/2) (this link will become obsolete by tomorrow, but it shows like the screenshot above.)

## Cause

Finally I found the cause of the bug: the failing render follows an HTML tag with an attribute!

```markdown
<abbr title="Coordinated Universal Time">UTC</abbr>

[date=2018-06-28 time=07:00 format=“HH:mm” timezones=“Europe/Brussels”] ![:arrow_right:](//cdck-file-uploads-global.s3.dualstack.us-west-2.amazonaws.com/meta/original/3X/5/a/5aa33b89419423f0712cf1e6c72f0813cb3f082c.png) [date=2018-06-28 time=15:00 format=“HH:mm” timezones=“Europe/Brussels”]

```

fails to render:

UTC

07:00 ![:arrow_right:](https://global.discourse-cdn.com/meta/original/3X/5/a/5aa33b89419423f0712cf1e6c72f0813cb3f082c.png) 15:00

## Solution

Avoid using HTML tags in Markdown – Or maybe [implement \<abbr\> in CommonMark](https://talk.commonmark.org/t/abbreviations-and-acronyms/890). 🙂

I suppose that an HTML tag appearing in a previous paragraph should not affect rendering later on though.

**In any case: when things fail, check for a mix of HTML and Markdown.**

---

<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:** [2018年六月28日 20:45 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/2 "2018-06-28T20:45:43Z")

</div>

Why do you need to use an emoji arrow? Use →

---

<div class="post-metadata">

**Author:** ![hellekin](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hellekin/32/51636_2.png) [@hellekin](https://meta.discourse.org/u/hellekin)\
**Post date:** [2018年六月28日 20:47 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/3 "2018-06-28T20:47:19Z")

</div>

I simply pasted the result I got from using the ‘Insert Date’ button. The emoji transformation must be part of the cooking.

Edit: here is pasted the original character ➡ (or `➡` with backquotes)

Edit:

```ruby
'➡'.unpack('U*')
=> [10145]

```

---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [2018年六月28日 22:14 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/4 "2018-06-28T22:14:10Z")

</div>

Yes `➡` will be cooked as an emoji

I will give it a look to this tomorrow.

Test:

A

07:00

---

<div class="post-metadata">

**Author:** ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)\
**Post date:** [2018年七月4日 21:50 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/5 "2018-07-04T21:50:09Z")

</div>

这实际上与 insert-date 无关。这是 `textPostProcess` 的一个限制。

例如，它在使用分类时也会失败，第一个会正常工作，但 `abbr` 之后的任何内容都不会（正如 @sam 提到的）：

* * *

#Contribute > Feature

`<abbr>A</abbr>`

A

#Contribute > Feature

* * *

我的理解是，`abbr` 之后的下一个块会被转换为段落，而不会被 `textPostProcess` 解释。这是我们的沙盒器（sanitizer）的行为，参见 [https://github.com/discourse/discourse/blob/master/test/javascripts/lib/sanitizer-test.js.es6#L117：](https://github.com/discourse/discourse/blob/master/test/javascripts/lib/sanitizer-test.js.es6#L117%EF%BC%9A)

@sam 有什么想法吗？你觉得值得修复吗？在我看来，这似乎是一个非常非常边缘的情况。

---

<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:** [2018年七月4日 22:16 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/6 "2018-07-04T22:16:44Z")

</div>

Something is not right internally cause `<small>` does not cause this issue nor does `<sub>` or `<ins>` or `<kbd>`

I am guessing this is something internally is broken in sanitizer that is specific to this inline tag. Probably worth fixing.

---

<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:** [2018年七月4日 23:28 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/7 "2018-07-04T23:28:24Z")

</div>

OK this was an `<abbr>` and all other tags that start with `<a` specific bug.

Fixed per:

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

---

<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:** [2018年七月6日 08:00 UTC](https://meta.discourse.org/t/insert-date-rendering-may-break-when-mixed-with-html/90959/8 "2018-07-06T08:00:00Z")

</div>

This topic was automatically closed after 32 hours. New replies are no longer allowed.
