evilstreak / markdown-js

A Markdown parser for javascript
7.69k stars 863 forks source link

Shouldn't <code> be wrapped with <pre> #241

Open jfraboni opened 9 years ago

jfraboni commented 9 years ago

If we want to keep whitespace, for indentation, shouldn't the parser output back-ticked code blocks to something like this?

<pre><code> console.log("I am code"); </code></pre>

Currently, instead of <pre>, it outputs <p>.

ashb commented 9 years ago

What input did you give? If you use vanila markdown it should do - https://github.com/evilstreak/markdown-js/blob/master/src/render_tree.js#L185 and https://github.com/evilstreak/markdown-js/blob/master/test/features/code/block.text for instance)

zhangfuwen commented 9 years ago

Got the same problem. I think @jfraboni give input like show in this page:https://support.codebasehq.com/articles/tips-tricks/syntax-highlighting-in-markdown

Fours spaces( also indicates code block) will generate

, which is expected.

coltonbrwn commented 9 years ago

https://github.com/chjj/marked does a good job of this

elliotpotts commented 8 years ago

I get this issue also

rccoder commented 8 years ago

@coltonTB Thanks. I used marked soloved the problem

KernelDeimos commented 7 years ago

I think the use of the preformatted tag could hinder the ability to style code blocks. For instance, say you want to implement some sort of auto-indent functionality (just as an example; I wouldn't) - it may be less elegant to do so if it's already in a <pre> tag.

Currently you could format it with an external stylesheet - i.e. a page with parsed markdown might have a style like this:

.my_markdown code {
  white-space: pre;
  font-family: monospace;
}

Edit: I apologize for any notifications that may have happened - just realized this repo hasn't been updated in 3 year...