@protomarkdown/parser 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -174,6 +174,15 @@ const code = generator.generate(nodes: MarkdownNode[]);
174
174
 
175
175
  **Returns:** Complete React component code as a string with necessary Shadcn UI imports
176
176
 
177
+ ### HtmlGenerator
178
+
179
+ ```ts
180
+ const generator = new HtmlGenerator();
181
+ const html = generator.generate(nodes: MarkdownNode[]);
182
+ ```
183
+
184
+ **Returns:** HTML string for VS Code extension preview rendering
185
+
177
186
  ## Examples
178
187
 
179
188
  ### Login Form
@@ -0,0 +1,35 @@
1
+ import { MarkdownNode } from "./parser/types";
2
+ /**
3
+ * Generates HTML from a Proto Markdown AST
4
+ * Used for VS Code extension preview rendering
5
+ */
6
+ export declare class HtmlGenerator {
7
+ /**
8
+ * Generate HTML from markdown AST
9
+ */
10
+ generate(nodes: MarkdownNode[]): string;
11
+ private renderNode;
12
+ private renderHeader;
13
+ private renderText;
14
+ private renderBold;
15
+ private renderItalic;
16
+ private renderInlineNodes;
17
+ private renderInlineNode;
18
+ private renderInput;
19
+ private renderTextarea;
20
+ private renderCheckbox;
21
+ private renderRadioGroup;
22
+ private renderDropdown;
23
+ private renderButton;
24
+ private renderCard;
25
+ private renderContainer;
26
+ private renderGrid;
27
+ private renderDiv;
28
+ private renderTable;
29
+ private renderImage;
30
+ private renderWorkflow;
31
+ private renderScreen;
32
+ private parseGridConfig;
33
+ private escapeHtml;
34
+ }
35
+ //# sourceMappingURL=HtmlGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HtmlGenerator.d.ts","sourceRoot":"","sources":["../src/HtmlGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,qBAAa,aAAa;IACxB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,MAAM;IAIvC,OAAO,CAAC,UAAU;IA2ClB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,YAAY;IAOpB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,gBAAgB;IAsBxB,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,cAAc;IAUtB,OAAO,CAAC,gBAAgB;IAoBxB,OAAO,CAAC,cAAc;IAYtB,OAAO,CAAC,YAAY;IAiBpB,OAAO,CAAC,UAAU;IAsBlB,OAAO,CAAC,eAAe;IAKvB,OAAO,CAAC,UAAU;IAMlB,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,WAAW;IAwBnB,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,cAAc;IA+BtB,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,eAAe;IAkBvB,OAAO,CAAC,UAAU;CAQnB"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { MarkdownParser } from "./parser";
2
2
  export type { MarkdownNode } from "./parser/types";
3
3
  export { ShadcnCodeGenerator } from "./ShadcnCodeGenerator";
