From a55e679563b7cbd64b14d49ebde499597ec66a9e Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 30 Jun 2017 12:21:01 -0400 Subject: [PATCH] support wrap function in bbcode rules --- .../engines/markdown-it/bbcode-block.js.es6 | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/pretty-text/engines/markdown-it/bbcode-block.js.es6 b/app/assets/javascripts/pretty-text/engines/markdown-it/bbcode-block.js.es6 index 952fe9426a9..40fa118a3d4 100644 --- a/app/assets/javascripts/pretty-text/engines/markdown-it/bbcode-block.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/markdown-it/bbcode-block.js.es6 @@ -213,14 +213,31 @@ function applyBBCode(state, startLine, endLine, silent, md) { let wrapTag; if (rule.wrap) { - let split = rule.wrap.split('.'); - wrapTag = split[0]; - let className = split.slice(1).join(' '); + let token; - let token = state.push('wrap_bbcode', wrapTag, 1); + if (typeof rule.wrap === 'function') { + token = new state.Token('wrap_bbcode', 'div', 1); + token.level = state.level+1; - if (className) { - token.attrs = [['class', className]]; + if (!rule.wrap(token, info)) { + return false; + } + + state.tokens.push(token); + state.level = token.level; + wrapTag = token.tag; + + } else { + + let split = rule.wrap.split('.'); + wrapTag = split[0]; + let className = split.slice(1).join(' '); + + token = state.push('wrap_bbcode', wrapTag, 1); + + if (className) { + token.attrs = [['class', className]]; + } } }