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

Disable wrapping everything is a p #156

Closed
Petah opened this issue Dec 1, 2013 · 10 comments
Closed

Disable wrapping everything is a p #156

Petah opened this issue Dec 1, 2013 · 10 comments

Comments

@Petah
Copy link

Petah commented Dec 1, 2013

Is there anyway to disable wrapping everything in a p

@jiananshi
Copy link

do agree with this, it's annoying

@funkytaco
Copy link

Same here.... wrapping in a paragraph element makes this module unusable.

@evilstreak
Copy link
Owner

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.

@jiananshi
Copy link

@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.

@ashb
Copy link
Collaborator

ashb commented Aug 7, 2014

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.

@jiananshi
Copy link

@ashb
That would be so nice, looking forward to it.

@ashb
Copy link
Collaborator

ashb commented Aug 12, 2014

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!

@ashb ashb closed this as completed Aug 12, 2014
@beaugunderson
Copy link

Rendering that ends up with the text in tags, so for example:

['markdown', ['Hello World']]

ends up as <Hello World>.

@beaugunderson
Copy link

Ah, I fixed this by using lodash's flatten operator and specifying true to the shallow argument to flatten the array by one level.

@beaugunderson
Copy link

Noting that lodash's flatten operator is shallow by default; the true argument makes it deep--not what you want here. :)

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

No branches or pull requests

6 participants