4
+ export { HtmlGenerator } from "./HtmlGenerator";
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
package/dist/index.esm.js CHANGED
@@ -1003,5 +1003,270 @@ ${this.indent()}</div>`;
1003
1003
  }
1004
1004
  }
1005
1005
 
1006
- export { MarkdownParser, ShadcnCodeGenerator };
1006
+ /**
1007
+ * Generates HTML from a Proto Markdown AST
1008
+ * Used for VS Code extension preview rendering
1009
+ */
1010
+ class HtmlGenerator {
1011
+ /**
1012
+ * Generate HTML from markdown AST
1013
+ */
1014
+ generate(nodes) {
1015
+ return nodes.map((node) => this.renderNode(node)).join("\n");
1016
+ }
1017
+ renderNode(node) {
1018
+ switch (node.type) {
1019
+ case "header":
1020
+ return this.renderHeader(node);
1021
+ case "text":
1022
+ return this.renderText(node);
1023
+ case "bold":
1024
+ return this.renderBold(node);
1025
+ case "italic":
1026
+ return this.renderItalic(node);
1027
+ case "input":
1028
+ return this.renderInput(node);
1029
+ case "textarea":
1030
+ return this.renderTextarea(node);
1031
+ case "checkbox":
1032
+ return this.renderCheckbox(node);
1033
+ case "radiogroup":
1034
+ return this.renderRadioGroup(node);
1035
+ case "dropdown":
1036
+ return this.renderDropdown(node);
1037
+ case "button":
1038
+ return this.renderButton(node);
1039
+ case "card":
1040
+ return this.renderCard(node);
1041
+ case "container":
1042
+ return this.renderContainer(node);
1043
+ case "grid":
1044
+ return this.renderGrid(node);
1045
+ case "div":
1046
+ return this.renderDiv(node);
1047
+ case "table":
1048
+ return this.renderTable(node);
1049
+ case "image":
1050
+ return this.renderImage(node);
1051
+ case "workflow":
1052
+ return this.renderWorkflow(node);
1053
+ case "screen":
1054
+ return this.renderScreen(node);
1055
+ default:
1056
+ return `<div class="proto-unknown">${JSON.stringify(node)}</div>`;
1057
+ }
1058
+ }
1059
+ renderHeader(node) {
1060
+ const level = node.level || 1;
1061
+ let content;
1062
+ if (node.children && node.children.length > 0) {
1063
+ content = this.renderInlineNodes(node.children);
1064
+ }
1065
+ else {
1066
+ content = this.escapeHtml(node.content || "");
1067
+ }
1068
+ return `<h${level} class="proto-header">${content}</h${level}>`;
1069
+ }
1070
+ renderText(node) {
1071
+ if (node.children && node.children.length > 0) {
1072
+ const content = this.renderInlineNodes(node.children);
1073
+ return `<p class="proto-text">${content}</p>`;
1074
+ }
1075
+ return `<p class="proto-text">${this.escapeHtml(node.content || "")}</p>`;
1076
+ }
1077
+ renderBold(node) {
1078
+ if (node.children && node.children.length > 0) {
1079
+ return `<strong>${this.renderInlineNodes(node.children)}</strong>`;
1080
+ }
1081
+ return `<strong>${this.escapeHtml(node.content || "")}</strong>`;
1082
+ }
1083
+ renderItalic(node) {
1084
+ if (node.children && node.children.length > 0) {
1085
+ return `<em>${this.renderInlineNodes(node.children)}</em>`;
1086
+ }
1087
+ return `<em>${this.escapeHtml(node.content || "")}</em>`;
1088
+ }
1089
+ renderInlineNodes(nodes) {
1090
+ return nodes.map((node) => this.renderInlineNode(node)).join("");
1091
+ }
1092
+ renderInlineNode(node) {
1093
+ switch (node.type) {
1094
+ case "bold":
1095
+ if (node.children && node.children.length > 0) {
1096
+ return `<strong>${this.renderInlineNodes(node.children)}</strong>`;
1097
+ }
1098
+ return `<strong>${this.escapeHtml(node.content || "")}</strong>`;
1099
+ case "italic":
1100
+ if (node.children && node.children.length > 0) {
1101
+ return `<em>${this.renderInlineNodes(node.children)}</em>`;
1102
+ }
1103
+ return `<em>${this.escapeHtml(node.content || "")}</em>`;
1104
+ case "text":
1105
+ if (node.children && node.children.length > 0) {
1106
+ return this.renderInlineNodes(node.children);
1107
+ }
1108
+ return this.escapeHtml(node.content || "");
1109
+ default:
1110
+ return this.escapeHtml(node.content || "");
1111
+ }
1112
+ }
1113
+ renderInput(node) {
1114
+ const placeholder = node.inputType === "password" ? "••••••••" : "";
1115
+ return `
1116
+ <div class="proto-field">
1117
+ <label class="proto-label">${this.escapeHtml(node.label || "")}</label>
1118
+ <input type="${node.inputType || "text"}" class="proto-input" placeholder="${placeholder}" disabled />
1119
+ </div>`;
1120
+ }
1121
+ renderTextarea(node) {
1122
+ return `
1123
+ <div class="proto-field">
1124
+ <label class="proto-label">${this.escapeHtml(node.label || "")}</label>
1125
+ <textarea class="proto-textarea" disabled></textarea>
1126
+ </div>`;
1127
+ }
1128
+ renderCheckbox(node) {
1129
+ return `
1130
+ <div class="proto-checkbox">
1131
+ <input type="checkbox" class="proto-checkbox-input" disabled />
1132
+ <label class="proto-checkbox-label">${this.escapeHtml(node.label || "")}</label>
1133
+ </div>`;
1134
+ }
1135
+ renderRadioGroup(node) {
1136
+ const options = (node.options || [])
1137
+ .map((opt) => `
1138
+ <div class="proto-radio-option">
1139
+ <input type="radio" class="proto-radio-input" name="${this.escapeHtml(node.label || "")}" disabled />
1140
+ <label class="proto-radio-label">${this.escapeHtml(opt)}</label>
1141
+ </div>`)
1142
+ .join("");
1143
+ return `
1144
+ <div class="proto-radiogroup">
1145
+ <label class="proto-label">${this.escapeHtml(node.label || "")}</label>
1146
+ <div class="proto-radio-options">${options}</div>
1147
+ </div>`;
1148
+ }
1149
+ renderDropdown(node) {
1150
+ const options = (node.options || ["Select an option"])
1151
+ .map((opt) => `<option>${this.escapeHtml(opt)}</option>`)
1152
+ .join("");
1153
+ return `
1154
+ <div class="proto-field">
1155
+ <label class="proto-label">${this.escapeHtml(node.label || "")}</label>
1156
+ <select class="proto-select" disabled>${options}</select>
1157
+ </div>`;
1158
+ }
1159
+ renderButton(node) {
1160
+ const btnClass = node.variant === "default"
1161
+ ? "proto-button-default"
1162
+ : "proto-button-outline";
1163
+ const navIndicator = node.navigateTo
1164
+ ? ` <span class="proto-nav-indicator">→ ${this.escapeHtml(node.navigateTo)}</span>`
1165
+ : "";
1166
+ return `<button class="proto-button ${btnClass}" disabled>${this.escapeHtml(node.content || "")}${navIndicator}</button>`;
1167
+ }
1168
+ renderCard(node) {
1169
+ let cardTitle = "";
1170
+ if (node.titleChildren && node.titleChildren.length > 0) {
1171
+ cardTitle = `<div class="proto-card-header">${this.renderInlineNodes(node.titleChildren)}</div>`;
1172
+ }
1173
+ else if (node.title) {
1174
+ cardTitle = `<div class="proto-card-header">${this.escapeHtml(node.title)}</div>`;
1175
+ }
1176
+ const cardChildren = node.children ? this.generate(node.children) : "";
1177
+ return `
1178
+ <div class="proto-card">
1179
+ ${cardTitle}
1180
+ <div class="proto-card-content">${cardChildren}</div>
1181
+ </div>`;
1182
+ }
1183
+ renderContainer(node) {
1184
+ const children = node.children ? this.generate(node.children) : "";
1185
+ return `<div class="proto-container">${children}</div>`;
1186
+ }
1187
+ renderGrid(node) {
1188
+ const children = node.children ? this.generate(node.children) : "";
1189
+ const gridConfig = this.parseGridConfig(node.gridConfig || "");
1190
+ return `<div class="proto-grid" style="${gridConfig}">${children}</div>`;
1191
+ }
1192
+ renderDiv(node) {
1193
+ const children = node.children ? this.generate(node.children) : "";
1194
+ return `<div class="proto-div ${this.escapeHtml(node.className || "")}">${children}</div>`;
1195
+ }
1196
+ renderTable(node) {
1197
+ const headerCells = (node.headers || [])
1198
+ .map((h) => `<th class="proto-table-th">${this.escapeHtml(h)}</th>`)
1199
+ .join("");
1200
+ const bodyRows = (node.rows || [])
1201
+ .map((row) => `<tr>${row
1202
+ .map((cell) => `<td class="proto-table-td">${this.escapeHtml(cell)}</td>`)
1203
+ .join("")}</tr>`)
1204
+ .join("");
1205
+ return `
1206
+ <table class="proto-table">
1207
+ <thead><tr>${headerCells}</tr></thead>
1208
+ <tbody>${bodyRows}</tbody>
1209
+ </table>`;
1210
+ }
1211
+ renderImage(node) {
1212
+ return `<img class="proto-image" src="${this.escapeHtml(node.src || "")}" alt="${this.escapeHtml(node.alt || "")}" />`;
1213
+ }
1214
+ renderWorkflow(node) {
1215
+ const screens = (node.children || [])
1216
+ .map((screen, idx) => {
1217
+ const isInitial = screen.id === node.initialScreen || idx === 0;
1218
+ const screenContent = screen.children
1219
+ ? this.generate(screen.children)
1220
+ : "";
1221
+ const screenId = screen.id || "";
1222
+ return `
1223
+ <div class="proto-screen${isInitial ? " proto-screen-active" : ""}" data-screen-id="${this.escapeHtml(screenId)}">
1224
+ <div class="proto-screen-header">
1225
+ <span class="proto-screen-badge">${this.escapeHtml(screenId)}</span>
1226
+ ${isInitial
1227
+ ? '<span class="proto-screen-initial">Initial</span>'
1228
+ : ""}
1229
+ </div>
1230
+ <div class="proto-screen-content">${screenContent}</div>
1231
+ </div>`;
1232
+ })
1233
+ .join("");
1234
+ return `<div class="proto-workflow">${screens}</div>`;
1235
+ }
1236
+ renderScreen(node) {
1237
+ const screenChildren = node.children ? this.generate(node.children) : "";
1238
+ const screenId = node.id || "";
1239
+ return `
1240
+ <div class="proto-screen" data-screen-id="${this.escapeHtml(screenId)}">
1241
+ <div class="proto-screen-header">
1242
+ <span class="proto-screen-badge">${this.escapeHtml(screenId)}</span>
1243
+ </div>
1244
+ <div class="proto-screen-content">${screenChildren}</div>
1245
+ </div>`;
1246
+ }
1247
+ parseGridConfig(config) {
1248
+ const styles = [];
1249
+ // Parse cols-N
1250
+ const colsMatch = config.match(/cols-(\d+)/);
1251
+ if (colsMatch) {
1252
+ styles.push(`grid-template-columns: repeat(${colsMatch[1]}, 1fr)`);
1253
+ }
1254
+ // Parse gap-N
1255
+ const gapMatch = config.match(/gap-(\d+)/);
1256
+ if (gapMatch) {
1257
+ styles.push(`gap: ${parseInt(gapMatch[1]) * 4}px`);
1258
+ }
1259
+ return styles.join("; ");
1260
+ }
1261
+ escapeHtml(text) {
1262
+ return text
1263
+ .replace(/&/g, "&amp;")
1264
+ .replace(/</g, "&lt;")
1265
+ .replace(/>/g, "&gt;")
1266
+ .replace(/"/g, "&quot;")
1267
+ .replace(/'/g, "&#039;");
1268
+ }
1269
+ }
1270
+
1271
+ export { HtmlGenerator, MarkdownParser, ShadcnCodeGenerator };
1007
1272
  //# sourceMappingURL=index.esm.js.map