M README.md => README.md +1 -1
@@ 29,7 29,7 @@` 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 `<https://example.com>`, or `<https://example.com|example page>`.
-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.
M gloss.py => gloss.py +13 -6
@@ 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 += '</p>'
content +='\n</div>'
-
+
if file.see_also is not None and len(file.see_also) != 0:
- content += "\n<hr>\n<h3>See Also:</h3>\n<ul>"
+ see_also = "<h3>See also:</h3>\n<ul>"
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<li><a href=\"{html.escape(href)}.html\">{html.escape(name)}</a></li>"
- content += "\n</ul>"
+ see_also += f"\n\t<li><a href=\"{html.escape(href)}.html\">{html.escape(name)}</a></li>"
+ see_also += "\n</ul>"
+ else:
+ see_also = ""
- return content
+ return content, see_also
### ENTRYPOINT ###
@@ 284,6 287,8 @@ if __name__ == '__main__':
<main>
{body}
</main>
+<hr>
+{see_also}
<footer>File last modified {modtime:%a, %Y-%d-%M %H:%M:%S %Z}</footer>
</body>
</html>
@@ 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))
M markup.c => markup.c +21 -0
@@ 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, "<a href=\"");
push_iesc(&tail, hend - href, href);
+ trim_segment(tail);
if(name == NULL){
push_html(&tail, 5, "\"<");
push_iesc(&tail, hend - href, href);
+ trim_segment(tail);
push_html(&tail, 8, "></a>");
}else{
push_html(&tail, 2, "\">");
push_iesc(&tail, i - name, name);
+ trim_segment(tail);
push_html(&tail, 4, "</a>");
}
A roughspec => roughspec +27 -0
@@ 0,0 1,27 @@
+File Format:
+
+
+
+name1
+name2
+name3
+<blank line>
+; comment
+para1
+para1
+<blank line>
+para2
+para2
+<blank line>
+> quote1
+> quote1
+> quote1
+~<author>[ @@ <date>][ // <url>]
+<blank line>
+para3
+para3
+<blank line>
+[***
+seealso1
+seealso2
+seealso3]