Skip to content

Loading…

Fails to parse Github flavored markdown example (chrome extension) #9

Closed
seanmcgary opened this Issue · 2 comments

2 participants

@seanmcgary

I noticed in the description that you say it uses Github Flavored Markdown. But when I copied their test markdown document (found here) into Gmail using the Chrome extension, all I get is a jumbled mess:

GitHub Flavored Markdown ================================ View the source of this content. Let's get the whole "linebreak" thing out of the way. The next paragraph contains two phrases separated by a single newline character: Roses are red Violets are blue The next paragraph has the same phrases, but now they are separated by two spaces and a newline character: Roses are red Violets are blue Oh, and one thing I cannot stand is the mangling of words with multiple underscores in them like performcomplicatedtask or dothis_and_do_that_and_another_thing. A bit of the GitHub spice ------------------------- In addition to the changes in the previous section, certain references are auto-linked: SHA: be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2 User@SHA ref: mojombo@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2 User/Project@SHA: mojombo/god@be6a8cc1c1ecfe9489fb51e4869af15a13fc2cd2 #Num: #1 User/#Num: mojombo#1 User/Project#Num: mojombo/god#1 These are dangerous goodies though, and we need to make sure email addresses don't get mangled: My email addy is tom@github.com. Math is hard, let's go shopping ------------------------------- In first grade I learned that 5 > 3 and 2 < 7. Maybe some arrows. 1 -> 2 -> 3. 9 <- 8 <- 7. Triangles man! a^2 + b^2 = c^2 We all like making lists ------------------------ The above header should be an H2 tag. Now, for a list of fruits: Red Apples Purple Grapes Green Kiwifruits Let's get crazy: 1. This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit. 2. Suspendisse id sem consectetuer libero luctus adipiscing. What about some code in a list? That's insane, right? 1. In Ruby you can map like this: ['a', 'b'].map { |x| x.uppercase } 2. In Rails, you can do a shortcut: ['a', 'b'].map(&:uppercase) Some people seem to like definition lists

Lower cost
The new version of this product costs significantly less than the previous one!
Easier to use
We've changed the product so that it's much easier to use!
I am a robot ------------ Maybe you want to print robot to the console 1000 times. Why not? def robot_invasion puts("robot " 1000) end You see, that was formatted as code because it's been indented by four spaces. How about we throw some angle braces and ampersands in there?
© 2004 Foo Corporation
Set in stone ------------ Preformatted blocks are useful for ASCII art:
              ,-.      ,     ,-.   ,-.     / \   (   )-(   )     \ |  ,.>-(   )-<      \|,' (   )-(   )       Y -'   -'       |//   `-'       |       |       |    -hrr-    _|_  
Playing the blame game ---------------------- If you need to blame someone, the best way to do so is by quoting them: > I, at any rate, am convinced that He does not throw dice. Or perhaps someone a little less eloquent: > I wish you'd have given me this written question ahead of time so I > could plan for it... I'm sure something will pop into my head here in > the midst of this press conference, with all the pressure of trying to > come up with answer, but it hadn't yet... > > I don't want to sound like > I have made no mistakes. I'm confident I have. I just haven't - you > just put me under the spot here, and maybe I'm not as quick on my feet > as I should be in coming up with one. Table for two -------------
ID  Name    Rank
1   Tom Preston-Werner  Awesome
2   Albert Einstein Nearly as awesome
Crazy linking action -------------------- I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3]. [1]: http://google.com/ "Google"   [2]: http://search.yahoo.com/ "Yahoo Search" [3]: http://search.msn.com/ "MSN Search"

I would check to make sure that your Markdown --> HTML parser is in fact compliant with GFM, because it seems that it may only support certain aspects of the markdown syntax.

@adam-p
Owner

There are a few separate problems here. I'm going to close this bug and open some more specific ones. @seanmcgary, please let me know if that doesn't satisfy you.

Our HTML-to-plaintext can't cope with <pre>

  1. Go to the example page @seanmcgary linked to.
  2. Select-all. Copy.
  3. Paste into Gmail. (Rich editor, of course.)
  4. You'll see that it looks all monospace. It got pasted rich -- not plaintext.
  5. Inspect the mail body. It's all a big <pre> or two.

Then if you do a "Markdown Toggle", you'll see that it's almost total garbage. As @seanmcgary says.

But if you paste plaintext (ctrl+shift+v, or a bunch of other ways), or strip the formatting (using the button in Gmail that looks like "Tx"), and then do a Markdown Toggle... looks great! (Well, pretty good, at least. Not perfect. That's the next thing...)

So, jsHtmlToText is probably not coping with white-space: pre;. Probably the newlines are lost.

I'll spin off a separate bug for this. The workaround is pretty easy, but it's still a bug that should be captured.

Our GFM compliance is imperfect

Take a look at the issues for marked. To wit:

I'm going to close this bug and open separate ones for each of those GFM deviations. I'll also make a comment in the README.

Our styling is/was lacking

Some of our styling is/was bad enough that the rendering looks broken, even when it isn't. I've fixed the ones I've found, although they're not yet in the master branch, much less a release. (But soon!) Examples:

  • Block quote styling was nonexistent. Fixed in c0f670a

  • Definition list styling was lacking. Fixed in 0f2a8d8

  • Table styling also lacking. Fixed in 386851c

Bonus points

The GFM ASCII art test works better in Markdown Here than in Github. Booyah.

             ,-. 
    ,     ,-.   ,-. 
   / \   (   )-(   ) 
   \ |  ,.>-(   )-< 
    \|,' (   )-(   ) 
     Y ___`-'   `-' 
     |/__/   `-' 
     | 
     | 
     |    -hrr- 
  ___|_____________ 
@adam-p adam-p closed this
@adam-p
Owner

Forked out separate issues. You should be able to see the references to them above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.