Showdown: Add complete class to the tasklist list element

Created on 24 May 2018  路  2Comments  路  Source: showdownjs/showdown

With the following markdown:

- [ ] test
- [x] testing complete

The following html is rendered:

<ul>
    <li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled="" style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"> test</li>
    <li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled="" style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked=""> testing complete</li>
</ul>

The li element that contains the complete item should have an additional class of something like task-list-item-complete as follows:

<ul>
    <li class="task-list-item" style="list-style-type: none;"><input type="checkbox" disabled="" style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"> test</li>
    <li class="task-list-item task-list-item-complete" style="list-style-type: none;"><input type="checkbox" disabled="" style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;" checked=""> testing complete</li>
</ul>

As it makes styling the completed list items impossible without writing an extension to override this (and I'm not sure I can figure out a way to add the class with one...

I'd appreciate a little help on this :) (I could open a PR for it too)

on this line

change

      // Support for github tasklists
      if (taskbtn && options.tasklists) {
        bulletStyle = ' class="task-list-item" style="list-style-type: none;"';
        item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () {
          var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"';
          if (checked) {
            otp += ' checked';
          }
          otp += '>';
          return otp;
        });
      }

to

      // Support for github tasklists
      if (taskbtn && options.tasklists) {
        bulletStyle = ' class="task-list-item' + checked ? ' task-list-item-complete' : '' + '" style="list-style-type: none;"';
        item = item.replace(/^[ \t]*\[(x|X| )?]/m, function () {
          var otp = '<input type="checkbox" disabled style="margin: 0px 0.35em 0.25em -1.6em; vertical-align: middle;"';
          if (checked) {
            otp += ' checked';
          }
          otp += '>';
          return otp;
        });
      }
enhancement request

All 2 comments

You can use the :checked pseudo-class.
MDN:
https://developer.mozilla.org/en-US/docs/Web/CSS/:checked

No need to add additional css class to make a distinction between checked and unchecked checkbox.

@bunyevacz you cannot style the task text with :checked, this will just select input and not its text.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oscarmorrison picture oscarmorrison  路  4Comments

subodhpareek18 picture subodhpareek18  路  5Comments

JerryYangJin picture JerryYangJin  路  7Comments

andistuder picture andistuder  路  5Comments

Ehesp picture Ehesp  路  3Comments