Wiki page
[branch/markdown-tagrefs] by
stephan
2024-07-03 09:32:41.
D 2024-07-03T09:32:41.370
L branch/markdown-tagrefs
N text/x-markdown
P e45e9240c0aa3448552f68a4934e4553c4daaaf246d48518c397e63dbbf64015
U stephan
W 2766
The purpose of the markdown-refs branch is to experiment with adding hashtag and `@username` support into the markdown parser.
In short, it attempts to recognize hashtags and `@username` references and wraps those tokens in SPAN elements with well-defined class name so that they can be identified by downstream JavaScript code and context-specific features applied to them:
- `#Hashtag` ==> `<span data-hashtag="Hashtag">#Hashtag</span>`
- `#nnnnn` (numeric) ==> `<span data-numtag="nnnnn">#nnnnn</span>`
- <s>`@name` ==> `<span data-atref="name">@name</span>`</s> Removed because it is flaky and is awkward with email-style user names. The last version with this (partial) support was [](9d3ca32ef7ad570d5b).
They have no outwardly-visible effect[^bug-headers] unless JS code is used to fetch the elements and apply features to them. The most obvious use for hashtags would be to apply them as filters in the forum and add a way to tag forum posts. Clicking on a hashtag in the forum would filter on messages which have that tag. (Note that containing the hashtag and "having that tag" are separate things: opaque text vs. a fossil tag artifact.) One issue we'd have for that use case, though, is that fossil tags are case-sensitive and hashtags are notoriously inconsistent in their casing, so any interface for adding tags for this purpose would need to lowercase them for consistency.
The core hashtag parsing seems to work well, including support for non-ASCII hashtags, and a demo of its use is integrated into the `/chat` page:
1. Tapping a `#nnnnn` numeric hashtag will scroll to the given message if it's been loaded. It's common to reference other messages that way in chat, and this branch now makes it easier to refer back to such references.
2. Tapping a hashtag will filter only on messages containing that hashtag.
Potential uses for these tags include:
- A separate, presumably louder/more visible, notification in `/chat` when a message containing a tag of your own name arrives.
- Filtering `/chat` and `/forum` posts by a user. The latter requires more UI infrastructure for providing a way to tag posts and search engine features for searching by hashtags.
- In the forum, constructs like "in response to #29" would link to the most recent post #29 (possibly 29.x) if it's loaded in the current page.
Example input to feed to the `test-markdown-render` command:
>
~~~
___#tag___
hashtag: #1_2
numtag: #123.4
numtag: #1
numtag 2.3: #2.3.4
xyz
#_notValid_
hashtag: #tag_ok
#tag__not
#tagNOT#NotATag
hashtag w/ em: *#ValidTag*
hashtag: #äValidTÄg
~~~
[^bug-headers]: bug: `#N` references in headers are rendered with their SPAN element HTML-escaped. Why headers get HTML-escaped is unclear.
Z adc4aeed474f4908952265fb282cc236