diff options
author | tschicke-brown <tyler_schicke@brown.edu> | 2019-03-16 23:20:16 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-16 23:20:16 -0400 |
commit | f505dfa8234de4ea94304b104e801f72ea30ff39 (patch) | |
tree | a6539212ad00eeb7e5a2d3b2a0af2b10745f0cc3 /src/client/util/RichTextRules.ts | |
parent | 8601bcbb46c80282d1fac6863544f9c72050ebd4 (diff) | |
parent | 6974d1ff65f997b045695fa4a6c541a5c1f91e90 (diff) |
Merge pull request #59 from browngraphicslab/improveText
Comments on text toolbar stuff
Diffstat (limited to 'src/client/util/RichTextRules.ts')
-rw-r--r-- | src/client/util/RichTextRules.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/client/util/RichTextRules.ts b/src/client/util/RichTextRules.ts new file mode 100644 index 000000000..3b8396510 --- /dev/null +++ b/src/client/util/RichTextRules.ts @@ -0,0 +1,43 @@ +import { + inputRules, + wrappingInputRule, + textblockTypeInputRule, + smartQuotes, + emDash, + ellipsis +} from "prosemirror-inputrules"; +import { Schema, NodeSpec, MarkSpec, DOMOutputSpecArray, NodeType } from "prosemirror-model"; + +import { schema } from "./RichTextSchema"; + +export const inpRules = { + rules: [ + ...smartQuotes, + ellipsis, + emDash, + + // > blockquote + wrappingInputRule(/^\s*>\s$/, schema.nodes.blockquote), + + // 1. ordered list + wrappingInputRule( + /^(\d+)\.\s$/, + schema.nodes.ordered_list, + match => ({ order: +match[1] }), + (match, node) => node.childCount + node.attrs.order === +match[1] + ), + + // * bullet list + wrappingInputRule(/^\s*([-+*])\s$/, schema.nodes.bullet_list), + + // ``` code block + textblockTypeInputRule(/^```$/, schema.nodes.code_block), + + // # heading + textblockTypeInputRule( + new RegExp("^(#{1,6})\\s$"), + schema.nodes.heading, + match => ({ level: match[1].length }) + ) + ] +}; |