Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve new lines (\n) within a <code> block #645

Closed
reggi opened this issue Aug 14, 2015 · 5 comments · Fixed by #1011
Closed

Preserve new lines (\n) within a <code> block #645

reggi opened this issue Aug 14, 2015 · 5 comments · Fixed by #1011

Comments

@reggi
Copy link

reggi commented Aug 14, 2015

How do I preserve new lines (\n) within a <code> block?

var marked = require('marked')
var Promise = require('bluebird')
var markedAsync = Promise.promisify(marked)

var markdown = [
  '```js',
  'if (true) {',
  '  console.log(\'word spaces\')',
  '}',
  '',
  '',
  '',
  '```'
].join('\n')

console.log(markdown)
markedAsync(markdown)
.then(console.log)

And the output:

```js
if (true) {
  console.log('word spaces')
}



```
<pre><code class="lang-js">if (true) {
  console.log(&#39;word spaces&#39;)
}
</code></pre>

However if there are spaces then a character, the empty lines are available.

var markdown = [
  '```js',
  'if (true) {',
  '  console.log(\'word spaces\')',
  '}',
  '',
  '',
  '',
  '```'
].join('\n')

console.log(markdown)
markedAsync(markdown)
.then(console.log)

Here's the output

```js
if (true) {
  console.log('word spaces')
}


x
```
<pre><code class="lang-js">if (true) {
  console.log(&#39;word spaces&#39;)
}


x
</code></pre>
@chrisdrackett
Copy link

I'm not sure if this is the same problem, but I'm also not getting new lines when using a code block with gym on:

input:

input

output:

<div> <span>test</span> </div>

expected output:

<div>
    <span>test</span>
</div>

@ChiChou
Copy link

ChiChou commented Dec 8, 2016

https://github.com/chjj/marked/blob/38f1727ffee0820975677027b8968bc1954e6637/lib/marked.js#L764

This project simply render inline code and code block as the same. It's a serious bug.

@joshbruce
Copy link
Member

#983

@Feder1co5oave
Copy link
Contributor

This is still a bug.
http://spec.commonmark.org/0.28/#example-98

@Feder1co5oave
Copy link
Contributor

Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants