123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- import {splice} from 'micromark-util-chunked'
- const hasOwnProperty = {}.hasOwnProperty
- export function combineExtensions(extensions) {
-
- const all = {}
- let index = -1
- while (++index < extensions.length) {
- syntaxExtension(all, extensions[index])
- }
- return all
- }
- function syntaxExtension(all, extension) {
-
- let hook
- for (hook in extension) {
- const maybe = hasOwnProperty.call(all, hook) ? all[hook] : undefined
-
- const left = maybe || (all[hook] = {})
-
- const right = extension[hook]
-
- let code
- if (right) {
- for (code in right) {
- if (!hasOwnProperty.call(left, code)) left[code] = []
- const value = right[code]
- constructs(
-
- left[code],
- Array.isArray(value) ? value : value ? [value] : []
- )
- }
- }
- }
- }
- function constructs(existing, list) {
- let index = -1
-
- const before = []
- while (++index < list.length) {
-
- ;(list[index].add === 'after' ? existing : before).push(list[index])
- }
- splice(existing, 0, 0, before)
- }
- export function combineHtmlExtensions(htmlExtensions) {
-
- const handlers = {}
- let index = -1
- while (++index < htmlExtensions.length) {
- htmlExtension(handlers, htmlExtensions[index])
- }
- return handlers
- }
- function htmlExtension(all, extension) {
-
- let hook
- for (hook in extension) {
- const maybe = hasOwnProperty.call(all, hook) ? all[hook] : undefined
- const left = maybe || (all[hook] = {})
- const right = extension[hook]
-
- let type
- if (right) {
- for (type in right) {
-
- left[type] = right[type]
- }
- }
- }
- }
|