automatically print synonyms in doc

This commit is contained in:
Felix Roos 2023-01-12 13:10:22 +01:00
parent 19982a2ffb
commit 78d14cdfea
2 changed files with 23 additions and 20 deletions

View File

@ -733,7 +733,7 @@ export class Pattern {
}
/**
* Appends the given pattern(s) to the current pattern. Synonyms: .sequence .fastcat
* Appends the given pattern(s) to the current pattern.
* @name seq
* @memberof Pattern
* @synonyms sequence, fastcat
@ -747,7 +747,7 @@ export class Pattern {
}
/**
* Appends the given pattern(s) to the next cycle. Synonym: .slowcat
* Appends the given pattern(s) to the next cycle.
* @name cat
* @memberof Pattern
* @synonyms slowcat
@ -1191,24 +1191,10 @@ export function slowcatPrime(...pats) {
return new Pattern(query).splitQueries();
}
/** Concatenation: as with {@link slowcat}, but squashes a cycle from each pattern into one cycle
*
* Synonyms: {@link Pattern.seq}, {@link Pattern.sequence}
*
* @param {...any} items - The items to concatenate
* @return {Pattern}
* @example
* fastcat(e5, b4, [d5, c5])
* // sequence(e5, b4, [d5, c5])
* // seq(e5, b4, [d5, c5])
*/
export function fastcat(...pats) {
return slowcat(...pats)._fast(pats.length);
}
/** The given items are con**cat**enated, where each one takes one cycle. Synonym: slowcat
/** The given items are con**cat**enated, where each one takes one cycle.
*
* @param {...any} items - The items to concatenate
* @synonyms slowcat
* @return {Pattern}
* @example
* cat(e5, b4, [d5, c5]).note() // "<e5 b4 [d5 c5]>".note()
@ -1235,12 +1221,17 @@ export function timeCat(...timepats) {
return stack(...pats);
}
export function fastcat(...pats) {
return slowcat(...pats)._fast(pats.length);
}
/** See {@link fastcat} */
export function sequence(...pats) {
return fastcat(...pats);
}
/** Like **cat**, but the items are crammed into one cycle. Synonyms: fastcat, sequence
/** Like **cat**, but the items are crammed into one cycle.
* @synonyms fastcat, sequence
* @example
* seq(e5, b4, [d5, c5]).note() // "e5 b4 [d5 c5]".note()
*

View File

@ -2,12 +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 }), {});
import { MiniRepl } from './MiniRepl';
const getTag = (title, item) => item.tags?.find((t) => t.title === title)?.text;
export function JsDoc({ name, h = 3, hideDescription }) {
const item = docs[name];
if (!item) {
console.warn('Not found: ' + name);
return <div />;
}
const synonyms = getTag('synonyms', item)?.split(', ') || [];
const CustomHeading = `h${h}`;
const description = item.description.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
// console.log(_, 'a', a, 'b', b);
@ -16,7 +19,16 @@ export function JsDoc({ name, h = 3, hideDescription }) {
return (
<>
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
{!hideDescription && <div dangerouslySetInnerHTML={{ __html: description }} />}
{!hideDescription && (
<>
{!!synonyms.length && (
<span>
Synonyms: <code>{synonyms.join(', ')}</code>
</span>
)}
<div dangerouslySetInnerHTML={{ __html: description }} />
</>
)}
<ul>
{item.params?.map((param, i) => (
<li key={i}>