UNPKG

@ethan-jones-vizio/sveld

Version:

Generate TypeScript definitions for your Svelte components.

92 lines (91 loc) 3.47 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; exports.__esModule = true; var Writer_1 = __importDefault(require("./Writer")); var WriterMarkdown = /** @class */ (function (_super) { __extends(WriterMarkdown, _super); function WriterMarkdown(options) { var _this = _super.call(this, { parser: "markdown", printWidth: 80 }) || this; _this.source = ""; _this.hasToC = false; _this.toc = []; _this.onAppend = options.onAppend; return _this; } WriterMarkdown.prototype.appendLineBreaks = function () { this.source += "\n\n"; return this; }; WriterMarkdown.prototype.append = function (type, raw) { var _a; switch (type) { case "h1": case "h2": case "h3": case "h4": case "h5": case "h6": var length_1 = Number(type.slice(-1)); this.source += "".concat(Array.from({ length: length_1 }) .map(function (_) { return "#"; }) .join(""), " ").concat(raw); if (this.hasToC && type === "h2") { this.toc.push({ array: Array.from({ length: (length_1 - 1) * 2 }), raw: raw }); } break; case "quote": this.source += "> ".concat(raw); break; case "p": this.source += raw; break; case "divider": this.source += "---"; break; case "raw": this.source += raw; break; } if (type !== "raw") this.appendLineBreaks(); (_a = this.onAppend) === null || _a === void 0 ? void 0 : _a.call(this, type, this); return this; }; WriterMarkdown.prototype.tableOfContents = function () { this.source += "<!-- __TOC__ -->"; this.hasToC = true; this.appendLineBreaks(); return this; }; WriterMarkdown.prototype.end = function () { this.source = this.source.replace("<!-- __TOC__ -->", this.toc .map(function (_a) { var array = _a.array, raw = _a.raw; return "".concat(array.join(" "), " - [").concat(raw, "](#").concat(raw.toLowerCase().replace(/\`/g, "").replace(/\s+/g, "-"), ")"); }) .join("\n")); return this.source; }; return WriterMarkdown; }(Writer_1["default"])); exports["default"] = WriterMarkdown;