@podlite/schema
Version:
AST tools for Podlite markup language
69 lines • 2.32 kB
JavaScript
import { nanoid } from 'nanoid';
export const mkNode = (attr) => {
return { ...attr };
};
export const filterNulls = content => {
if (Array.isArray(content)) {
return content.filter(i => i);
}
console.warn('[podlite-schema] filterNulls got not array as content');
};
export const mkBlock = (attrs, content) => {
const type = 'block';
const name = attrs.name;
const attributes = { id: nanoid(), margin: '', ...attrs };
var result = mkNode({ type, ...attributes, content: filterNulls(content) });
return result;
};
export const mkBlankline = () => {
return mkNode({ type: 'blankline' });
};
export const mkFomattingCode = (attrs, content) => {
return mkNode({ type: 'fcode', ...attrs, content });
};
export const mkFomattingCodeL = (attrs, content) => {
return mkNode({ ...attrs, type: 'fcode', name: 'L', content: filterNulls(content) });
};
export const mkFomattingCodeDelete = content => {
return mkNode({ type: 'fcode', name: 'Delete', content: filterNulls(content) });
};
export const mkMarkupCodeF = (formula) => {
return mkNode({ type: 'fcode', name: 'F', content: [{ type: 'text', value: formula }] });
};
export const mkVerbatim = text => {
return mkNode({ type: 'verbatim', value: text });
};
// Table of contents helpers
export const mkToc = (content, title, location) => {
return mkNode({ type: 'toc', title, content, location });
};
export const mkTocList = (content, level) => {
return mkNode({ type: 'toc-list', level, content });
};
export const mkTocItem = (content) => {
return mkNode({ type: 'toc-item', node: content, content: [content] });
};
export const mkCaption = (content) => {
return {
type: 'block',
name: 'caption',
content,
};
};
export const mkImage = (src, alt) => {
return {
type: 'image',
src,
alt,
};
};
export const mkRootBlock = ({ margin = '' }, content) => {
return mkBlock({ name: 'root', margin }, content);
};
export const mkItemBlock = ({ level, location, margin }, content) => {
return mkBlock({ name: 'item', level, margin, location }, content);
};
export const mkFormulaBlock = ({ value, location }) => {
return mkBlock({ name: 'formula', location }, [mkVerbatim(value)]);
};
//# sourceMappingURL=blocks-helpers.js.map