.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / mdast-util-compact / index.js
diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/mdast-util-compact/index.js b/.config/coc/extensions/node_modules/coc-prettier/node_modules/mdast-util-compact/index.js
new file mode 100644 (file)
index 0000000..eee0fdf
--- /dev/null
@@ -0,0 +1,61 @@
+'use strict'
+
+var visit = require('unist-util-visit')
+
+module.exports = compact
+
+// Make an mdast tree compact by merging adjacent text nodes.
+function compact(tree, commonmark) {
+  visit(tree, visitor)
+
+  return tree
+
+  function visitor(child, index, parent) {
+    var siblings = parent ? parent.children : []
+    var prev = index && siblings[index - 1]
+
+    if (
+      prev &&
+      child.type === prev.type &&
+      mergeable(prev, commonmark) &&
+      mergeable(child, commonmark)
+    ) {
+      if (child.value) {
+        prev.value += child.value
+      }
+
+      if (child.children) {
+        prev.children = prev.children.concat(child.children)
+      }
+
+      siblings.splice(index, 1)
+
+      if (prev.position && child.position) {
+        prev.position.end = child.position.end
+      }
+
+      return index
+    }
+  }
+}
+
+function mergeable(node, commonmark) {
+  var start
+  var end
+
+  if (node.type === 'text') {
+    if (!node.position) {
+      return true
+    }
+
+    start = node.position.start
+    end = node.position.end
+
+    // Only merge nodes which occupy the same size as their `value`.
+    return (
+      start.line !== end.line || end.column - start.column === node.value.length
+    )
+  }
+
+  return commonmark && node.type === 'blockquote'
+}