From 88cdd4d90224a639f3bac0e0b4d7dc1a6fb1fa38 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Fri, 15 Aug 2025 00:51:30 -0400 Subject: [PATCH] inline links, minor fixes --- gloss.py | 26 ++++++++++++++++++++++---- testout/a.html | 7 ++++--- testsrc/a.gls | 4 +++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/gloss.py b/gloss.py index 7708f1b7dd3658792ec68a91dab39a8ad0f5fb1b..c643bed4cde7c46445286d7b57e1ca31f9611dd5 100755 --- a/gloss.py +++ b/gloss.py @@ -73,7 +73,7 @@ def first_pass(slug, fp): blocks = [] for line in lines: if len(line) == 0 and block_type is not None: # block end - blocks.append(Block(block_type, [html.escape(block_text)], block_meta)) + blocks.append(Block(block_type, block_text, block_meta)) block_type = None block_text = None block_meta = '' @@ -110,10 +110,18 @@ def first_pass(slug, fp): return GlsFile(slug, [*names], blocks, see_also) quote_pat = re.compile("((?:(?!@@)(?!//).)+)(?:@@((?:(?!//).)+))?(?://(.+))?") +link_pat = re.compile("(?|]+)(?:\\|([^>]*))?>(?)") ### GENERATION ### - + +def link_repl(mat): + url, name = map(lambda x: x if x is None else html.escape(x.strip()), mat.groups()) + if name is not None and len(name) != 0: + return f'{name}' + else: + return f'<{url}>' + @dataclass(init=False) class Indexes: by_slug: Dict[str, GlsFile] @@ -138,6 +146,16 @@ class Indexes: sorted(self.names_sorted, key=lambda x: len(x[0])) def gen_inner_html(file, idx): + for block in file.blocks: # populate external links, listify block.text + text = block.text + block.text = [] + while (m := link_pat.search(text)) is not None: + s,e = m.span() + block.text.append(text[:s].replace('\\<', '<').replace('\\>', '>')) + text = text[e:] + block.text.append((link_repl(m),)) + block.text.append(text) + blacklist = set() for name, pat in idx.names_sorted: # populate local links if name in file.names: # ...but not to the same file @@ -162,12 +180,12 @@ def gen_inner_html(file, idx): content = f"

{html.escape(file.names[0])}

" for block in file.blocks: # ok generate the html - text = ''.join(map(lambda x: x if type(x) == str else x[0], block.text)) + text = ''.join(map(lambda x: html.escape(x) if type(x) == str else x[0], block.text)) if block.ty == 'para': content += f"\n

{text}

" elif block.ty == 'quote': sauce, date, url = map( - lambda x: x if x is None else html.escape(x), + lambda x: x if x is None else html.escape(x.strip()), quote_pat.match(block.meta).groups() ) content += "\n
\n\t' diff --git a/testout/a.html b/testout/a.html index 688ecfccb13ff1b5e19a02d76dd6c21e8f30d62c..707fabe43d5e3882f3e6fd3597d84456bd961336 100644 --- a/testout/a.html +++ b/testout/a.html @@ -9,15 +9,16 @@

The Letter A

this is a paragraph block. these lines will be folded into one string and ultimately rendered roughly the same in the browser.

-
this is a quote block
-

aleteoryx

+
this is a quote block
+

aleteoryx, 2025

+

example page


See Also:

  • The Letter B
  • -
    File last modified Thu, 2025-14-40 18:40:06
    +
    File last modified Fri, 2025-15-51 00:51:02
    diff --git a/testsrc/a.gls b/testsrc/a.gls index d2e5722120fff5bb5a8dc1fad8c8431cc2b719a0..ddd597491609f225b2d97a4847758cc6330c1de4 100644 --- a/testsrc/a.gls +++ b/testsrc/a.gls @@ -7,7 +7,9 @@ string and ultimately rendered roughly the same in the browser. > this is a quote block -~aleteoryx +~aleteoryx @@ 2025 // https://aleteoryx.me + + *** b