@curvenote/schema
Version:
Schema and markdown parser for @curvenote/editor
57 lines • 1.74 kB
JavaScript
import { createLatexStatement } from '../serialize/tex/utils';
import { NodeGroups, CaptionKind } from './types';
import { nodeNames } from '../types';
const figcaption = {
content: `${NodeGroups.inline}*`,
attrs: {
kind: { default: null },
},
draggable: false,
defining: true,
toDOM(node) {
const { kind } = node.attrs;
return [
'figcaption',
{
kind: kind !== null && kind !== void 0 ? kind : undefined,
},
0,
];
},
parseDOM: [
{
tag: 'figcaption',
getAttrs(dom) {
var _a;
return {
kind: (_a = dom.getAttribute('kind')) !== null && _a !== void 0 ? _a : null,
};
},
},
],
attrsFromMyst: (token, tokens) => {
const adjacentTypes = tokens.map((t) => t.type);
return { kind: adjacentTypes.includes(nodeNames.table) ? CaptionKind.table : CaptionKind.fig };
},
toMyst: (props) => ({
type: 'caption',
children: (props.children || []),
}),
};
export const toMarkdown = (state, node) => {
state.renderInline(node);
state.closeBlock(node);
};
export const toTex = createLatexStatement((state, node) => {
if (state.isInTable && node.attrs.kind !== CaptionKind.table) {
return null;
}
const { nextCaptionNumbered: numbered, nextCaptionId: id } = state;
return {
command: numbered === false ? 'caption*' : 'caption',
inline: true,
after: numbered && id ? `\\label{${id}}` : '',
};
}, (state, node) => state.renderInline(node));
export default figcaption;
//# sourceMappingURL=figcaption.js.map