~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
7 3

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

Details
Message ID
<20200523123937.347774-1-ivan@habunek.com>
DKIM signature
pass
Download raw message
This is the second option.

In my opinion this looks nicer, is immutable, but renders a bunch of
svg and allows adding some svg elements to the markdown whitelist.

Your pick.

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

 srht/markdown.py                   | 27 +++++++++++++++++++++++++--
 srht/static/icons/check-square.svg |  1 +
 srht/static/icons/square.svg       |  1 +
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 srht/static/icons/check-square.svg
 create mode 100644 srht/static/icons/square.svg

-- 
2.26.2

[PATCH core.sr.hr] Implement markdown checkbox lists with icons

Details
Message ID
<20200523123937.347774-2-ivan@habunek.com>
In-Reply-To
<20200523123937.347774-1-ivan@habunek.com> (view parent)
DKIM signature
pass
Download raw message
Patch: +27 -2
---
 srht/markdown.py                   | 27 +++++++++++++++++++++++++--
 srht/static/icons/check-square.svg |  1 +
 srht/static/icons/square.svg       |  1 +
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 srht/static/icons/check-square.svg
 create mode 100644 srht/static/icons/square.svg

diff --git a/srht/markdown.py b/srht/markdown.py
index b48d2a4..9e2fc6b 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,21 @@ 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):
        from srht.flask import icon
        content = content.strip()
        match = re.match(r"^\[([ xX])\]", content)
        if match:
            checked = match.group(1).lower() == "x"
            checkbox = icon("check-square") if checked else icon("square")
            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]))')
@@ -90,6 +104,12 @@ def _img_filter(tag, name, value):
        return p.scheme in ["http", "https", ""]
    return False

def _svg_filter(tag, name, value):
    return name in ["xmlns", "viewBox"]

def _path_filter(tag, name, value):
    return name == "d"

def _input_filter(tag, name, value):
    if name in ["checked", "disabled"]:
        return True
@@ -112,6 +132,8 @@ def markdown(text, tags=[], baselevel=1, link_prefix=None):
        "h4": ["id"],
        "h5": ["id"],
        "img": _img_filter,
        "svg": _svg_filter,
        "path": _path_filter,
        "input": _input_filter,
        "*": _wildcard_filter,
    }
@@ -123,6 +145,7 @@ def markdown(text, tags=[], baselevel=1, link_prefix=None):
            "table", "thead", "tbody", "tr", "th", "td",
            "input",
            "img",
            "svg", "path",
            "q",
        ] + tags,
        attributes=attrs,
diff --git a/srht/static/icons/check-square.svg b/srht/static/icons/check-square.svg
new file mode 100644
index 0000000..602b375
--- /dev/null
+++ b/srht/static/icons/check-square.svg
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M400 32H48C21.49 32 0 53.49 0 80v352c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V80c0-26.51-21.49-48-48-48zm0 400H48V80h352v352zm-35.864-241.724L191.547 361.48c-4.705 4.667-12.303 4.637-16.97-.068l-90.781-91.516c-4.667-4.705-4.637-12.303.069-16.971l22.719-22.536c4.705-4.667 12.303-4.637 16.97.069l59.792 60.277 141.352-140.216c4.705-4.667 12.303-4.637 16.97.068l22.536 22.718c4.667 4.706 4.637 12.304-.068 16.971z"/></svg>
\ No newline at end of file
diff --git a/srht/static/icons/square.svg b/srht/static/icons/square.svg
new file mode 100644
index 0000000..b9a4b96
--- /dev/null
+++ b/srht/static/icons/square.svg
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M400 32H48C21.5 32 0 53.5 0 80v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V80c0-26.5-21.5-48-48-48zm-6 400H54c-3.3 0-6-2.7-6-6V86c0-3.3 2.7-6 6-6h340c3.3 0 6 2.7 6 6v340c0 3.3-2.7 6-6 6z"/></svg>
\ No newline at end of file
-- 
2.26.2

