quotes.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.getQuote = exports.quotes = void 0;
  4. var parser_1 = require("../syntax/parser");
  5. exports.quotes = {
  6. name: 'quotes',
  7. initialValue: 'none',
  8. prefix: true,
  9. type: 1 /* LIST */,
  10. parse: function (_context, tokens) {
  11. if (tokens.length === 0) {
  12. return null;
  13. }
  14. var first = tokens[0];
  15. if (first.type === 20 /* IDENT_TOKEN */ && first.value === 'none') {
  16. return null;
  17. }
  18. var quotes = [];
  19. var filtered = tokens.filter(parser_1.isStringToken);
  20. if (filtered.length % 2 !== 0) {
  21. return null;
  22. }
  23. for (var i = 0; i < filtered.length; i += 2) {
  24. var open_1 = filtered[i].value;
  25. var close_1 = filtered[i + 1].value;
  26. quotes.push({ open: open_1, close: close_1 });
  27. }
  28. return quotes;
  29. }
  30. };
  31. var getQuote = function (quotes, depth, open) {
  32. if (!quotes) {
  33. return '';
  34. }
  35. var quote = quotes[Math.min(depth, quotes.length - 1)];
  36. if (!quote) {
  37. return '';
  38. }
  39. return open ? quote.open : quote.close;
  40. };
  41. exports.getQuote = getQuote;
  42. //# sourceMappingURL=quotes.js.map