Fossil SCM
branch/markdown-tagrefs
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 wrap those tokens in SPAN elements with well-defined attributes 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>Removed because it is flaky and is awkward with email-style user names. The last version with this (partial) support was .@name==><span data-atref="name">@name</span>
This markup has no outwardly-visible effect unless CSS and/or JS code are apply style resp. features to the elements. The most obvious use for hashtags would be to apply them as filters in the forum and chat. For example, clicking on a hashtag in the forum or chat could 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:
- Tapping a
#nnnnnnumeric hashtag will scroll to the given message if it's been loaded, otherwise it will search the chat history for that message. It's common to reference other messages that way in chat, and this branch now makes it easier to refer back to such references. - Tapping a hashtag will filter only on messages containing that hashtag, noting that this is limited to locally-loaded messages and does not search the chat history (adding hashtag support to that would require a custom tokenizer to handle the
#characters).
Potential uses for these tags include:
- Filtering
/chatand/forumposts by hashtags or, in the case of/chat, message IDs. For the forum, this would require UI infrastructure for providing a way to tag posts. For/chatmessages which are already loaded into the current session, searching for matching entries can be done client-side. - In the forum, constructs like "in response to #29" could link to the most recent post #29 (possibly 29.x) if it's loaded in the current page.
The functional code for all such links can be injected via Javascript. The C level simply has to provide the HTML markup. Searching the DOM for such entries requires only a call to, e.g., document.querySelectorAll('span[data-hashtag]').
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 (note that only 2.3 gets wrapped)
xyz
#_notAHashtag_
hashtag: #tag_ok
#tag__not: not a hashtag because of multiple underscores
#tagNOT#NotATag
hashtag w/ em: *#ValidTag*
hashtag: #äValidTÄg
not tagged: `#InBackticks`
# header with #123 tag
# header with #hashtag
Z