# Disable indent code block for emails

**URL:** https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707
**Category:** Feature
**Created:** [August 2, 2018, 2:30am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707 "2018-08-02T02:30:23Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [August 2, 2018, 2:30am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/1 "2018-08-02T02:30:23Z")

</div>

Many posts in my forums are created via email. They do not contain code.

Would appreciate a setting to turn off the four-character code-block feature of Markdown when the post originated from an email.

That is to prevent many email paragraphs being turned into code blocks due to paragraph indents.

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [August 2, 2018, 6:12am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/2 "2018-08-02T06:12:54Z")

</div>

I wholeheartedly second this request with an extra ❤.

---

<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: [August 2, 2018, 6:19am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/3 "2018-08-02T06:19:37Z")

</div>

hmmm … I thought we had `incoming email prefer html` and that is default on?

So you are saying you have people composing stuff in plain text mode and indenting?

Can you reply to this post via email with an example problem?

---

<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: [August 2, 2018, 9:15am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/4 "2018-08-02T09:15:37Z")

</div>

> [@sam](#):
>
> So you are saying you have people composing stuff in plain text mode and indenting?

No, it’s the email client that’s adding these whitespaces (in the HTML version).

The actual bug is that our html-to-markdown library isn’t interpreting whitespace as well as the browser does.

[https://medium.com/@patrickbrosset/when-does-white-space-matter-in-html-b90e8a7cdd33](https://medium.com/@patrickbrosset/when-does-white-space-matter-in-html-b90e8a7cdd33)

It’s been on my TODO list since the inception of incoming email support.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [August 3, 2018, 11:46am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/5 "2018-08-03T11:46:29Z")

</div>

We do have emails sent in text-only. Usually sent by people with older email systems, but that is not at all rare.

What is rare is email containing code fragments.

---

<div class="post-metadata">

### Author: ![prdsr](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/prdsr/32/113300_2.png) [@prdsr](https://meta.discourse.org/u/prdsr)
#### Post date: [October 2, 2018, 6:15am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/6 "2018-10-02T06:15:26Z")

</div>

+1  
I fully second this!

---

<div class="post-metadata">

### Author: ![frjosephfessiosj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frjosephfessiosj/32/134433_2.png) [@frjosephfessiosj](https://meta.discourse.org/u/frjosephfessiosj)
#### Post date: [March 29, 2019, 4:46am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/12 "2019-03-29T04:46:29Z")

</div>

Ok, I’m old. I’m also a publisher of books (on paper and electronic). Books indent new paragraphs. In letters or emails that use this convention, a tab is used. I’ve looked through the posts on this topic and haven’t found if there is a way to allow tabs as a default. (Or at least allow 4 or 5 spaces to function as an indent.)  
Is this possible without complicated programmin or plugins?

---

<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: [March 29, 2019, 4:49am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/13 "2019-03-29T04:49:22Z")

</div>

Yeah we have meant to work on this issue for quite a while now, thanks for the reminder, there is no setting now but we plan to sort this out.

---

<div class="post-metadata">

### Author: ![frjosephfessiosj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/frjosephfessiosj/32/134433_2.png) [@frjosephfessiosj](https://meta.discourse.org/u/frjosephfessiosj)
#### Post date: [March 29, 2019, 5:28am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/15 "2019-03-29T05:28:20Z")

</div>

Thanks for the prompt and encouraging reply. I’ve been very impressed by Discourse, and by the helpfulness of the community.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [March 29, 2019, 10:17am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/16 "2019-03-29T10:17:46Z")

</div>

This will help a **GREAT** deal in getting much less messy emails!

---

<div class="post-metadata">

### Author: ![dan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dan/32/101549_2.png) [@dan](https://meta.discourse.org/u/dan)
#### Post date: [April 12, 2019, 10:39pm UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/17 "2019-04-12T22:39:57Z")

</div>

I just [submitted a pull request](https://github.com/discourse/discourse/pull/7375) to introduce a new site setting `strip incoming email lines `. I did not want to completely disable code blocks when this setting is enabled, so code blocks will still be accepted between [code]…[/code] and ```…```, but all the other lines will be stripped (leading and trailing whitespaces will be removed).

For example, the following email:

```plaintext
MIME-Version: 1.0
Date: Tue, 01 Jan 2019 00:00:00 +0300
Subject: An email with whitespaces
From: Foo <foo@discourse.org>
To: bar@discourse.org
Content-Type: text/plain; charset="UTF-8"

Hello

    This is a line that will be stripped
    This is another line that will be stripped

This is a line that will not be touched.
This is another line that will not be touched.

[code]
  1.upto(10).each do |i|
    puts i
  end
[/code]

    This is going to be stripped too.

Bye!

```

will produce the following reply:

* * *

Hello

This is a line that will be stripped  
This is another line that will be stripped

This is a line that will not be touched.  
This is another line that will not be touched.

```plaintext
  1.upto(10).each do |i|
    puts i
  end
```

This is going to be stripped too.

Bye!

* * *

disabling this setting will create the following reply:

* * *

Hello

```
This is a line that will be stripped
This is another line that will be stripped

```

This is a line that will not be touched.  
This is another line that will not be touched.

```plaintext
  1.upto(10).each do |i|
    puts i
  end
```

```
This is going to be stripped too.

```

Bye!

* * *

---

<div class="post-metadata">

### Author: ![omarfilip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/omarfilip/32/208019_2.png) [@omarfilip](https://meta.discourse.org/u/omarfilip)
#### Post date: [April 12, 2019, 10:45pm UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/19 "2019-04-12T22:45:51Z")

</div>

Excellent! Thanks, Dan. This will clean up a large number of our incoming emails. 👌

---

<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: [April 12, 2019, 11:26pm UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/20 "2019-04-12T23:26:46Z")

</div>

Cool so the upshot of this setting is that traditional space indented commonmark code blocks become impossible, right? No other side effects? That seems like a reasonable tradeoff for sites that have the “random space indenting problem” 😉

---

<div class="post-metadata">

### Author: ![dan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dan/32/101549_2.png) [@dan](https://meta.discourse.org/u/dan)
#### Post date: [April 13, 2019, 9:41am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/21 "2019-04-13T09:41:24Z")

</div>

Unfortunately, no. Stripping every line also results in losing levels for nested lists.

```plaintext
* parent
  * child 1
  * child 2
```

becomes

```plaintext
* parent
* child 1
* child 2
```

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [April 14, 2019, 9:49am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/22 "2019-04-14T09:49:55Z")

</div>

A better way is probably to trap the code block recognition from the MarkDown engine and change the block type to normal text.

---

<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: [April 14, 2019, 11:26am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/23 "2019-04-14T11:26:12Z")

</div>

This is kind of an edge case behind a flag that has to be opted in. It’s not worth a ton of engineering, a “good enough” solution is fine.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [April 14, 2019, 12:34pm UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/24 "2019-04-14T12:34:40Z")

</div>

Agree. Who uses multi-layer bullets anyway? Not many I predict.

---

<div class="post-metadata">

### Author: ![dan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dan/32/101549_2.png) [@dan](https://meta.discourse.org/u/dan)
#### Post date: [April 14, 2019, 12:54pm UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/25 "2019-04-14T12:54:32Z")

</div>

> [@schungx](#):
>
> A better way is probably to trap the code block recognition from the MarkDown engine and change the block type to normal text.

Of course, that would be ideal, but it is a lot more effort than you would think.

Our “post cooking” (converting raw text to HTML) pipeline is quite complex and in the end it gets to MarkdownIt, which does not offer something such as a reverse mapping.

---

<div class="post-metadata">

### Author: ![schungx](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/schungx/32/70989_2.png) [@schungx](https://meta.discourse.org/u/schungx)
#### Post date: [April 16, 2019, 3:24am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/26 "2019-04-16T03:24:26Z")

</div>

Or… Only strip leading white space if the first letter of the line is not an obvious bullet mark like `*` or `-`.

That still won’t solve the problem for multi-layer numbered lists but those should be very rare…

---

<div class="post-metadata">

### Author: ![dan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dan/32/101549_2.png) [@dan](https://meta.discourse.org/u/dan)
#### Post date: [April 16, 2019, 8:49am UTC](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707/27 "2019-04-16T08:49:32Z")

</div>

That is an excellent idea!

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

[Next page](https://meta.discourse.org/t/disable-indent-code-block-for-emails/93707.md?page=2)
