~nhanb/mcross-devel

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] Support alt text for preformatted text

Details
Message ID
<20200614141653.12420-1-fkfd@macaw.me>
DKIM signature
missing
Download raw message
Patch: +15 -5
In Gemini's new, pending spec:

=> gemini://gemini.circumlunar.space/docs/specification-modified.gmi

...section 5.4.3:

> Any text following the leading "```" of a preformat toggle line which
> toggles preformatted mode on MAY be interpreted by the client as "alt
> text" pertaining to the preformatted text lines which follow the
> toggle line.

Since McRoss didn't adhere to the spec in the first place:

> Any line whose first three characters are "```"

"first three characters" means simply `if line == "```"` won't do. I
resolved this as a side effect.

This patch may be postponed until the modified spec takes effect.
---
 src/mcross/document.py  | 16 +++++++++++++---
 src/mcross/gui/model.py |  2 +-
 src/mcross/gui/view.py  |  2 +-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/mcross/document.py b/src/mcross/document.py
index 821f673..f285642 100644
--- a/src/mcross/document.py
+++ b/src/mcross/document.py
@@ -54,7 +54,15 @@ class LinkNode(GeminiNode):


class PreformattedNode(GeminiNode):
    pass
    __slots__ = ("alt",)
    alt: str

    def __init__(self, text, alt):
        self.text = text
        self.alt = alt  # optional alt-text for preformatted text

    def __repr__(self):
        return f"{self.__class__.__name__}: {self.alt.__repr__()}"


def parse(text):
@@ -63,15 +71,17 @@ def parse(text):
    """
    nodes = []
    preformatted = None
    preformatted_alt = ""

    for line in text.strip().split(NEWLINE):

        if line == "```":
        if line.startswith("```"):
            if preformatted is None:
                # start preformatted mode
                preformatted = ""
                preformatted_alt = line[3:]
            else:
                nodes.append(PreformattedNode(preformatted))
                nodes.append(PreformattedNode(preformatted, preformatted_alt))
                preformatted = None

        elif preformatted is not None:
diff --git a/src/mcross/gui/model.py b/src/mcross/gui/model.py
index 23667bd..98a5823 100644
--- a/src/mcross/gui/model.py
+++ b/src/mcross/gui/model.py
@@ -26,7 +26,7 @@ DEMO_TEXT = """\

## Codes

```
```a snippet from pyproject.toml
[tool.poetry]
name = "mcross"
version = "0.1.0"
diff --git a/src/mcross/gui/view.py b/src/mcross/gui/view.py
index 7e5ed33..0bc8f23 100644
--- a/src/mcross/gui/view.py
+++ b/src/mcross/gui/view.py
@@ -266,7 +266,7 @@ def render_node(node: GeminiNode, widget: Text):
        if node.name:
            widget.insert("end", f" {node.name}")
    elif nodetype is PreformattedNode:
        widget.insert("end", f"```\n{node.text}\n```", ("pre",))
        widget.insert("end", f"```{node.alt}\n{node.text}\n```", ("pre",))
    elif nodetype is ListItemNode:
        widget.insert("end", node.text, ("listitem",))
    elif nodetype is H1Node:
-- 
2.27.0
Details
Message ID
<1a036adb-faf5-9ca6-4010-e205bd36ea86@imnhan.com>
In-Reply-To
<20200614141653.12420-1-fkfd@macaw.me> (view parent)
DKIM signature
missing
Download raw message
 > In Gemini's new, pending spec

Aw crap, looks like it's promoted to official spec now. Do you know if 
they maintain some version controlled repo of the spec? Implementing an 
evolving spec with neither a changelog nor a diff is... not fun.

There's no excuse for missing the "Any line whose first three characters 
are ```" though. My bad.

Guess I'll comb through the new spec.
Details
Message ID
<F0C488A3-F3F4-41EA-A5B6-8FDE1FC6F265@macaw.me>
In-Reply-To
<1a036adb-faf5-9ca6-4010-e205bd36ea86@imnhan.com> (view parent)
DKIM signature
missing
Download raw message
On June 16, 2020 6:56:21 AM UTC, "Bùi Thành Nhân" <hi@imnhan.com> wrote:
> > In Gemini's new, pending spec
>
>Aw crap, looks like it's promoted to official spec now. Do you know if 
>they maintain some version controlled repo of the spec? 

I guess not, but I can quote solderpunk's summary on spec updates:

----- BEGIN QUOTATION -----
SUMMARY OF CHANGES:

* A gemini:// URI scheme is formally defined for the first time,
explicitly disallowing the use of the userinfo subcomponent of the
authority component.
* The client certificate system has been substantially simplified, with
transient certificates no long a formally defined concept with
prescribed behaviour.
* A lightweight notion of alt text for pre-formatted content has been
introduced as a tentative step toward fixing the worst search and
accessibility related problems with pre-formatted non-textual content.
No special structures or semantics for alt text are defined - if a
convention for doing this organically arises in the community it may
become a recommended best practice.
* A few minor corrections and tidyups.
----- END OF QUOTATION -----

>Implementing an evolving spec with neither a changelog nor a diff is... not fun.

Do you subscribe to the Gemini list? If so you can catch up with the important updates*.

>There's no excuse for missing the "Any line whose first three
>characters 
>are ```" though. My bad.
>
>Guess I'll comb through the new spec.

* Plus a dozen times more of other updates.

~fkfd
Details
Message ID
<50a0da15-3880-3197-c78f-bcbb57517835@imnhan.com>
In-Reply-To
<1a036adb-faf5-9ca6-4010-e205bd36ea86@imnhan.com> (view parent)
DKIM signature
missing
Download raw message
 > Do you subscribe to the Gemini list? If so you can catch up with the 
important updates*.

Right, I forgot about that, thanks. Better than nothing I guess.
Reply to thread Export thread (mbox)