Refactor code-style

This commit is contained in:
Titus Wormer 2021-06-08 16:19:30 +02:00
parent 399bc1ecef
commit 71af94adb5
No known key found for this signature in database
GPG key ID: E6E581152ED04E2E

View file

@ -2,21 +2,27 @@ import {decodeEntity} from 'parse-entities/decode-entity.js'
const own = {}.hasOwnProperty
export function directiveHtml(options) {
const extensions = options || {}
export function directiveHtml(options = {}) {
return {
enter: {
directiveContainer: enterContainer,
directiveContainer() {
return enter.call(this, 'containerDirective')
},
directiveContainerAttributes: enterAttributes,
directiveContainerContent: enterContainerContent,
directiveContainerLabel: enterLabel,
directiveContainerContent() {
this.buffer()
},
directiveLeaf: enterLeaf,
directiveLeaf() {
return enter.call(this, 'leafDirective')
},
directiveLeafAttributes: enterAttributes,
directiveLeafLabel: enterLabel,
directiveText: enterText,
directiveText() {
return enter.call(this, 'textDirective')
},
directiveTextAttributes: enterAttributes,
directiveTextLabel: enterLabel
},
@ -52,18 +58,6 @@ export function directiveHtml(options) {
}
}
function enterContainer() {
return enter.call(this, 'containerDirective')
}
function enterLeaf() {
return enter.call(this, 'leafDirective')
}
function enterText() {
return enter.call(this, 'textDirective')
}
function enter(type) {
let stack = this.getData('directiveStack')
if (!stack) this.setData('directiveStack', (stack = []))
@ -139,10 +133,6 @@ export function directiveHtml(options) {
stack[stack.length - 1].attributes = cleaned
}
function enterContainerContent() {
this.buffer()
}
function exitContainerContent() {
const data = this.resume()
const stack = this.getData('directiveStack')
@ -162,13 +152,13 @@ export function directiveHtml(options) {
let found
let result
if (own.call(extensions, directive.name)) {
result = extensions[directive.name].call(this, directive)
if (own.call(options, directive.name)) {
result = options[directive.name].call(this, directive)
found = result !== false
}
if (!found && own.call(extensions, '*')) {
result = extensions['*'].call(this, directive)
if (!found && own.call(options, '*')) {
result = options['*'].call(this, directive)
found = result !== false
}