-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { MyST } from './MyST.js'; | ||
|
||
type HasValue = { | ||
value: string; | ||
}; | ||
|
||
type HasTextChildren = { | ||
children: HasValue[]; | ||
}; | ||
|
||
type HasChildren = { | ||
children: any[]; | ||
}; | ||
|
||
const preParentRenderer = ({ node }: { node: HasTextChildren }) => { | ||
const [child] = node.children; | ||
return ( | ||
<span | ||
style={{ | ||
whiteSpace: 'pre', | ||
}} | ||
> | ||
{child.value} | ||
</span> | ||
); | ||
}; | ||
|
||
const renderChildren = ({ node }: { node: HasChildren }) => { | ||
return <MyST ast={node.children} />; | ||
}; | ||
|
||
const AUTODOC_RENDERERS = { | ||
descType: preParentRenderer, | ||
descType_parameter: preParentRenderer, | ||
descAddname: preParentRenderer, | ||
descParameterlist({ node }: { node: HasChildren }) { | ||
const merged: React.ReactNode[] = []; | ||
node.children.slice(0, -1).forEach((item) => { | ||
merged.push(<MyST ast={item} />); | ||
merged.push(<>, </>); | ||
}); | ||
if (node.children.length > 0) { | ||
merged.push(<MyST ast={node.children[node.children.length - 1]} />); | ||
} | ||
return [<>(</>, ...merged, <>) </>]; | ||
}, | ||
descName({ node }: { node: HasTextChildren }) { | ||
const [child] = node.children; | ||
return ( | ||
<span | ||
style={{ | ||
fontWeight: 'bold', | ||
whiteSpace: 'pre', | ||
}} | ||
> | ||
{child.value} | ||
</span> | ||
); // | ||
}, | ||
fieldList({ node }: { node: HasChildren }) { | ||
return ( | ||
<dl> | ||
<MyST ast={node.children} /> | ||
</dl> | ||
); | ||
}, | ||
fieldListItem({ node }: { node: HasChildren }) { | ||
return ( | ||
<p> | ||
<MyST ast={node.children} /> | ||
</p> | ||
); | ||
}, | ||
fieldName({ node }: { node: HasChildren }) { | ||
return ( | ||
<dt> | ||
<MyST ast={node.children} /> | ||
</dt> | ||
); | ||
}, | ||
fieldDescription({ node }: { node: HasChildren }) { | ||
return ( | ||
<dd> | ||
<MyST ast={node.children} /> | ||
</dd> | ||
); | ||
}, | ||
desc({ node }: { node: HasChildren }) { | ||
return ( | ||
<dl> | ||
<MyST ast={node.children} /> | ||
</dl> | ||
); | ||
}, | ||
descSignature({ node }: { node: HasChildren }) { | ||
return ( | ||
<dt | ||
style={{ | ||
fontWeight: 'lighter', | ||
fontFamily: "Menlo, Consolas, 'DejaVu Sans Mono', monospace", | ||
}} | ||
> | ||
<MyST ast={node.children} /> | ||
</dt> | ||
); | ||
}, | ||
descContent({ node }: { node: HasChildren }) { | ||
return ( | ||
<dd> | ||
<MyST ast={node.children} /> | ||
</dd> | ||
); | ||
}, | ||
descAnnotation: renderChildren, | ||
descParameter: renderChildren, | ||
descReturns({ node }: { node: HasChildren }) { | ||
return ( | ||
<> | ||
<span>→ </span> | ||
<MyST ast={node.children as any} /> | ||
</> | ||
); | ||
}, | ||
descSigPunctuation: preParentRenderer, | ||
descSigSpace: preParentRenderer, | ||
descSigName: renderChildren, | ||
descSigOperator: preParentRenderer, | ||
descSigKeyword: preParentRenderer, | ||
descSigKeywordType: preParentRenderer, | ||
descSigKeywordLiteralNumber: preParentRenderer, | ||
descSigKeywordLiteralString: preParentRenderer, | ||
descSigKeywordLiteralChar: preParentRenderer, | ||
}; | ||
export default AUTODOC_RENDERERS; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters