prosemirror-model
Advanced tools
Comparing version 1.12.0 to 1.13.0
@@ -0,1 +1,7 @@ | ||
## 1.13.0 (2020-12-11) | ||
### New features | ||
Parse rules can now have a `consuming: false` property which allows other rules to match their tag or style even when they apply. | ||
## 1.12.0 (2020-10-11) | ||
@@ -2,0 +8,0 @@ |
{ | ||
"name": "prosemirror-model", | ||
"version": "1.12.0", | ||
"version": "1.13.0", | ||
"description": "ProseMirror's document model", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,3 +13,3 @@ module.exports = { | ||
plugins: [require('@rollup/plugin-buble')()], | ||
external(id) { return !/^[\.\/]/.test(id) } | ||
external(id) { return id[0] != "." && !require("path").isAbsolute(id) } | ||
} |
@@ -71,2 +71,8 @@ import {Fragment} from "./fragment" | ||
// | ||
// consuming:: ?boolean | ||
// By default, when a rule matches an element or style, no further | ||
// rules get a chance to match it. By setting this to `false`, you | ||
// indicate that even when this rule matches, other rules that come | ||
// after it should also run. | ||
// | ||
// context:: ?string | ||
@@ -193,4 +199,4 @@ // When given, restricts this rule to only match when the current | ||
matchTag(dom, context) { | ||
for (let i = 0; i < this.tags.length; i++) { | ||
matchTag(dom, context, after) { | ||
for (let i = after ? this.tags.indexOf(after) + 1 : 0; i < this.tags.length; i++) { | ||
let rule = this.tags[i] | ||
@@ -210,4 +216,4 @@ if (matches(dom, rule.tag) && | ||
matchStyle(prop, value, context) { | ||
for (let i = 0; i < this.styles.length; i++) { | ||
matchStyle(prop, value, context, after) { | ||
for (let i = after ? this.styles.indexOf(after) + 1 : 0; i < this.styles.length; i++) { | ||
let rule = this.styles[i] | ||
@@ -435,9 +441,10 @@ if (rule.style.indexOf(prop) != 0 || | ||
// : (dom.Element) | ||
// : (dom.Element, ?ParseRule) | ||
// Try to find a handler for the given tag and use that to parse. If | ||
// none is found, the element's content nodes are added directly. | ||
addElement(dom) { | ||
let name = dom.nodeName.toLowerCase() | ||
addElement(dom, matchAfter) { | ||
let name = dom.nodeName.toLowerCase(), ruleID | ||
if (listTags.hasOwnProperty(name) && this.parser.normalizeLists) normalizeList(dom) | ||
let rule = (this.options.ruleFromNode && this.options.ruleFromNode(dom)) || this.parser.matchTag(dom, this) | ||
let rule = (this.options.ruleFromNode && this.options.ruleFromNode(dom)) || | ||
(ruleID = this.parser.matchTag(dom, this, matchAfter)) | ||
if (rule ? rule.ignore : ignoreTags.hasOwnProperty(name)) { | ||
@@ -460,3 +467,3 @@ this.findInside(dom) | ||
} else { | ||
this.addElementByRule(dom, rule) | ||
this.addElementByRule(dom, rule, rule.consuming === false ? ruleID : null) | ||
} | ||
@@ -476,7 +483,11 @@ } | ||
let marks = Mark.none | ||
for (let i = 0; i < styles.length; i += 2) { | ||
let rule = this.parser.matchStyle(styles[i], styles[i + 1], this) | ||
if (!rule) continue | ||
if (rule.ignore) return null | ||
marks = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(marks) | ||
style: for (let i = 0; i < styles.length; i += 2) { | ||
for (let after = null;;) { | ||
let rule = this.parser.matchStyle(styles[i], styles[i + 1], this, after) | ||
if (!rule) continue style | ||
if (rule.ignore) return null | ||
marks = this.parser.schema.marks[rule.mark].create(rule.attrs).addToSet(marks) | ||
if (rule.consuming === false) after = rule | ||
else break | ||
} | ||
} | ||
@@ -490,3 +501,3 @@ return marks | ||
// the node's content is wrapped, and return true. | ||
addElementByRule(dom, rule) { | ||
addElementByRule(dom, rule, continueAfter) { | ||
let sync, nodeType, markType, mark | ||
@@ -509,2 +520,4 @@ if (rule.node) { | ||
this.findInside(dom) | ||
} else if (continueAfter) { | ||
this.addElement(dom, continueAfter) | ||
} else if (rule.getContent) { | ||
@@ -511,0 +524,0 @@ this.findInside(dom) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
891796
9174