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

Add checkbox support to markdown #3459

Closed
wants to merge 6 commits into from
Closed

Add checkbox support to markdown #3459

wants to merge 6 commits into from

Conversation

watzon
Copy link
Contributor

@watzon watzon commented Oct 23, 2016

Fixes #2217 and #3458. Figured I'd see if I could do it and it seems to work. Probably still need to add specs.

# Checks if the following sequence of characters is a checkbox.
# A valid checkbox is made up of 3 characters and looks like
# this `[ ]` or this `[x]` with the latter being a checked one.
def check_checkbox(str, pos, bytesize)
Copy link
Contributor

@RX14 RX14 Oct 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this method a bit too complex? Why not simply

def check_checkbox(str, pos, bytesize)
  return false unless pos + 3 < bytesize

  return false unless str[pos] == '['.ord
  return false unless str[pos + 1] == ' '.ord || str[pos + 1] == 'x'.ord
  return false unless str[pos + 2] == ']'.ord

  true
end

Is it required to be whitespace-insensitive? Is [ ] (that has more than 1 space but markdown renders it as one) really a checkbox?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I figured someone with more knowledge of the markdown parser would be able to give me some helpful feedback since before yesterday I didn't know anything about it.

@@ -383,11 +384,18 @@ class Markdown::Parser
when '['
unless in_link
link = check_link str, (pos + 1), bytesize
checkbox = check_checkbox str, (pos + 1), bytesize
puts link, checkbox
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug statement.

@RX14
Copy link
Contributor

RX14 commented Oct 23, 2016

Thanks for the PR! I personally think it's a good addition because it's quite useful, a common implementation uses it, and the character sequence is pretty unambiguous. Does this PR limit checkboxes to the beginning of list items though? I'm pretty sure github does that and it might be a good idea.

@ysbaddaden
Copy link
Contributor

This was previously closed as not being Markdown, but a GitHub extension. See #2217.

@asterite
Copy link
Member

I'm actually in favor of providing a complete markdown implementation in the standard library, together with extensions (that can be disabled). The current markdown parser is a bit ugly/hacky, I don't know if there's a nice/formal algorithm to parse markdown in its entirety. If someone wants to provide a complete implementation, go ahead :-)

@ysbaddaden
Copy link
Contributor

I would say that extensions must be disabled by default —they're unexpected.

@watzon
Copy link
Contributor Author

watzon commented Oct 23, 2016

@asterite I like that idea a lot. Maybe I'll look into this and see if I can come up with something

@ujifgc
Copy link
Contributor

ujifgc commented Oct 30, 2016

Here is a WIP implementation of CommonMark spec and markdown-it extensions. It's written on Crystal but it is a carbon-copy of markdown-it JavaScript-flavored algorithms. I don't think the code size and quality is suitable for Crystal standard lib but it's worth mentioning. There are two reference CommonMark implementations but they are not extensible.

I'm putting it here mostly for you to realize how big CommonMark spec is.

@asterite
Copy link
Member

I think we'll eventually use markd and remove the poor Markdown support we have now, so closing.

@asterite asterite closed this Sep 29, 2017
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 this pull request may close these issues.

5 participants