.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / postcss-html / lib / markdown-parser.js
1 "use strict";
2
3 const remark = require("remark");
4 const findAllAfter = require("unist-util-find-all-after");
5
6 module.exports = function (source, opts) {
7         // Skip known non-markdown files.
8         if (opts.from && !/\.(?:md|markdown)(?:\?.+)?$/i.test(opts.from)) {
9                 return;
10         }
11         let isStructureMD = false;
12         const ast = remark().parse(source);
13         const blocks = findAllAfter(ast, 0, (node) => {
14                 if (node.type === "code" && node.lang) {
15                         isStructureMD = true;
16                         return /^(?:(?:[ps]?c)|le|wx|sa?|sugar)ss$/i.test(node.lang);
17                 }
18         });
19
20         if (!isStructureMD) {
21                 return;
22         }
23
24         return blocks.map((block) => {
25                 const startIndex = source.indexOf(block.value, block.position.start.offset);
26                 const content = source.slice(startIndex, block.position.end.offset).replace(/[ \t]*`*$/, "");
27                 return {
28                         startIndex: startIndex,
29                         lang: block.lang.toLowerCase(),
30                         isMarkdown: true,
31                         content: content,
32                 };
33         });
34 };