.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / remark-stringify / lib / visitors / inline-code.js
1 'use strict';
2
3 var streak = require('longest-streak');
4 var repeat = require('repeat-string');
5
6 module.exports = inlineCode;
7
8 /* Stringify inline code.
9  *
10  * Knows about internal ticks (`\``), and ensures one more
11  * tick is used to enclose the inline code:
12  *
13  *     ```foo ``bar`` baz```
14  *
15  * Even knows about inital and final ticks:
16  *
17  *     `` `foo ``
18  *     `` foo` ``
19  */
20 function inlineCode(node) {
21   var value = node.value;
22   var ticks = repeat('`', streak(value, '`') + 1);
23   var start = ticks;
24   var end = ticks;
25
26   if (value.charAt(0) === '`') {
27     start += ' ';
28   }
29
30   if (value.charAt(value.length - 1) === '`') {
31     end = ' ' + end;
32   }
33
34   return start + value + end;
35 }