~sircmpwn/sr.ht-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 2

[PATCH core.sr.hr 0/1] Markdown checklists using inputs

Details
Message ID
<20200523123712.346817-1-ivan@habunek.com>
DKIM signature
pass
Download raw message
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

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

Details
Message ID
<20200523123712.346817-2-ivan@habunek.com>
In-Reply-To
<20200523123712.346817-1-ivan@habunek.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +15 -2
---
 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
Details
Message ID
<Ea-uCY3N_t5pJpLafbW2StgwOxk09ThBGKaP_a4VzDqjKu7M70QhhfSbp5wgJ0eC4kbmz1tZ7zVjKYXBAgYijDB3u_JAZW3HF3P2ZH9jObo=@emersion.fr>
In-Reply-To
<20200523123712.346817-1-ivan@habunek.com> (view parent)
DKIM signature
pass
Download raw message
On Saturday, May 23, 2020 2:37 PM, Ivan Habunek <ivan@habunek.com> wrote:

> 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.

There's a "readonly" attribute that makes it look like regular
checkboxes while being immutable.
Details
Message ID
<20200524075727.GA372056@tomodachi>
In-Reply-To
<Ea-uCY3N_t5pJpLafbW2StgwOxk09ThBGKaP_a4VzDqjKu7M70QhhfSbp5wgJ0eC4kbmz1tZ7zVjKYXBAgYijDB3u_JAZW3HF3P2ZH9jObo=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
On Sun, May 24, 2020 at 07:25:01AM +0000, Simon Ser wrote:
> There's a "readonly" attribute that makes it look like regular
> checkboxes while being immutable.

The readonly attribute does not apply to checkboxes unfortunately.

MDN says:
"Note: Only text controls can be made read-only, since for other
controls (such as checkboxes and buttons) there is no useful distinction
between being read-only and being disabled, so the readonly attribute
does not apply."

I would argue that visuals are a useful distinction, but hey.

-- Ivan
Reply to thread Export thread (mbox)