Skip to content

Commit

Permalink
refactor(extensions): reducing the use of yfm in variable and file na…
Browse files Browse the repository at this point in the history
…mes (#256)
  • Loading branch information
d3m1d0v authored May 31, 2024
1 parent 85cc2af commit a294398
Show file tree
Hide file tree
Showing 42 changed files with 165 additions and 165 deletions.
26 changes: 13 additions & 13 deletions src/extensions/markdown/Deflist/DeflistSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {ExtensionAuto} from '../../../../core';
import {nodeTypeFactory} from '../../../../utils/schema';

import {DeflistNode} from './const';
import {fromYfm} from './fromYfm';
import {getSpec} from './spec';
import {toYfm} from './toYfm';
import {parserTokens} from './parser';
import {getSchemaSpecs} from './schema';
import {serializerTokens} from './serializer';

export {DeflistNode} from './const';
export const defListType = nodeTypeFactory(DeflistNode.List);
Expand All @@ -26,23 +26,23 @@ export type DeflistSpecsOptions = {
};

export const DeflistSpecs: ExtensionAuto<DeflistSpecsOptions> = (builder, opts) => {
const spec = getSpec(opts, builder.context.get('placeholder'));
const schemaSpecs = getSchemaSpecs(opts, builder.context.get('placeholder'));

builder.configureMd((md) => md.use(deflistPlugin));
builder
.addNode(DeflistNode.List, () => ({
spec: spec[DeflistNode.List],
fromMd: {tokenSpec: fromYfm[DeflistNode.List]},
toMd: toYfm[DeflistNode.List],
spec: schemaSpecs[DeflistNode.List],
fromMd: {tokenSpec: parserTokens[DeflistNode.List]},
toMd: serializerTokens[DeflistNode.List],
}))
.addNode(DeflistNode.Term, () => ({
spec: spec[DeflistNode.Term],
fromMd: {tokenSpec: fromYfm[DeflistNode.Term]},
toMd: toYfm[DeflistNode.Term],
spec: schemaSpecs[DeflistNode.Term],
fromMd: {tokenSpec: parserTokens[DeflistNode.Term]},
toMd: serializerTokens[DeflistNode.Term],
}))
.addNode(DeflistNode.Desc, () => ({
spec: spec[DeflistNode.Desc],
fromMd: {tokenSpec: fromYfm[DeflistNode.Desc]},
toMd: toYfm[DeflistNode.Desc],
spec: schemaSpecs[DeflistNode.Desc],
fromMd: {tokenSpec: parserTokens[DeflistNode.Desc]},
toMd: serializerTokens[DeflistNode.Desc],
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {ParserToken} from '../../../../core';

import {DeflistNode} from './const';

export const fromYfm: Record<DeflistNode, ParserToken> = {
export const parserTokens: Record<DeflistNode, ParserToken> = {
[DeflistNode.List]: {name: DeflistNode.List, type: 'block'},

[DeflistNode.Term]: {name: DeflistNode.Term, type: 'block'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DEFAULT_PLACEHOLDERS = {
Desc: 'Definition description',
};

export const getSpec = (
export const getSchemaSpecs = (
opts?: DeflistSpecsOptions,
placeholder?: PlaceholderOptions,
): Record<DeflistNode, NodeSpec> => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {SerializerNodeToken} from '../../../../core';

import {DeflistNode} from './const';

export const toYfm: Record<DeflistNode, SerializerNodeToken> = {
export const serializerTokens: Record<DeflistNode, SerializerNodeToken> = {
[DeflistNode.List]: (state, node) => {
state.renderContent(node);
},
Expand Down
18 changes: 9 additions & 9 deletions src/extensions/markdown/Html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type {ExtensionAuto} from '../../../core';
import {logger} from '../../../logger';

import {HtmlNode} from './const';
import {fromYfm} from './fromYfm';
import {spec} from './spec';
import {toYfm} from './toYfm';
import {parserTokens} from './parser';
import {schemaSpecs} from './schema';
import {serializerTokens} from './serializer';

export {HtmlAttr, HtmlNode} from './const';

Expand All @@ -15,15 +15,15 @@ export const Html: ExtensionAuto = (builder) => {
}

builder.addNode(HtmlNode.Block, () => ({
spec: spec[HtmlNode.Block],
fromMd: {tokenSpec: fromYfm[HtmlNode.Block]},
toMd: toYfm[HtmlNode.Block],
spec: schemaSpecs[HtmlNode.Block],
fromMd: {tokenSpec: parserTokens[HtmlNode.Block]},
toMd: serializerTokens[HtmlNode.Block],
}));

builder.addNode(HtmlNode.Inline, () => ({
spec: spec[HtmlNode.Inline],
fromMd: {tokenSpec: fromYfm[HtmlNode.Inline]},
toMd: toYfm[HtmlNode.Inline],
spec: schemaSpecs[HtmlNode.Inline],
fromMd: {tokenSpec: parserTokens[HtmlNode.Inline]},
toMd: serializerTokens[HtmlNode.Inline],
}));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {ParserToken} from '../../../core';

import {HtmlAttr, HtmlNode} from './const';

export const fromYfm: Record<HtmlNode, ParserToken> = {
export const parserTokens: Record<HtmlNode, ParserToken> = {
[HtmlNode.Block]: {
name: HtmlNode.Block,
type: 'node',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ enum DomAttr {
HtmlRaw = 'data-html-raw',
}

export const spec: Record<HtmlNode, NodeSpec> = {
export const schemaSpecs: Record<HtmlNode, NodeSpec> = {
[HtmlNode.Block]: {
atom: true,
group: 'block',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {SerializerNodeToken} from '../../../core';

import {HtmlAttr, HtmlNode} from './const';

export const toYfm: Record<HtmlNode, SerializerNodeToken> = {
export const serializerTokens: Record<HtmlNode, SerializerNodeToken> = {
[HtmlNode.Block]: (state, node) => {
state.write(node.attrs[HtmlAttr.Content]);
state.ensureNewLine();
Expand Down
24 changes: 12 additions & 12 deletions src/extensions/markdown/Lists/ListsSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type {ExtensionAuto} from '../../../../core';
import {nodeTypeFactory} from '../../../../utils/schema';

import {ListNode} from './const';
import {fromYfm} from './fromYfm';
import {spec} from './spec';
import {toYfm} from './toYfm';
import {parserTokens} from './parser';
import {schemaSpecs} from './schema';
import {serializerTokens} from './serializer';

export {ListNode} from './const';
export const liType = nodeTypeFactory(ListNode.ListItem);
Expand All @@ -14,18 +14,18 @@ export const olType = nodeTypeFactory(ListNode.OrderedList);
export const ListsSpecs: ExtensionAuto = (builder) => {
builder
.addNode(ListNode.ListItem, () => ({
spec: spec[ListNode.ListItem],
toMd: toYfm[ListNode.ListItem],
fromMd: {tokenSpec: fromYfm[ListNode.ListItem]},
spec: schemaSpecs[ListNode.ListItem],
toMd: serializerTokens[ListNode.ListItem],
fromMd: {tokenSpec: parserTokens[ListNode.ListItem]},
}))
.addNode(ListNode.BulletList, () => ({
spec: spec[ListNode.BulletList],
toMd: toYfm[ListNode.BulletList],
fromMd: {tokenSpec: fromYfm[ListNode.BulletList]},
spec: schemaSpecs[ListNode.BulletList],
toMd: serializerTokens[ListNode.BulletList],
fromMd: {tokenSpec: parserTokens[ListNode.BulletList]},
}))
.addNode(ListNode.OrderedList, () => ({
spec: spec[ListNode.OrderedList],
toMd: toYfm[ListNode.OrderedList],
fromMd: {tokenSpec: fromYfm[ListNode.OrderedList]},
spec: schemaSpecs[ListNode.OrderedList],
toMd: serializerTokens[ListNode.OrderedList],
fromMd: {tokenSpec: parserTokens[ListNode.OrderedList]},
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type {ParserToken} from '../../../../core';

import {ListNode} from './const';

export const fromYfm: Record<ListNode, ParserToken> = {
export const parserTokens: Record<ListNode, ParserToken> = {
[ListNode.ListItem]: {name: ListNode.ListItem, type: 'block'},

[ListNode.BulletList]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {NodeSpec} from 'prosemirror-model';

import {ListNode} from './const';

export const spec: Record<ListNode, NodeSpec> = {
export const schemaSpecs: Record<ListNode, NodeSpec> = {
[ListNode.ListItem]: {
attrs: {tight: {default: false}},
content: '(paragraph|block)+',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {SerializerNodeToken} from '../../../../core';

import {ListNode} from './const';

export const toYfm: Record<ListNode, SerializerNodeToken> = {
export const serializerTokens: Record<ListNode, SerializerNodeToken> = {
[ListNode.ListItem]: (state, node) => {
state.renderContent(node);
},
Expand Down
42 changes: 21 additions & 21 deletions src/extensions/markdown/Table/TableSpecs/index.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
import type {ExtensionAuto} from '../../../../core';

import {TableNode} from './const';
import {fromYfm} from './fromYfm';
import {spec} from './spec';
import {toYfm} from './toYfm';
import {parserTokens} from './parser';
import {schemaSpecs} from './schema';
import {serializerTokens} from './serializer';

export {TableNode} from './const';

export const TableSpecs: ExtensionAuto = (builder) => {
builder
.addNode(TableNode.Table, () => ({
spec: spec[TableNode.Table],
toMd: toYfm[TableNode.Table],
fromMd: {tokenSpec: fromYfm[TableNode.Table]},
spec: schemaSpecs[TableNode.Table],
toMd: serializerTokens[TableNode.Table],
fromMd: {tokenSpec: parserTokens[TableNode.Table]},
}))
.addNode(TableNode.Head, () => ({
spec: spec[TableNode.Head],
toMd: toYfm[TableNode.Head],
fromMd: {tokenSpec: fromYfm[TableNode.Head]},
spec: schemaSpecs[TableNode.Head],
toMd: serializerTokens[TableNode.Head],
fromMd: {tokenSpec: parserTokens[TableNode.Head]},
}))
.addNode(TableNode.Body, () => ({
spec: spec[TableNode.Body],
toMd: toYfm[TableNode.Body],
fromMd: {tokenSpec: fromYfm[TableNode.Body]},
spec: schemaSpecs[TableNode.Body],
toMd: serializerTokens[TableNode.Body],
fromMd: {tokenSpec: parserTokens[TableNode.Body]},
}))
.addNode(TableNode.Row, () => ({
spec: spec[TableNode.Row],
toMd: toYfm[TableNode.Row],
fromMd: {tokenSpec: fromYfm[TableNode.Row]},
spec: schemaSpecs[TableNode.Row],
toMd: serializerTokens[TableNode.Row],
fromMd: {tokenSpec: parserTokens[TableNode.Row]},
}))
.addNode(TableNode.HeaderCell, () => ({
spec: spec[TableNode.HeaderCell],
toMd: toYfm[TableNode.HeaderCell],
fromMd: {tokenSpec: fromYfm[TableNode.HeaderCell]},
spec: schemaSpecs[TableNode.HeaderCell],
toMd: serializerTokens[TableNode.HeaderCell],
fromMd: {tokenSpec: parserTokens[TableNode.HeaderCell]},
}))
.addNode(TableNode.DataCell, () => ({
spec: spec[TableNode.DataCell],
toMd: toYfm[TableNode.DataCell],
fromMd: {tokenSpec: fromYfm[TableNode.DataCell]},
spec: schemaSpecs[TableNode.DataCell],
toMd: serializerTokens[TableNode.DataCell],
fromMd: {tokenSpec: parserTokens[TableNode.DataCell]},
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type Token from 'markdown-it/lib/token';
import type {ParserToken} from '../../../../core';
import {CellAlign, TableAttrs, TableNode} from '../const';

export const fromYfm: Record<TableNode, ParserToken> = {
export const parserTokens: Record<TableNode, ParserToken> = {
[TableNode.Table]: {name: TableNode.Table, type: 'block'},

[TableNode.Head]: {name: TableNode.Head, type: 'block'},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type {NodeSpec} from 'prosemirror-model';
import {TableRole} from '../../../../table-utils';
import {CellAlign, TableAttrs, TableNode} from '../const';

export const spec: Record<TableNode, NodeSpec> = {
export const schemaSpecs: Record<TableNode, NodeSpec> = {
[TableNode.Table]: {
group: 'block',
content: `${TableNode.Head} ${TableNode.Body}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {SerializerNodeToken} from '../../../../core';
import {CellAlign, TableAttrs, TableNode} from '../const';

export const toYfm: Record<TableNode, SerializerNodeToken> = {
export const serializerTokens: Record<TableNode, SerializerNodeToken> = {
[TableNode.Table]: (state, node) => {
state.ensureNewLine();
state.write('\n');
Expand Down
26 changes: 13 additions & 13 deletions src/extensions/yfm/Checkbox/CheckboxSpecs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type {ExtensionAuto, ExtensionNodeSpec} from '../../../../core';
import {nodeTypeFactory} from '../../../../utils/schema';

import {CheckboxNode, b, idPrefix} from './const';
import {fromYfm} from './fromYfm';
import {getSpec} from './spec';
import {toYfm} from './toYfm';
import {parserTokens} from './parser';
import {getSchemaSpecs} from './schema';
import {serializerTokens} from './serializer';

export {CheckboxNode} from './const';
export const checkboxType = nodeTypeFactory(CheckboxNode.Checkbox);
Expand All @@ -25,31 +25,31 @@ export type CheckboxSpecsOptions = {
};

export const CheckboxSpecs: ExtensionAuto<CheckboxSpecsOptions> = (builder, opts) => {
const spec = getSpec(opts, builder.context.get('placeholder'));
const schemaSpecs = getSchemaSpecs(opts, builder.context.get('placeholder'));

builder
.configureMd((md) => checkboxPlugin(md, {idPrefix, divClass: b()}))
.addNode(CheckboxNode.Checkbox, () => ({
spec: spec[CheckboxNode.Checkbox],
toMd: toYfm[CheckboxNode.Checkbox],
spec: schemaSpecs[CheckboxNode.Checkbox],
toMd: serializerTokens[CheckboxNode.Checkbox],
fromMd: {
tokenSpec: fromYfm[CheckboxNode.Checkbox],
tokenSpec: parserTokens[CheckboxNode.Checkbox],
},
view: opts.checkboxView,
}))
.addNode(CheckboxNode.Input, () => ({
spec: spec[CheckboxNode.Input],
toMd: toYfm[CheckboxNode.Input],
spec: schemaSpecs[CheckboxNode.Input],
toMd: serializerTokens[CheckboxNode.Input],
fromMd: {
tokenSpec: fromYfm[CheckboxNode.Input],
tokenSpec: parserTokens[CheckboxNode.Input],
},
view: opts.inputView,
}))
.addNode(CheckboxNode.Label, () => ({
spec: spec[CheckboxNode.Label],
toMd: toYfm[CheckboxNode.Label],
spec: schemaSpecs[CheckboxNode.Label],
toMd: serializerTokens[CheckboxNode.Label],
fromMd: {
tokenSpec: fromYfm[CheckboxNode.Label],
tokenSpec: parserTokens[CheckboxNode.Label],
tokenName: 'checkbox_label',
},
view: opts.labelView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {CheckboxNode} from '../const';

const getAttrs: ParserToken['getAttrs'] = (tok) => (tok.attrs ? Object.fromEntries(tok.attrs) : {});

export const fromYfm: Record<CheckboxNode, ParserToken> = {
export const parserTokens: Record<CheckboxNode, ParserToken> = {
[CheckboxNode.Checkbox]: {name: CheckboxNode.Checkbox, type: 'block', getAttrs},

[CheckboxNode.Input]: {name: CheckboxNode.Input, type: 'node', getAttrs},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {CheckboxSpecsOptions} from './index';

const DEFAULT_LABEL_PLACEHOLDER = 'Checkbox';

export const getSpec = (
export const getSchemaSpecs = (
opts?: Pick<CheckboxSpecsOptions, 'checkboxLabelPlaceholder'>,
placeholder?: PlaceholderOptions,
): Record<CheckboxNode, NodeSpec> => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {SerializerNodeToken} from '../../../../core';
import {getPlaceholderContent} from '../../../../utils/placeholder';
import {CheckboxNode} from '../const';

export const toYfm: Record<CheckboxNode, SerializerNodeToken> = {
export const serializerTokens: Record<CheckboxNode, SerializerNodeToken> = {
[CheckboxNode.Checkbox]: (state, node) => {
state.renderInline(node);
state.closeBlock(node);
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/yfm/Checkbox/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {builders} from 'prosemirror-test-builder';

import {applyCommand} from '../../../../tests/utils';

import {getSpec} from './CheckboxSpecs/spec';
import {getSchemaSpecs} from './CheckboxSpecs/schema';
import {addCheckboxCmd} from './actions';

const schema = new Schema({
nodes: {
doc: {content: 'block+'},
text: {group: 'inline'},
paragraph: {group: 'block', content: 'inline*'},
...getSpec(),
...getSchemaSpecs(),
},
});

Expand Down
Loading

0 comments on commit a294398

Please sign in to comment.