-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
135 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
# Enable history support in the editor | ||
|
||
Reference | ||
|
||
- https://prosemirror.net/docs/ref/#history | ||
- https://prosemirror.net/docs/ref/#keymap | ||
# Enable/Disable editor history support | ||
|
||
```ts | ||
import { undo, redo, history } from 'prosemirror-history'; | ||
import { keymap } from 'prosemirror-keymap'; | ||
import { Editor } from 'ngx-editor'; | ||
|
||
new Editor({ | ||
plugins: [ | ||
history(), // enable history support | ||
keymap({ | ||
// configure shortcuts | ||
'Mod-z': undo, | ||
'Shift-Mod-z': redo, | ||
}), | ||
], | ||
history: true, | ||
}); | ||
``` | ||
|
||
_**Note**: You may need to disable history if you are using collaborative editing_ | ||
|
||
Related links | ||
|
||
- https://prosemirror.net/docs/ref/#history | ||
- https://prosemirror.net/docs/ref/#keymap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,18 @@ | ||
# Input rules | ||
|
||
This module defines a plugin for attaching input rules to an editor, which can react to or transform text typed by the user. | ||
|
||
Doc: https://prosemirror.net/docs/ref/#inputrules | ||
|
||
Source: https://github.com/ProseMirror/prosemirror-example-setup/ | ||
|
||
### Rules | ||
|
||
````ts | ||
import { | ||
inputRules, | ||
wrappingInputRule, | ||
textblockTypeInputRule, | ||
smartQuotes, | ||
emDash, | ||
ellipsis, | ||
InputRule, | ||
} from 'prosemirror-inputrules'; | ||
import { NodeType, Schema } from 'prosemirror-model'; | ||
|
||
// : (NodeType) → InputRule | ||
// Given a blockquote node type, returns an input rule that turns `"> "` | ||
// at the start of a textblock into a blockquote. | ||
export function blockQuoteRule(nodeType: NodeType): InputRule { | ||
return wrappingInputRule(/^\s*>\s$/, nodeType); | ||
} | ||
|
||
// : (NodeType) → InputRule | ||
// Given a list node type, returns an input rule that turns a number | ||
// followed by a dot at the start of a textblock into an ordered list. | ||
export function orderedListRule(nodeType: NodeType): InputRule { | ||
return wrappingInputRule( | ||
/^(\d+)\.\s$/, | ||
nodeType, | ||
(match) => ({ order: +match[1] }), | ||
(match, node) => node.childCount + node.attrs.order === +match[1] | ||
); | ||
} | ||
|
||
// : (NodeType) → InputRule | ||
// Given a list node type, returns an input rule that turns a bullet | ||
// (dash, plush, or asterisk) at the start of a textblock into a | ||
// bullet list. | ||
export function bulletListRule(nodeType: NodeType): InputRule { | ||
return wrappingInputRule(/^\s*([-+*])\s$/, nodeType); | ||
} | ||
|
||
// : (NodeType) → InputRule | ||
// Given a code block node type, returns an input rule that turns a | ||
// textblock starting with three backticks into a code block. | ||
export function codeBlockRule(nodeType: NodeType): InputRule { | ||
return textblockTypeInputRule(/^```$/, nodeType); | ||
} | ||
|
||
// : (NodeType, number) → InputRule | ||
// Given a node type and a maximum level, creates an input rule that | ||
// turns up to that number of `#` characters followed by a space at | ||
// the start of a textblock into a heading whose level corresponds to | ||
// the number of `#` signs. | ||
export function headingRule(nodeType: NodeType, maxLevel: number): InputRule { | ||
return textblockTypeInputRule( | ||
new RegExp('^(#{1,' + maxLevel + '})\\s$'), | ||
nodeType, | ||
(match) => ({ | ||
level: match[1].length, | ||
}) | ||
); | ||
} | ||
|
||
// : (Schema) → Plugin | ||
// A set of input rules for creating the basic block quotes, lists, | ||
// code blocks, and heading. | ||
export function buildInputRules(schema: Schema) { | ||
const rules = smartQuotes.concat(ellipsis, emDash); | ||
|
||
rules.push(blockQuoteRule(schema.nodes.blockquote)); | ||
rules.push(orderedListRule(schema.nodes.ordered_list)); | ||
rules.push(bulletListRule(schema.nodes.bullet_list)); | ||
rules.push(codeBlockRule(schema.nodes.code_block)); | ||
rules.push(headingRule(schema.nodes.heading, 6)); | ||
|
||
return inputRules({ rules }); | ||
} | ||
```` | ||
Some default input rules based on schema is enabled by defualt | ||
|
||
### Config | ||
|
||
```ts | ||
import { Editor, schema } from 'ngx-editor'; | ||
import { Editor } from 'ngx-editor'; | ||
|
||
new Editor({ | ||
plugins: [buildInputRules(schema)], | ||
inputRules: true, | ||
}); | ||
``` | ||
|
||
Related Links: | ||
|
||
- https://prosemirror.net/docs/ref/#inputrules | ||
- https://github.com/ProseMirror/prosemirror-example-setup/ |
Oops, something went wrong.