.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-stringify / lib / visitors / inline-code.js
diff --git a/.config/coc/extensions/node_modules/coc-prettier/node_modules/remark-stringify/lib/visitors/inline-code.js b/.config/coc/extensions/node_modules/coc-prettier/node_modules/remark-stringify/lib/visitors/inline-code.js
new file mode 100644 (file)
index 0000000..21666ba
--- /dev/null
@@ -0,0 +1,35 @@
+'use strict';
+
+var streak = require('longest-streak');
+var repeat = require('repeat-string');
+
+module.exports = inlineCode;
+
+/* Stringify inline code.
+ *
+ * Knows about internal ticks (`\``), and ensures one more
+ * tick is used to enclose the inline code:
+ *
+ *     ```foo ``bar`` baz```
+ *
+ * Even knows about inital and final ticks:
+ *
+ *     `` `foo ``
+ *     `` foo` ``
+ */
+function inlineCode(node) {
+  var value = node.value;
+  var ticks = repeat('`', streak(value, '`') + 1);
+  var start = ticks;
+  var end = ticks;
+
+  if (value.charAt(0) === '`') {
+    start += ' ';
+  }
+
+  if (value.charAt(value.length - 1) === '`') {
+    end = ' ' + end;
+  }
+
+  return start + value + end;
+}