Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extract.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. const remark = require("remark");
  3. const findAllAfter = require("unist-util-find-all-after");
  4. function mdParser (source, opts, result) {
  5. const htmlInMd = opts.syntax.config.htmlInMd;
  6. if (!result && (htmlInMd == null || htmlInMd)) {
  7. result = require("postcss-html/extract")(source, opts, []);
  8. }
  9. const ast = remark().parse(source);
  10. const blocks = findAllAfter(ast, 0, (node) => (
  11. node.type === "code"
  12. )).map((block) => {
  13. if (result && (!block.lang || !/^(?:[sx]?html?|[sx]ht)$/i.test(block.lang))) {
  14. result = result.filter(styleHtm => {
  15. return styleHtm.startIndex >= block.position.end.offset ||
  16. styleHtm.startIndex + styleHtm.content.length <= block.position.start.offset;
  17. });
  18. }
  19. if (block.lang && /^(?:(?:\w*c)|le|wx|sa?|sugar)ss$/i.test(block.lang)) {
  20. let startIndex = source.indexOf(block.lang, block.position.start.offset) + block.lang.length;
  21. if (block.value) {
  22. startIndex = source.indexOf(block.value, startIndex);
  23. } else {
  24. startIndex = source.indexOf("\n", startIndex) + 1;
  25. }
  26. return {
  27. startIndex: startIndex,
  28. lang: block.lang.toLowerCase(),
  29. isMarkdown: true,
  30. content: source.slice(startIndex, block.position.end.offset).replace(/[ \t]*`*$/, ""),
  31. };
  32. }
  33. }).filter(Boolean);
  34. if (result) {
  35. return result.concat(blocks);
  36. } else {
  37. return blocks;
  38. }
  39. };
  40. module.exports = mdParser;