~sircmpwn/sr.ht-dev

core.sr.hr: Markdown checklists using inputs v1 PROPOSED

This is the first option.

It has the advantage of being very simple, but looks kinda crap on some
browsers since the inputs need to be disabled to make them immutable.

Ivan Habunek (1):
  Implement markdown checkbox lists with inputs

 srht/markdown.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

-- 
2.26.2
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~sircmpwn/sr.ht-dev/patches/10765/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH core.sr.hr 1/1] Implement markdown checkbox lists with inputs Export this patch

---
 srht/markdown.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/srht/markdown.py b/srht/markdown.py
index b48d2a4..5a69a1b 100644
--- a/srht/markdown.py
+++ b/srht/markdown.py
@@ -10,7 +10,7 @@ import bleach
import misaka as m
import re

SRHT_MARKDOWN_VERSION = 4
SRHT_MARKDOWN_VERSION = 5

class RelativeLinkPrefixRenderer(m.HtmlRenderer):
    def __init__(self, *args, link_prefix=None, **kwargs):
@@ -77,7 +77,20 @@ class HighlighterRenderer(m.HtmlRenderer):
            {content}
        </h{str(level)}>\n'''

class CustomRenderer(RelativeLinkPrefixRenderer, HighlighterRenderer):
class CheckboxListItemRenderer(m.HtmlRenderer):
    def listitem(self, content, is_ordered, is_block):
        content = content.strip()
        match = re.match(r"^\[([ xX])\]", content)
        if match:
            checked = "checked" if match.group(1).lower() == "x" else ""
            checkbox = f'<input type="checkbox" disabled {checked}>'
            rest = content[3:].strip()
            return f'<li>{checkbox} {rest}</li>\n'

        return f"<li>{content}</li>\n"

class CustomRenderer(RelativeLinkPrefixRenderer, HighlighterRenderer,
        CheckboxListItemRenderer):
    pass

urlregex = re.compile(r'(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019]))')
-- 
2.26.2