From dfbc0b2878b2933a41ea22834a2301f90767b932 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Sun, 31 Aug 2025 16:57:56 -0400 Subject: [PATCH] multiline links, see also edits --- README.md | 2 +- gloss.py | 19 +++++++++++++------ markup.c | 21 +++++++++++++++++++++ roughspec | 27 +++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 roughspec diff --git a/README.md b/README.md index 8b6b5207b751416e1d0898a2c6b1ebafafca6b6a..1caa45f7117a2b91715713a2e512bb8a6be65a09 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ if `@@` is omitted, the signature will have no time associated. if `//` is omitted, the signature will have no URL associated. within a block, one can write a link of the form ``, or ``. -one can also escape `<` and `>` with backslashes. +one can also escape `<` and `>` with backslashes. regions of text can be italicized by putting them `/in slashes/`. if a block begins with `***`, the "see also" section is entered. each subsequent non-empty line should be the slug (filename, minus .gls) of an article. diff --git a/gloss.py b/gloss.py index 21bc8a17a44f647bb11072cd7be931311859eea3..6990f2357a702f67e9b90af30683a91c15aa9da6 100755 --- a/gloss.py +++ b/gloss.py @@ -22,6 +22,7 @@ interpolated as in str.format, and the following keys are provided: {{title}} - The first name for an article. {{slug}} - The name of the output file, minus '.html'. {{body}} - The HTML content of an article. + {{see_also}} - The HTML content of the "See also" section. {{modtime}} - The datetime of the article's last edit. '''[1:] @@ -236,9 +237,9 @@ def gen_inner_html(fmt, file, idx): content += f', {date}' content += '

' content +='\n' - + if file.see_also is not None and len(file.see_also) != 0: - content += "\n
\n

See Also:

\n
    " + see_also = "

    See also:

    \n
      " for what in file.see_also: if what in idx.by_slug: page = idx.by_slug[what] @@ -253,10 +254,12 @@ def gen_inner_html(fmt, file, idx): href, name = what.split('|', 1) else: href = name = what - content += f"\n\t
    • {html.escape(name)}
    • " - content += "\n
    " + see_also += f"\n\t
  • {html.escape(name)}
  • " + see_also += "\n
" + else: + see_also = "" - return content + return content, see_also ### ENTRYPOINT ### @@ -284,6 +287,8 @@ if __name__ == '__main__':
{body}
+
+{see_also}
File last modified {modtime:%a, %Y-%d-%M %H:%M:%S %Z}
@@ -301,10 +306,12 @@ if __name__ == '__main__': indexes = Indexes(files) for file in files: with open(f'{outdir}/{file.slug}.html', 'wt') as fp: + content, see_also = gen_inner_html(fmt, file, indexes) ctx = { 'title': html.escape(file.title), 'slug': html.escape(file.slug), - 'body': gen_inner_html(fmt, file, indexes), + 'body': content, + 'see_also': see_also, 'modtime': datetime.fromtimestamp(stat(f'{srcdir}/{file.slug}.gls').st_mtime) } fp.write(template.format(**ctx)) diff --git a/markup.c b/markup.c index 663a5c7ed221e26817d1ac3c49396e4f9a0a0714..ed27a33cd83aa9c6cfe6c35735fd71bb10adb334 100644 --- a/markup.c +++ b/markup.c @@ -93,6 +93,24 @@ free_segments(struct segment *seg) shift_segment(&seg); } +// trim the contents of seg, leaving one character remaining if it is al blanks +static void +trim_segment(struct segment *seg) +{ + int moved_end = 0; + while(seg->length != 0 && isblank(seg->text[seg->length-1])){ + seg->length--; + moved_end = 1; + } + while(seg->length != 0 && isblank(*seg->text)){ + seg->text++; + seg->length--; + } + + if(seg->length == 0 && moved_end) // if a string is all blanks, we will only modify the length. + seg->length++; +} + static inline void push_segment(struct segment **seg, int type, size_t length, const char *text) { @@ -142,13 +160,16 @@ try_link(const char **ip, const char *end, struct segment **tailp) head = tail = new_segment(SEG_HTML, 9, ""); }else{ push_html(&tail, 2, "\">"); push_iesc(&tail, i - name, name); + trim_segment(tail); push_html(&tail, 4, ""); } diff --git a/roughspec b/roughspec new file mode 100644 index 0000000000000000000000000000000000000000..c0313ed97ddd8972564486b1dd4d27faf9d53219 --- /dev/null +++ b/roughspec @@ -0,0 +1,27 @@ +File Format: + + + +name1 +name2 +name3 + +; comment +para1 +para1 + +para2 +para2 + +> quote1 +> quote1 +> quote1 +~[ @@ ][ // ] + +para3 +para3 + +[*** +seealso1 +seealso2 +seealso3]