# forward slashes in \<pre\> tag in md

**URL:** https://talk.observablehq.com/t/forward-slashes-in-pre-tag-in-md/2624
**Category:** Feedback
**Created:** [December 6, 2019, 8:28pm UTC](https://talk.observablehq.com/t/forward-slashes-in-pre-tag-in-md/2624 "2019-12-06T20:28:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![andreasplesch](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/andreasplesch/32/676_2.png) [@andreasplesch](https://talk.observablehq.com/u/andreasplesch)
#### Post date: [December 6, 2019, 8:28pm UTC](https://talk.observablehq.com/t/forward-slashes-in-pre-tag-in-md/2624/1 "2019-12-06T20:28:17Z")

</div>

While working on a [Advent of Code problem with ASCII graphics](https://observablehq.com/@andreasplesch/day-6-advent-of-code-2019?collection=@andreasplesch/aoc2019) I came across a markdown parsing issue with forward slashes:

> **[slashes in pre](https://observablehq.com/@andreasplesch/slashes-in-pre)**
>
> This does not work (leading tags and empty line): COM - B - C - D - E - F
> \\\\
> I
> This works (no leading empty lines): = G - H J - K - L
> = / /
> COM - B - C - D - E - F
> \\\\
> ...

Leading empty lines and white space in a \<pre\> tag seem to confuse the md renderer while the html processor does not have a problem.

Also I did not expect that backslashes have to be escaped with another backslash in pre tags both in md and html tagged templates.

Perhaps this is a general markdown limitation.

---

<div class="post-metadata">

### Author: ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)
#### Post date: [December 6, 2019, 9:21pm UTC](https://talk.observablehq.com/t/forward-slashes-in-pre-tag-in-md/2624/2 "2019-12-06T21:21:07Z")

</div>

I recommend using fenced code blocks for preformatted text:

```auto
~~~
        G - H J - K - L
       / /
COM - B - C - D - E - F
               \\
                I
~~~

```

---

<div class="post-metadata">

### Author: ![andreasplesch](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/andreasplesch/32/676_2.png) [@andreasplesch](https://talk.observablehq.com/u/andreasplesch)
#### Post date: [December 6, 2019, 9:29pm UTC](https://talk.observablehq.com/t/forward-slashes-in-pre-tag-in-md/2624/3 "2019-12-06T21:29:16Z")

</div>

Thanks for the workaround but I tend to forget the more exotic md decorators.

So \<pre\> tags are known to not always behave ?

And backslashes still need to be escaped in fenced code blocks ?

---

<div class="post-metadata">

### Author: ![andreasplesch](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/andreasplesch/32/676_2.png) [@andreasplesch](https://talk.observablehq.com/u/andreasplesch)
#### Post date: [December 6, 2019, 9:49pm UTC](https://talk.observablehq.com/t/forward-slashes-in-pre-tag-in-md/2624/4 "2019-12-06T21:49:53Z")

</div>

This appears to be a Marked issue so nothing observable related. Perhaps it is actually a more general md issue since this also does not work on [commonmark](https://spec.commonmark.org/dingus/?text=This%20does%20not%20work%20(leading%20tags%20and%20empty%20line)%3A%0A%3Cdiv%3E%3C%2Fdiv%3E%3Cpre%3E%0A%0A%20%20%20%20%20%20%20%20G%20-%20H%20%20%20%20%20%20%20J%20-%20K%20-%20L%0A%20%20%20%20%20%20%20%2F%20%20%20%20%20%20%20%20%20%20%20%2F%0ACOM%20-%20B%20-%20C%20-%20D%20-%20E%20-%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20I%0A%3C%2Fpre%3E%0A%0AThis%20works%20(no%20leading%20empty%20lines)%3A%0A%3Cdiv%3E%3C%2Fdiv%3E%3Cpre%3E%0A%20%20%20%20%20%20%20%20G%20-%20H%20%20%20%20%20%20%20J%20-%20K%20-%20L%0A%20%20%20%20%20%20%20%2F%20%20%20%20%20%20%20%20%20%20%20%2F%0ACOM%20-%20B%20-%20C%20-%20D%20-%20E%20-%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20I%0A%0A%3C%2Fpre%3E%0AThis%20also%20works%20(leading%20empty%20line%20but%20no%20initial%20white%20space)%3A%0A%3Cdiv%3E%3C%2Fdiv%3E%3Cpre%3E%0A%0A%3D%20%20%20%20%20%20%20G%20-%20H%20%20%20%20%20%20%20J%20-%20K%20-%20L%0A%3D%20%20%20%20%20%20%2F%20%20%20%20%20%20%20%20%20%20%20%2F%0ACOM%20-%20B%20-%20C%20-%20D%20-%20E%20-%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20I%0A%0A%3C%2Fpre%3E%0A%0ABackslashes%20%3F%0A%20%20%20-%20sublist%0A%0A)  
I could reproduce on [marked.js.org](https://marked.js.org/demo/?text=This%20does%20not%20work%20(leading%20tags%20and%20empty%20line)%3A%0A%3Cdiv%3E%3C%2Fdiv%3E%3Cpre%3E%0A%0A%20%20%20%20%20%20%20%20G%20-%20H%20%20%20%20%20%20%20J%20-%20K%20-%20L%0A%20%20%20%20%20%20%20%2F%20%20%20%20%20%20%20%20%20%20%20%2F%0ACOM%20-%20B%20-%20C%20-%20D%20-%20E%20-%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20I%0A%3C%2Fpre%3E%0A%0AThis%20works%20(no%20leading%20empty%20lines)%3A%0A%3Cdiv%3E%3C%2Fdiv%3E%3Cpre%3E%0A%20%20%20%20%20%20%20%20G%20-%20H%20%20%20%20%20%20%20J%20-%20K%20-%20L%0A%20%20%20%20%20%20%20%2F%20%20%20%20%20%20%20%20%20%20%20%2F%0ACOM%20-%20B%20-%20C%20-%20D%20-%20E%20-%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20I%0A%0A%3C%2Fpre%3E%0AThis%20also%20works%20(leading%20empty%20line%20but%20no%20initial%20white%20space)%3A%0A%3Cdiv%3E%3C%2Fdiv%3E%3Cpre%3E%0A%0A%3D%20%20%20%20%20%20%20G%20-%20H%20%20%20%20%20%20%20J%20-%20K%20-%20L%0A%3D%20%20%20%20%20%20%2F%20%20%20%20%20%20%20%20%20%20%20%2F%0ACOM%20-%20B%20-%20C%20-%20D%20-%20E%20-%20F%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%5C%5C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20I%0A%0A%3C%2Fpre%3E%0A%0ABackslashes%20%3F&options=%7B%0A%20%22baseUrl%22%3A%20null%2C%0A%20%22breaks%22%3A%20false%2C%0A%20%22gfm%22%3A%20true%2C%0A%20%22headerIds%22%3A%20true%2C%0A%20%22headerPrefix%22%3A%20%22%22%2C%0A%20%22highlight%22%3A%20null%2C%0A%20%22langPrefix%22%3A%20%22language-%22%2C%0A%20%22mangle%22%3A%20true%2C%0A%20%22pedantic%22%3A%20false%2C%0A%20%22sanitize%22%3A%20false%2C%0A%20%22sanitizer%22%3A%20null%2C%0A%20%22silent%22%3A%20false%2C%0A%20%22smartLists%22%3A%20false%2C%0A%20%22smartypants%22%3A%20false%2C%0A%20%22xhtml%22%3A%20false%0A%7D&version=master).

See [https://github.com/markedjs/marked/issues/1578](https://github.com/markedjs/marked/issues/1578)

---

<div class="post-metadata">

### Author: ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)
#### Post date: [December 6, 2019, 10:11pm UTC](https://talk.observablehq.com/t/forward-slashes-in-pre-tag-in-md/2624/5 "2019-12-06T22:11:24Z")

</div>

Yes, backslashes need to be escaped.

The behavior of Marked in regards to embedding HTML within Markdown is a bit… unpredictable. It’s a bit more predictable if you stick to Markdown or use `${…}` to embed an _html_ template literal within Markdown.
