From 86b03123645ee3c543c6b5930bc46e5eebd9a959 Mon Sep 17 00:00:00 2001 From: appix-CH Date: Thu, 30 Nov 2017 13:43:58 +0100 Subject: [PATCH] Allow function as "parentTag" property This enables advanced functionality where the parent tag depends on the value of an attribute, e.g. lists --- lib/doc.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/doc.js b/lib/doc.js index e105783..cb35b4b 100644 --- a/lib/doc.js +++ b/lib/doc.js @@ -81,7 +81,11 @@ Doc.prototype.applyFormat = function(node, format, value) { } if (format.parentTag) { - var parent = this.document.createElement(format.parentTag); + var parentTag = format.parentTag; + if (typeof parentTag === 'function') { + parentTag = parentTag(node, value, dom); + } + var parent = this.document.createElement(parentTag); dom(node).wrap(parent); if (parent.previousSibling && parent.tagName === parent.previousSibling.tagName) { dom(parent.previousSibling).merge(parent);