{value}
); const [previewType, setPreviewType] = useState('DEMO'); useEffect(() => { @@ -195,7 +192,7 @@ export function MySTRenderer({ parse( text, { numbering }, - { renderers, removeHeading: !!TitleBlock, jats: { fullArticle: !!TitleBlock } }, + { removeHeading: !!TitleBlock, jats: { fullArticle: !!TitleBlock } }, ).then((result) => { if (!ref.current) return; setFrontmatter(result.frontmatter); @@ -206,13 +203,12 @@ export function MySTRenderer({ setTexWarnings(result.texWarnings); setJats(result.jats); setJatsWarnings(result.jatsWarnings); - setContent(result.content); setWarnings(result.warnings); }); return () => { ref.current = false; }; - }, [text, renderers]); + }, [text]); useEffect(() => { if (!area.current) return; @@ -315,7 +311,7 @@ export function MySTRenderer({ <>- {children} +
+
{node.value}
;
+ inlineMath({ node }) {
+ return {node.value}
;
},
- math(node) {
- return {node.value}
;
+ math({ node }) {
+ return {node.value}
;
},
- list(node, children) {
+ list({ node }) {
if (node.ordered) {
return (
- - {children} ++); }, - thematicBreak(node) { - return
; + thematicBreak() { + return
; }, - captionNumber(node, children) { - function backwardsCompatibleLabel(value: string, kind?: string) { - const capital = kind?.slice(0, 1).toUpperCase() ?? 'F'; - const body = kind?.slice(1) ?? 'igure'; - return `${capital}${body}: ${children}`; - } - const label = - typeof children === 'string' ? backwardsCompatibleLabel(children, node.kind) : children; + captionNumber({ node }) { const id = node.html_id || node.identifier || node.key; return (- {label} + ); }, - table(node, children) { + table({ node }) { // TODO: actually render the tbody on the server if it isn't included here. return ( -- {children} +
+ +
); }, - tableRow(node, children) { - return+ {children} ; + tableRow({ node }) { + return ( ++ + ); }, - tableCell(node, children) { + tableCell({ node }) { const ifGreaterThanOne = (num?: number) => (num === 1 ? undefined : num); const attrs = { - key: node.key, rowSpan: ifGreaterThanOne(node.rowspan), colSpan: ifGreaterThanOne(node.colspan), }; - if (node.header) return+ {children} ; - return{children} ; + if (node.header) + return ( ++ + ); + return ( ++ + + ); }, - subscript(node, children) { - return {children}; + subscript({ node }) { + return ( + ++ + + ); }, - superscript(node, children) { - return {children}; + superscript({ node }) { + return ( + + + + ); }, - abbreviation(node, children) { + abbreviation({ node }) { return ( - + - {children} + ); @@ -236,33 +270,36 @@ const BASIC_RENDERERS: BasicNodeRenderers = { comment() { return null; }, - definitionList(node, children) { + definitionList({ node }) { return ( -- {children} +
+
); }, - definitionTerm(node, children) { - let strongChildren: React.ReactNode = children; - if (Array.isArray(children)) { - const allowedStrongTypes = new Set(['emphasis']); - strongChildren = children.map((child, i) => { - if (typeof child === 'string') return {child}; - if (allowedStrongTypes.has(child?.type)) return {child}; - return child; - }); - } else if (typeof children === 'string') { - strongChildren = {children}; - } + definitionTerm({ node }) { + const allowedStrongTypes = new Set(['text', 'emphasis']); + const makeStrong = + node.children?.reduce((allowed, n) => allowed && allowedStrongTypes.has(n.type), true) ?? + false; return ( -- - {strongChildren} +
- + {makeStrong ? ( + +
); }, - definitionDescription(node, children) { - return+ + ) : ( + + )} - {children}
; + definitionDescription({ node }) { + return ( +- +
+ ); }, }; diff --git a/packages/myst-to-react/src/card.tsx b/packages/myst-to-react/src/card.tsx index 0098d2664..cd5d9dcd5 100644 --- a/packages/myst-to-react/src/card.tsx +++ b/packages/myst-to-react/src/card.tsx @@ -2,6 +2,8 @@ import React from 'react'; import type { NodeRenderer } from '@myst-theme/providers'; import classNames from 'classnames'; import { useLinkProvider, useBaseurl, withBaseurl } from '@myst-theme/providers'; +import { MyST } from './MyST'; +import type { GenericNode } from 'myst-common'; type CardSpec = { type: 'card'; @@ -18,43 +20,37 @@ type FooterSpec = { type: 'footer'; }; -export const Header: NodeRenderer+ = (node, children) => { +export const Header: NodeRenderer = ({ node }) => { return ( - - {children} + + ); }; -export const Footer: NodeRenderer= (node, children) => { +export const Footer: NodeRenderer = ({ node }) => { return ( -