"""Builds task/todo lists out of markdown lists with items starting with [ ] or [x]""" # Ported by Wolmar Nyberg Åkerström from https://github.com/revin/markdown-it-task-lists # ISC License # Copyright (c) 2016, Revin Guillen # # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. from __future__ import annotations import re from uuid import uuid4 from markdown_it import MarkdownIt from markdown_it.rules_core import StateCore from markdown_it.token import Token # Regex string to match a whitespace character, as specified in # https://github.github.com/gfm/#whitespace-character # (spec version 0.29-gfm (2019-04-06)) _GFM_WHITESPACE_RE = r"[ \t\n\v\f\r]" def tasklists_plugin( md: MarkdownIt, enabled: bool = False, label: bool = False, label_after: bool = False, ) -> None: """Plugin for building task/todo lists out of markdown lists with items starting with [ ] or [x] .. Nothing else For example:: - [ ] An item that needs doing - [x] An item that is complete The rendered HTML checkboxes are disabled; to change this, pass a truthy value into the enabled property of the plugin options. :param enabled: True enables the rendered checkboxes :param label: True wraps the rendered list items in a