Added task list ability to GFM parser.#442
Conversation
gettalong
left a comment
There was a problem hiding this comment.
Thanks for your pull request! Please see the line comments for needed changes.
And please also add tests into the test/testcases_gfm/ directory to verify that everything works as expected.
Thanks!
| # elements where necessary (as well as applying classes to the ul/ol and li elements). | ||
| def parse_list | ||
| super | ||
| @tree.children.each do |element| |
There was a problem hiding this comment.
Using @tree.children.each would mean that, e.g., parsing the third list involves checking the first two lists. It would be better to restrict the processing to the list at hand which saves time.
| def parse_list | ||
| super | ||
| @tree.children.each do |element| | ||
| if [:ul, :ol].include? element.type |
There was a problem hiding this comment.
Please use parentheses around method arguments.
| /\[ \]\s+/, '<input type="checkbox" class="task-list-item-checkbox" disabled="disabled" />') | ||
| unchecked = li.children[0].children[0].value.gsub!( | ||
| /\[x\]\s+/i, '<input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />') | ||
| is_tasklist = (checked != nil or unchecked != nil) |
There was a problem hiding this comment.
Please use || instead of or; and checked.nil? as this avoids a method call.
Since is_tasklist is also used outside this loop, you need to use is_tasklist ||= ... since otherwise only the state of the last list item determines the status (which is probably not wanted).
| /\[x\]\s+/i, '<input type="checkbox" class="task-list-item-checkbox" disabled="disabled" checked="checked" />') | ||
| is_tasklist = (checked != nil or unchecked != nil) | ||
| if is_tasklist | ||
| li.attr[:class] = 'task-list-item' |
There was a problem hiding this comment.
- Please use the if-modifier syntax syntax for this since it is a short line and easy to understand.
- Use
attr['class']since the keys are strings, not symbols.
All this also applies to line 176.
|
Hey. I've addressed all of the comments and added some tests. Thanks! |
|
Thanks - I'm currently rather busy but will have a look at soon as possible! |
|
Thanks for your contribution - I have squashed the commits and integrated your code. |
|
@adwylie @gettalong Thanks for this added feature! Curious what the decision was for making the checkbox disabled by default? |
|
@robbiejaeger kramdown generates static content, so if the input would be clickable the visible state would change but nothing else. |
|
Makes sense - thanks for the clarification! |
Followed most of the suggestions in #172. Never written Ruby before though so it may be a bit sloppy.
Currently renders as li disc followed by the checkbox, was assuming there'd be css to change
list-style-typetononeif the checkbox exists. If not I can change it.Thanks, Andrew.