edytor/export
Every name edytor/export exports, with its declaration and documentation (generated from the published types).
Every name edytor/export exports, generated from the package’s published type declarations, with the documentation its JSDoc carries. The guides explain how the pieces fit; this page is the exhaustive list. 33 names.
AtomForms
An atom’s export and import forms.
export type AtomForms = Pick<InlineBlockDefinition, 'html' | 'plain' | 'markdown' | 'parse'>;
BlockForms
A kind’s export and import forms: the fields of its record the export and HTML import read.
export type BlockForms = Pick<BlockDefinition, 'html' | 'plain' | 'markdown' | 'parse' | 'element' | 'contentElement' | 'void' | 'island' | 'lines' | 'rendersContent' | 'defaultChild' | 'itemKind'> & {
presets?: {
data?: Record<string, SerializableContent>;
}[];
};
bundledForms
Every bundled kind’s, mark’s and atom’s forms, with each plugin’s
default options: what toHTML, toMarkdown and fromHTML read when
given no kinds (each its own direction of them). A view’s own records
(kinds: edytor) carry its options (its callout icon, its embed
providers, its page links).
declare const bundledForms: {
blocks: Record<keyof ReturnType<typeof bundledRead>["blocks"], BlockForms>;
marks: {
bold: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
italic: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
underline: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
strike: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
code: {
tag: string;
};
link: {
tag: string;
attributes: (m: {
href?: unknown;
target?: string;
}) => {
href: string | undefined;
target: string | undefined;
};
parse: (el: HTMLElement) => {
target?: string | undefined;
href: string;
} | undefined;
edge: "side-dependent";
};
superscript: {
tag: string;
};
subscript: {
tag: string;
};
color: {
tag: string;
attributes: (v: unknown) => {
style: string | undefined;
};
parse: (el: HTMLElement) => string | undefined;
};
highlight: {
tag: string;
attributes: (v: unknown) => {
style: string | undefined;
};
parse: (el: HTMLElement) => string | undefined;
};
};
inlineBlocks: {
inlineEquation: {
html?: (data: import("../utils/json.js").JSONInlineBlock["data"]) => string;
markdown?: (data: import("../utils/json.js").JSONInlineBlock["data"]) => string;
plain?: (data: import("../utils/json.js").JSONInlineBlock["data"]) => string;
parse?: (element: HTMLElement) => Record<string, import("../utils/json.js").SerializableContent> | undefined;
};
mention: import("../clipboard/serializeClipboardFragment.js").AtomForms;
pageLink: import("../clipboard/serializeClipboardFragment.js").AtomForms;
};
};
codeForms
declare const codeForms: () => Rows;
columnsForms
declare const columnsForms: () => Rows;
equationForms
declare const equationForms: (m?: MathML) => {
blocks: {
equation: {
lines?: boolean;
island?: boolean;
rendersContent: boolean;
defaultChild?: string;
void: boolean;
html?: string | ((block: JSONBlock, content: string, children: string) => string);
markdown?: (block: JSONBlock, content: string, children: string, context: import("../plugins.js").MarkdownContext) => string;
plain?: (block: JSONBlock, content: string, children: string) => string;
parse?: (element: HTMLElement) => Record<string, import("../utils/json.js").SerializableContent> | undefined;
element?: import("../plugins.js").BlockElement | ((data: Record<string, any>, id?: string) => import("../plugins.js").BlockElement);
contentElement?: import("../plugins.js").BlockElement | ((data: Record<string, any>, id?: string) => import("../plugins.js").BlockElement);
itemKind?: string;
};
};
inlineBlocks: {
inlineEquation: {
html?: (data: import("../utils/json.js").JSONInlineBlock["data"]) => string;
markdown?: (data: import("../utils/json.js").JSONInlineBlock["data"]) => string;
plain?: (data: import("../utils/json.js").JSONInlineBlock["data"]) => string;
parse?: (element: HTMLElement) => Record<string, import("../utils/json.js").SerializableContent> | undefined;
};
};
};
escapeHtml
value escaped for an HTML text or a double-quoted attribute: every kind’s export reads it.
declare const escapeHtml: (value: string) => string;
ExportKinds
The records the export reads: each kind, mark and atom declares its own forms (a view is one).
export type ExportKinds = {
readonly blocks: ReadonlyMap<string, BlockForms>;
readonly marks: ReadonlyMap<string, MarkForms>;
readonly inlineBlocks: ReadonlyMap<string, AtomForms>;
};
ExportOptions
Which forms a conversion reads.
export type ExportOptions = {
kinds?: KindForms | ExportKinds;
components?: MarkdownComponents;
};
kinds: The kinds, marks and atoms to read: a view (edytor, its own records), or forms by name.components: MDX-lite, fortoMarkdown: the tags to write, each the kind it stands for ({ Endpoint: 'endpoint' }), the mapfromMarkdownreads.
fromHTML
HTML as a document, the paste’s reading (flow.html.*): only the kinds,
marks and atoms of kinds survive (an unknown element is its text, a
script or style nothing), every value through its record’s parse
hook (a link’s href through the link sanitizer: javascript: drops the
link, an image’s source through the image’s), and nothing executes: the
parser only parses, no attribute is copied (onerror, style).
import { DOMParser } from 'linkedom'; // on a server; the browser has its own
import { fromHTML } from 'edytor/export';
const value = fromHTML(html, { DOMParser });
declare const fromHTML: (html: string, options?: ImportOptions) => JSONDoc;
fromMarkdown
Markdown as a document: textToBlocks’s reading, as a JSONDoc.
With components, MDX-lite tags (<Endpoint operationId="getPet" />)
are blocks of the kinds they name; a tag it does not name, an
expression, an import or an export stays text and is told to onUnknown.
import { fromMarkdown } from 'edytor/export';
const value = fromMarkdown(source, { components: { Endpoint: 'endpoint' } });
declare const fromMarkdown: (source: string, options?: MarkdownOptions) => JSONDoc;
HtmlParser
A DOMParser constructor: the browser’s, or a server’s (linkedom, jsdom, happy-dom).
export type HtmlParser = new () => {
parseFromString(html: string, type: 'text/html'): {
body: Node | null;
};
};
imageForms
declare const imageForms: () => Rows;
ImportOptions
What fromHTML reads.
export type ImportOptions = ExportOptions & {
DOMParser?: HtmlParser;
};
KindForms
export type KindForms = {
blocks?: Record<string, BlockForms>;
marks?: Record<string, MarkForms>;
inlineBlocks?: Record<string, AtomForms>;
};
MarkdownComponents
MDX-lite tags by name, each the kind it reads as: { Endpoint: 'endpoint' }.
export type MarkdownComponents = Readonly<Record<string, string>>;
MarkdownContext
What a kind’s markdown form is given beside its block, content and children.
export type MarkdownContext = {
index: number;
indent: (text: string, prefix: string) => string;
inline: (content: JSONBlock['content']) => string;
};
index: The block’s position in its run of same-kind siblings, from 1 (a numbered item’s number).indent: Every line oftextprefixed withprefix(' 'under a list item,'> 'in a quote).inline: Rich text as inline markdown, by the marks’ and atoms’ forms (a table cell’s).
MarkdownIssue
A tag or line fromMarkdown kept as text, with why.
export type MarkdownIssue = {
reason: 'component' | 'expression' | 'unclosed' | 'import' | 'export';
source: string;
name?: string;
};
reason:component: a tagcomponentsdoes not name;expression: an attribute whose value is not a string, a number,trueorfalse({a + b},{...props});unclosed: a tag without its closing tag;import/export: an MDX import or export line.source: The line kept as text.name: The tag’s name, for a tag.
MarkdownOptions
export type MarkdownOptions = {
markdown?: boolean;
type?: string;
streaming?: boolean;
components?: MarkdownComponents;
onUnknown?: (issue: MarkdownIssue) => void;
};
markdown: Read markdown (defaulttrue);falsekeeps every character as text.type: The kind of a paragraph (defaultparagraph).streaming: The text is still arriving (defaultfalse): hold back an unfinished last line’s block marker or unclosed inline marker, and a table header row without its separator yet, so a streamed preview never shows raw markdown that the next chunk turns into a kind or a mark.components: MDX-lite: the tags to read, each as the kind it names ({ Endpoint: 'endpoint', Callout: 'callout' }).onUnknown: Told of each tag, expression, import or export kept as text.
MarkForms
A mark’s export and import forms.
export type MarkForms = Pick<MarkDefinition, 'tag' | 'attributes' | 'parse' | 'markdown'>;
MathML
export type MathML = (tex: string, display: boolean) => string;
mdxComponent
A component tag, for a kind’s markdown form: mdxComponent('Endpoint', block.data, content, children). Each data value that has a literal is an
attribute (a string "x", a number {1}, a boolean {true}); others
(objects, arrays, null, a string holding a newline or both quotes) are
left out. No text and no children: a self-closing tag. Text only: the
text inside the tag on one line. Children: the tag on its own lines, the
text first (a paragraph), then the children.
declare const mdxComponent: (name: string, data?: Record<string, SerializableContent> | undefined, content?: string, children?: string) => string;
mediaForms
declare const mediaForms: (ps?: readonly EmbedProvider[]) => Rows;
mentionForms
declare const mentionForms: (kind?: string, char?: string) => AtomForms;
pageForms
declare const pageForms: (o?: PagePluginOptions, u?: string) => Rows;
pageLinkForms
declare const pageLinkForms: () => AtomForms;
richTextForms
declare const richTextForms: (callout: (d: Data) => string) => Rows;
richTextMarkForms
declare const richTextMarkForms: {
bold: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
italic: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
underline: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
strike: {
tag: string;
parse: (el: HTMLElement) => true | undefined;
};
code: {
tag: string;
};
link: {
tag: string;
attributes: (m: {
href?: unknown;
target?: string;
}) => {
href: string | undefined;
target: string | undefined;
};
parse: (el: HTMLElement) => {
target?: string | undefined;
href: string;
} | undefined;
edge: "side-dependent";
};
superscript: {
tag: string;
};
subscript: {
tag: string;
};
color: {
tag: string;
attributes: (v: unknown) => {
style: string | undefined;
};
parse: (el: HTMLElement) => string | undefined;
};
highlight: {
tag: string;
attributes: (v: unknown) => {
style: string | undefined;
};
parse: (el: HTMLElement) => string | undefined;
};
};
tableForms
declare const tableForms: () => Rows;
textToBlocks
text as blocks (see the module comment).
declare const textToBlocks: (text: string, { markdown, type, streaming, components, onUnknown }?: MarkdownOptions) => JSONBlock[];
tocForms
declare const tocForms: () => Rows;
toHTML
A document (or blocks) as HTML: each block by its kind’s html form, a
run of list items in their list’s element, text by its marks’ elements.
Values are escaped and links through the link sanitizer; ids and empty
data are never written.
import { toHTML } from 'edytor/export';
const html = toHTML(value);
declare const toHTML: (doc: JSONDoc | readonly JSONBlock[], options?: ExportOptions) => string;
toMarkdown
A document (or blocks) as Markdown (CommonMark with GFM tables, task
lists and strikethrough): each block by its kind’s markdown form (else
its plain form), marks by theirs, atoms by theirs (else their plain
form). A toggle is a <details> disclosure, a callout a > [!NOTE]
alert; textToBlocks reads both back.
declare const toMarkdown: (doc: JSONDoc | readonly JSONBlock[], options?: ExportOptions) => string;