mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-11 21:58:37 +00:00
Simplify JSDoc
This commit is contained in:
parent
6ba2b767b0
commit
2aff31fe06
@ -2,19 +2,15 @@ import jsdoc from '../../../doc.json'; // doc.json is built with `npm run jsdoc-
|
|||||||
const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {});
|
const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {});
|
||||||
import { MiniRepl } from './MiniRepl';
|
import { MiniRepl } from './MiniRepl';
|
||||||
|
|
||||||
const getTag = (title, item) => item.tags?.find((t) => t.title === title)?.text;
|
|
||||||
|
|
||||||
export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) {
|
export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) {
|
||||||
const item = docs[name];
|
const item = docs[name];
|
||||||
if (!item) {
|
if (!item) {
|
||||||
console.warn('Not found: ' + name);
|
console.warn('Not found: ' + name);
|
||||||
return <div />;
|
return <div />;
|
||||||
}
|
}
|
||||||
const synonyms = getTag('synonyms', item)?.split(', ') || [];
|
|
||||||
const CustomHeading = `h${h}`;
|
const CustomHeading = `h${h}`;
|
||||||
const description =
|
const description =
|
||||||
item.description?.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
|
item.description?.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
|
||||||
// console.log(_, 'a', a, 'b', b);
|
|
||||||
return `<a href="#${a.replaceAll('.', '').toLowerCase()}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
|
return `<a href="#${a.replaceAll('.', '').toLowerCase()}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
|
||||||
}) || '';
|
}) || '';
|
||||||
return (
|
return (
|
||||||
@ -22,9 +18,9 @@ export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight })
|
|||||||
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
|
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
|
||||||
{!hideDescription && (
|
{!hideDescription && (
|
||||||
<>
|
<>
|
||||||
{!!synonyms.length && (
|
{!!item.synonyms_text && (
|
||||||
<span>
|
<span>
|
||||||
Synonyms: <code>{synonyms.join(', ')}</code>
|
Synonyms: <code>{item.synonyms_text}</code>
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<div dangerouslySetInnerHTML={{ __html: description }} />
|
<div dangerouslySetInnerHTML={{ __html: description }} />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user