Replace @endflags with blank newline detection

This is kind of a hack but I won't lose too much sleep over it
This commit is contained in:
Oliver Blanthorn 2026-08-28 14:36:12 +02:00
parent 5e1929db02
commit a0073eaf01
No known key found for this signature in database
GPG key ID: 2BB8C36BB504BFF3
4 changed files with 36 additions and 19 deletions

View file

@ -39,7 +39,8 @@ function convertMetadata(project) {
const text = (tag.content || []) const text = (tag.content || [])
.map(part => part.text || "") .map(part => part.text || "")
.join("") .join("")
const m = /^(-\S+)[ \t]+([^\n]+)\n*([\s\S]*)$/.exec(text.trim()) const flagText = text.split(/\r?\n[ \t]*\r?\n/, 1)[0]
const m = /^(-\S+)[ \t]+([^\n]+)\n*([\s\S]*)$/.exec(flagText.trim())
if (!m) continue if (!m) continue
const [, flag, short, rest] = m const [, flag, short, rest] = m
const elaboration = rest.trim() const elaboration = rest.trim()

View file

@ -48,8 +48,7 @@ function rewriteWikiLinks(parts, owner, reflections) {
candidate => candidate =>
!candidate.kindOf( !candidate.kindOf(
ReflectionKind.Module | ReflectionKind.Namespace, ReflectionKind.Module | ReflectionKind.Namespace,
) && ) && !candidate.sources?.some(isGeneratedSource),
!candidate.sources?.some(isGeneratedSource),
) || ) ||
candidates.find( candidates.find(
candidate => candidate =>
@ -253,12 +252,31 @@ class TridactylRouter extends KindRouter {
} }
function parseFlagTag(tag) { function parseFlagTag(tag) {
const text = (tag.content || []).map(part => part.text || "").join("") const parts = tag.content || []
let text = ""
let trailing = []
for (let i = 0; i < parts.length; i++) {
const part = parts[i]
const match = part.kind === "text" && /\r?\n[ \t]*\r?\n/.exec(part.text)
if (!match) {
text += part.text || ""
continue
}
text += part.text.slice(0, match.index)
trailing = [
{
...part,
text: part.text.slice(match.index + match[0].length),
},
...parts.slice(i + 1),
]
break
}
const m = /^(-\S+)[ \t]+([^\n]+)\n*([\s\S]*)$/.exec(text.trim()) const m = /^(-\S+)[ \t]+([^\n]+)\n*([\s\S]*)$/.exec(text.trim())
if (!m) return undefined if (!m) return undefined
const [, flag, short, rest] = m const [, flag, short, rest] = m
const elaboration = rest.trim() const elaboration = rest.trim()
return [flag, short, elaboration] return [flag, short, elaboration, trailing]
} }
function renderFlagList(context, parsed) { function renderFlagList(context, parsed) {
@ -286,7 +304,7 @@ class TridactylTheme extends DefaultTheme {
const defaultCommentSummary = context.commentSummary const defaultCommentSummary = context.commentSummary
context.commentSummary = props => { context.commentSummary = props => {
const blockTags = props.comment?.blockTags || [] const blockTags = props.comment?.blockTags || []
if (!blockTags.some(tag => tag.tag === "@flag" || tag.tag === "@endflags")) if (!blockTags.some(tag => tag.tag === "@flag"))
return defaultCommentSummary(props) return defaultCommentSummary(props)
const summaryHeadingCount = page.pageHeadings.length const summaryHeadingCount = page.pageHeadings.length
@ -295,19 +313,20 @@ class TridactylTheme extends DefaultTheme {
let flagRun = [] let flagRun = []
const flushFlags = () => { const flushFlags = () => {
if (flagRun.length === 0) return if (flagRun.length === 0) return
const parsed = flagRun.map(parseFlagTag).filter(Boolean) nodes.push(renderFlagList(context, flagRun))
nodes.push(renderFlagList(context, parsed))
flagRun = [] flagRun = []
} }
for (const tag of blockTags) { for (const tag of blockTags) {
if (tag.tag === "@flag") { if (tag.tag === "@flag") {
tag.skipRendering = true tag.skipRendering = true
flagRun.push(tag) const parsed = parseFlagTag(tag)
} else if (tag.tag === "@endflags") { if (!parsed) continue
tag.skipRendering = true const [flag, short, elaboration, trailing] = parsed
flagRun.push([flag, short, elaboration])
if (trailing.length === 0) continue
flushFlags() flushFlags()
const headingCount = page.pageHeadings.length const headingCount = page.pageHeadings.length
nodes.push(context.displayParts(tag.content || [])) nodes.push(context.displayParts(trailing))
page.pageHeadings.length = headingCount page.pageHeadings.length = headingCount
} }
} }
@ -399,7 +418,10 @@ class TridactylTheme extends DefaultTheme {
h( h(
"ul", "ul",
null, null,
docLink("Commands", "modules/_src_excmds_.html"), docLink(
"Commands",
"modules/_src_excmds_.html",
),
docLink( docLink(
"Settings", "Settings",
"classes/_src_lib_config_.default_config.html", "classes/_src_lib_config_.default_config.html",

View file

@ -5565,7 +5565,6 @@ const KILL_STACK: Element[] = []
* - If you need to use a query selector, use `-pipe` instead. * - If you need to use a query selector, use `-pipe` instead.
* @flag -F [callback] - run a custom callback on the selected hint * @flag -F [callback] - run a custom callback on the selected hint
* - e.g. `hint -JF e => {tri.excmds.tabopen("-b",e.href); e.remove()}`. * - e.g. `hint -JF e => {tri.excmds.tabopen("-b",e.href); e.remove()}`.
* @endflags
* *
* #### Element selection flags * #### Element selection flags
* *
@ -5583,7 +5582,6 @@ const KILL_STACK: Element[] = []
* - Also useful on sites with plenty of useless javascript elements such as google.com * - Also useful on sites with plenty of useless javascript elements such as google.com
* @flag -V create hints for invisible elements * @flag -V create hints for invisible elements
* - By default, elements outside the viewport when calling :hint are not hinted; this includes them anyways. * - By default, elements outside the viewport when calling :hint are not hinted; this includes them anyways.
* @endflags
* *
* #### Hinting mode selection: * #### Hinting mode selection:
* *

View file

@ -6,10 +6,6 @@
{ {
"tagName": "@flag", "tagName": "@flag",
"syntaxKind": "block" "syntaxKind": "block"
},
{
"tagName": "@endflags",
"syntaxKind": "block"
} }
] ]
} }