Re: [PATCH core.sr.hr] Implement markdown checkbox lists with icons

Details
Message ID
<C2Y46NG5CD47.2JSNA74A8E794@homura>
In-Reply-To
<20200523123937.347774-2-ivan@habunek.com> (view parent)
DKIM signature
pass
Download raw message
The problem with either approach is that the checklists are read-only.
Making checklists has never been difficult; making them writable has
been.

Re: [PATCH core.sr.hr] Implement markdown checkbox lists with icons

Details
Message ID
<20200523124251.GA347907@tomodachi>
In-Reply-To
<C2Y46NG5CD47.2JSNA74A8E794@homura> (view parent)
DKIM signature
pass
Download raw message
On Sat, May 23, 2020 at 08:40:07AM -0400, Drew DeVault wrote:
> The problem with either approach is that the checklists are read-only.
> Making checklists has never been difficult; making them writable has
> been.

I didn't realize that was a wanted feature. It does complicate things,
e.g. editing comments is not permitted at all currently.

-- Ivan

Re: [PATCH core.sr.hr] Implement markdown checkbox lists with icons

Details
Message ID
<C2Y49CK8RFMP.1P8XM9IDWGZFW@homura>
In-Reply-To
<20200523124251.GA347907@tomodachi> (view parent)
DKIM signature
pass
Download raw message
On Sat May 23, 2020 at 10:42 AM PST, Ivan Habunek wrote:
> I didn't realize that was a wanted feature. It does complicate things,
> e.g. editing comments is not permitted at all currently.

Yeah, it would only work for ticket descriptions. But that's not the
hard part: the hard part is extending the markdown parser with
line/colno annotations, so that we know what characterse to edit to
apply the change.

Re: [PATCH core.sr.hr] Implement markdown checkbox lists with icons

Details
Message ID
<20200523131123.GA348071@tomodachi>
In-Reply-To
<C2Y49CK8RFMP.1P8XM9IDWGZFW@homura> (view parent)
DKIM signature
pass
Download raw message
On Sat, May 23, 2020 at 08:43:38AM -0400, Drew DeVault wrote:
> Yeah, it would only work for ticket descriptions. But that's not the
> hard part: the hard part is extending the markdown parser with
> line/colno annotations, so that we know what characterse to edit to
> apply the change.

Is that even possible in Misaka or would you have to change Hoedown?

Apparently FSX is working on replacing Hoedown:
https://github.com/FSX/misaka/issues/69

I can see why this issue is unresolved.

-- Ivan

Re: [PATCH core.sr.hr] Implement markdown checkbox lists with icons

Details
Message ID
<NENPfkwHp9bBQ-hX06cH_32d-3U1PTNhO_EL7L4E6n7tvqABfjgKo2QpiqKpNhgbvAjOcNvrwudaoXb3jebEdaEPG_SJ5pPVKl4isLBGqjQ=@emersion.fr>
In-Reply-To
<C2Y46NG5CD47.2JSNA74A8E794@homura> (view parent)
DKIM signature
pass
Download raw message
IMHO rendering as checkboxes is already a step forward. I don't mind
having to edit the Markdown source to update the checkbox status.

Re: [PATCH core.sr.hr] Implement markdown checkbox lists with icons

Details
Message ID
<20200525072725.GA402606@tomodachi>
In-Reply-To
<NENPfkwHp9bBQ-hX06cH_32d-3U1PTNhO_EL7L4E6n7tvqABfjgKo2QpiqKpNhgbvAjOcNvrwudaoXb3jebEdaEPG_SJ5pPVKl4isLBGqjQ=@emersion.fr> (view parent)
DKIM signature
pass
Download raw message
On Sun, May 24, 2020 at 07:26:18AM +0000, Simon Ser wrote:
> IMHO rendering as checkboxes is already a step forward. I don't mind
> having to edit the Markdown source to update the checkbox status.

I agree with Simon. Having read-only checkboxes is better than not
having them at all.

-- Ivan