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.

get-syntax.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. "use strict";
  2. const path = require("path");
  3. const reSyntaxCSS = /^(?:post)?css$/i;
  4. function cssSyntax () {
  5. return {
  6. stringify: require("postcss/lib/stringify"),
  7. parse: require("postcss/lib/parse"),
  8. };
  9. }
  10. function normalize (syntax) {
  11. if (!syntax.parse) {
  12. syntax = {
  13. parse: syntax,
  14. };
  15. }
  16. return syntax;
  17. }
  18. function requireSyntax (syntax) {
  19. if (reSyntaxCSS.test(syntax)) {
  20. return cssSyntax();
  21. } else if (/^sugarss$/i.test(syntax)) {
  22. syntax = "sugarss";
  23. } else if (path.isAbsolute(syntax) || syntax[0] === ".") {
  24. syntax = path.resolve(syntax);
  25. } else {
  26. syntax = syntax.toLowerCase().replace(/^(?:postcss-)?(\w+)/i, "postcss-$1");
  27. }
  28. return normalize(require(syntax));
  29. }
  30. function getSyntax (lang, opts) {
  31. let syntax;
  32. lang = lang || "css";
  33. if (opts.syntax.config[lang]) {
  34. syntax = opts.syntax.config[lang];
  35. if (typeof syntax === "string") {
  36. if (syntax !== lang && opts.syntax.config[syntax]) {
  37. return getSyntax(syntax, opts);
  38. }
  39. syntax = requireSyntax(syntax);
  40. } else {
  41. syntax = normalize(syntax);
  42. }
  43. } else if (reSyntaxCSS.test(lang)) {
  44. syntax = cssSyntax();
  45. } else {
  46. return requireSyntax(lang);
  47. }
  48. if (!syntax.stringify) {
  49. if (reSyntaxCSS.test(lang)) {
  50. syntax.stringify = require("postcss/lib/stringify");
  51. } else {
  52. syntax.stringify = getSyntax(null, opts).stringify;
  53. }
  54. }
  55. opts.syntax.config[lang] = syntax;
  56. return syntax;
  57. }
  58. module.exports = getSyntax;