Closed Petah closed 10 years ago
do agree with this, it's annoying
Same here.... wrapping in a paragraph element makes this module unusable.
When you say wrapping everything in a <p>
, do you mean the way that this …
The quick brown fox jumps
over the lazy dog.
Pack my box with five
dozen liquor jugs.
… gets turned into this …
<p>The quick brown fox jumps
over the lazy dog.</p>
<p>Pack my box with five
dozen liquor jugs.</p>
If so, that's just how Markdown works I'm afraid.
@evilstreak
If so, I suggest adding an option to get rid of it in the plugin. Usually it's annoying when I get data from my database and pass it to toHTML
function, I have no idea to detect whether it contains markdown syntax. If it's not, then plain text with <p>
tag surround will be sent to the backend and continue to frontend, bad things happens.
Currently I'm getting rid of it at the backend, remove the p
tag after got it from database.
You can do this by not calling toHTML
directly andinstead processing the parsed tree before turning it into HTML - I'll knock up a quick wiki page showing how to do that this evening.
@ashb That would be so nice, looking forward to it.
Here's a version.
tree = md.markdown.parse("The quick brown fox jumps\n*over* the lazy dog.\n\nPack my box with five\ndozen liquor jugs.\n")
This gives us a tree that looks like this
[ 'markdown',
[ 'para',
'The quick brown fox jumps\n',
[ 'em', 'over' ],
' the lazy dog.' ],
[ 'para',
'Pack my box with five\ndozen liquor jugs.' ] ]
We can remove the top level paras and keep them separated like this:
tree.forEach( function(jsonml) { if (jsonml[0] == "para") { jsonml.splice(0,1) } } )
yeilding:
[ 'markdown',
[ 'The quick brown fox jumps\n',
[ 'em', 'over' ],
' the lazy dog.' ],
[ 'Pack my box with five\ndozen liquor jugs.' ] ]
This should give you enough to go on I hope. If you have more precise requirements let us know!
Rendering that ends up with the text in tags, so for example:
['markdown', ['Hello World']]
ends up as <Hello World>
.
Ah, I fixed this by using lodash's flatten
operator and specifying true
to the shallow
argument to flatten the array by one level.
Noting that lodash
's flatten
operator is shallow by default; the true
argument makes it deep--not what you want here. :)
Is there anyway to disable wrapping everything in a
p