- if target != null then
- if name == null then name = target.title
- link = target.href_from(context)
- else
- wiki.message("Warning: unknown wikilink `{link}` (in {context.src_path.as(not null)})", 0)
- v.add "class=\"broken\" "
+ v.add "<a "
+ if not link.has_prefix("http://") and not link.has_prefix("https://") then
+ # Extract commands from the link.
+ var command = null
+ var command_split = link.split_once_on(":")
+ if command_split.length > 1 then
+ command = command_split[0].trim
+ link = command_split[1].trim
+ end
+
+ if link.has("#") then
+ var parts = link.split_with("#")
+ link = parts.first
+ anchor = parts.subarray(1, parts.length - 1).join("#")
+ end
+ if link.has("/") then
+ target = wiki.lookup_entry_by_path(context, link.to_s)
+ else
+ target = wiki.lookup_entry_by_name(context, link.to_s)
+ if target == null then
+ target = wiki.lookup_entry_by_title(context, link.to_s)
+ end
+ end
+ if target != null then
+ if name == null then name = target.title
+ link = target.href_from(context)
+
+ if command == "trail" then
+ if target isa WikiSection then target = target.index
+ wiki.trails.add(context, target)
+ end
+ else
+ wiki.message("Warning: unknown wikilink `{link}` (in {context.src_path.as(not null)})", 0)
+ v.add "class=\"broken\" "
+ end