Merge pull request #339 from michalsnik/feature/support-inputRules-in-Image

Feature: Support `inputRules` in Image node
This commit is contained in:
Philipp Kühn 2019-06-04 21:22:01 +02:00 committed by GitHub
commit 38f876c927
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,15 @@
import { Node, Plugin } from 'tiptap'
import { nodeInputRule } from 'tiptap-commands'
/**
* Matches following attributes in Markdown-typed image: [, alt, src, title]
*
* Example:
* ![Lorem](image.jpg) -> [, "Lorem", "image.jpg"]
* ![](image.jpg "Ipsum") -> [, "", "image.jpg", "Ipsum"]
* ![Lorem](image.jpg "Ipsum") -> [, "Lorem", "image.jpg", "Ipsum"]
*/
const IMAGE_INPUT_REGEX = /!\[(.+|:?)\]\((\S+)(?:(?:\s+)["'](\S+)["'])?\)/
export default class Image extends Node {
@ -44,6 +55,19 @@ export default class Image extends Node {
}
}
inputRules({ type }) {
return [
nodeInputRule(IMAGE_INPUT_REGEX, type, match => {
const [, alt, src, title] = match
return {
src,
alt,
title,
}
}),
]
}
get plugins() {
return [
new Plugin({