# 纯文本表格检测应尊重代码围栏

**URL:** <https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894>\
**Category:** Bug\
**Created:** [2019年四月24日 20:21 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894 "2019-04-24T20:21:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [2019年四月24日 20:21 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894/1 "2019-04-24T20:21:02Z")

</div>

When pasting text inside a code fence block, the rich-to-markdown support is disabled.

“plain text table” detection should be disabled as well.

---

<div class="post-metadata">

**Author:** ![venarius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/venarius/32/133142_2.png) [@venarius](https://meta.discourse.org/u/venarius)\
**Post date:** [2019年四月24日 20:22 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894/3 "2019-04-24T20:22:47Z")

</div>

Will have a look 🙂

---

<div class="post-metadata">

**Author:** ![venarius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/venarius/32/133142_2.png) [@venarius](https://meta.discourse.org/u/venarius)\
**Post date:** [2019年四月25日 07:18 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894/4 "2019-04-25T07:18:14Z")

</div>

Hmm, maybe I am a bit stuck here…

`d-editor` has an action called `paste`, in which it detects if you can paste HTML:

````plaintext
canPasteHtml = !isInside(pre, /(^|\n)```/g);

````

This returns false if you are currently inside of a code fence block. The conversion of the text into markdown happens in this function:

```plaintext
if (canPasteHtml && ...) {
      let markdown = toMarkdown(html);
}

```

So, conversion to markdown only happens when not inside of a code fence block. From what I understand, the “plain text table” detection is part of the markdown-it and hence should also be disabled here, because it’s not trying to convert the pasted text.

Am I missing out on something here?

---

<div class="post-metadata">

**Author:** ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)\
**Post date:** [2019年四月25日 08:10 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894/5 "2019-04-25T08:10:37Z")

</div>

Currently plain text table detection is not part of the “HTML pasting” feature. It is happening [here](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/components/d-editor.js.es6#L805-L812). I think you have to move it to the end of [this `if` condition](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/components/d-editor.js.es6#L827).

---

<div class="post-metadata">

**Author:** ![venarius](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/venarius/32/133142_2.png) [@venarius](https://meta.discourse.org/u/venarius)\
**Post date:** [2019年四月25日 08:14 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894/6 "2019-04-25T08:14:13Z")

</div>

Ouh, yeah, I see it. Thanks a lot!

EDIT: Opened a PR

[https://github.com/discourse/discourse/pull/7436](https://github.com/discourse/discourse/pull/7436)

---

<div class="post-metadata">

**Author:** ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)\
**Post date:** [2019年四月26日 13:31 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894/7 "2019-04-26T13:31:30Z")

</div>

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

It’s done as per the above commit. Thanks for the PR! ❤ @venarius.

---

<div class="post-metadata">

**Author:** ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)\
**Post date:** [2019年四月26日 16:00 UTC](https://meta.discourse.org/t/plain-text-table-detection-should-respect-code-fences/115894/8 "2019-04-26T16:00:17Z")

</div>

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