-
Notifications
You must be signed in to change notification settings - Fork 601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[api-documenter] How to define custom tags behavior? #4954
Comments
I have the same issue. I created a |
@octogonz - Can you provide some info on how to do this? This would be via a TSDoc plugin I think. |
The best I can do right now is an intermediate script between const apiPath = path.resolve(__dirname, '../temp/PACKAGE.api.json')
const apiJson = JSON.parse(fs.readFileSync(apiPath, 'utf-8'))
function jsonCrawler (obj, handler, context = { parent: null }) {
handler(obj, context)
if (typeof obj === 'object') {
if (obj === null) {
// nothing
} else if (Array.isArray(obj)) {
for (let index = 0; index < obj.length; ++index) {
jsonCrawler(obj[index], handler, { parent: { parent: context, _: obj }, key: index })
}
} else {
for (const key in obj) {
jsonCrawler(obj[key], handler, { parent: { parent: context, _: obj }, key })
}
}
}
}
jsonCrawler(apiJson, (value, { parent, key }) => {
if (key === 'docComment' && typeof value === 'string') {
value = value.replaceAll(/{@linkcode ([^|}]*) \| ([^}]*)}/g, '{@link $1 | <code>$2</code>}')
value = value.replaceAll(/{@linkcode ([^|}]*)}/g, '{@link $1 | <code>$1</code>}')
value = value.replaceAll(/@linkcode/g, '@link')
parent._[key] = value
}
})
fs.writeFileSync(apiPath, JSON.stringify(apiJson, null, 2)) |
The intend design is that API Extractor would accept these tags (because they are valid according to your config definition). And then an API Documenter plugin would implement any special processing. The plugin system is in early/experimental stages, but if you are interested to contribute to API Documenter, I can help to design a solution for your problem. I've been really busy lately, so the best way would be to arrange a Rush Stack community call. |
Summary
The
tsdoc.json
file allows adding custom tags. This allows them to be parsed, but how do I get them to be eventually emitted byapi-documenter
?To be more specific, I want to add the inline
@linkcode
tag and have it behave exactly the same as the@link
tag.Repro steps
tsdoc.json:
Source code:
Actual result:
The documentation is created without any errors, but the custom
@linkcode
tag is simply ignored.Details
I noticed there's a seemingly undocumented
api-documenter.json
config file, but it mentions nothing of custom tags. If I need to create a plugin to add here, that's fine, but a how-to would be nice.Standard questions
Please answer these questions to help us investigate your issue more quickly:
@microsoft/api-documenter
version?node -v
)?The text was updated successfully, but these errors were encountered: