quasar-ui-danx 0.4.99 → 0.5.1

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.
Files changed (90) hide show
  1. package/dist/danx.es.js +17884 -12732
  2. package/dist/danx.es.js.map +1 -1
  3. package/dist/danx.umd.js +192 -118
  4. package/dist/danx.umd.js.map +1 -1
  5. package/dist/style.css +1 -1
  6. package/package.json +11 -2
  7. package/scripts/publish.sh +76 -0
  8. package/src/components/Utility/Code/CodeViewer.vue +31 -14
  9. package/src/components/Utility/Code/CodeViewerCollapsed.vue +2 -0
  10. package/src/components/Utility/Code/CodeViewerFooter.vue +1 -1
  11. package/src/components/Utility/Code/LanguageBadge.vue +278 -5
  12. package/src/components/Utility/Code/MarkdownContent.vue +160 -6
  13. package/src/components/Utility/Code/index.ts +3 -0
  14. package/src/components/Utility/Markdown/ContextMenu.vue +314 -0
  15. package/src/components/Utility/Markdown/HotkeyHelpPopover.vue +259 -0
  16. package/src/components/Utility/Markdown/LineTypeMenu.vue +226 -0
  17. package/src/components/Utility/Markdown/LinkPopover.vue +331 -0
  18. package/src/components/Utility/Markdown/MarkdownEditor.vue +228 -0
  19. package/src/components/Utility/Markdown/MarkdownEditorContent.vue +235 -0
  20. package/src/components/Utility/Markdown/MarkdownEditorFooter.vue +50 -0
  21. package/src/components/Utility/Markdown/TablePopover.vue +420 -0
  22. package/src/components/Utility/Markdown/index.ts +11 -0
  23. package/src/components/Utility/Markdown/types.ts +27 -0
  24. package/src/components/Utility/index.ts +1 -0
  25. package/src/composables/index.ts +1 -0
  26. package/src/composables/markdown/features/useBlockquotes.spec.ts +428 -0
  27. package/src/composables/markdown/features/useBlockquotes.ts +248 -0
  28. package/src/composables/markdown/features/useCodeBlockManager.ts +369 -0
  29. package/src/composables/markdown/features/useCodeBlocks.spec.ts +779 -0
  30. package/src/composables/markdown/features/useCodeBlocks.ts +774 -0
  31. package/src/composables/markdown/features/useContextMenu.ts +444 -0
  32. package/src/composables/markdown/features/useFocusTracking.ts +116 -0
  33. package/src/composables/markdown/features/useHeadings.spec.ts +834 -0
  34. package/src/composables/markdown/features/useHeadings.ts +290 -0
  35. package/src/composables/markdown/features/useInlineFormatting.spec.ts +705 -0
  36. package/src/composables/markdown/features/useInlineFormatting.ts +402 -0
  37. package/src/composables/markdown/features/useLineTypeMenu.ts +285 -0
  38. package/src/composables/markdown/features/useLinks.spec.ts +369 -0
  39. package/src/composables/markdown/features/useLinks.ts +374 -0
  40. package/src/composables/markdown/features/useLists.spec.ts +834 -0
  41. package/src/composables/markdown/features/useLists.ts +747 -0
  42. package/src/composables/markdown/features/usePopoverManager.ts +181 -0
  43. package/src/composables/markdown/features/useTables.spec.ts +1601 -0
  44. package/src/composables/markdown/features/useTables.ts +1107 -0
  45. package/src/composables/markdown/index.ts +16 -0
  46. package/src/composables/markdown/useMarkdownEditor.spec.ts +332 -0
  47. package/src/composables/markdown/useMarkdownEditor.ts +1068 -0
  48. package/src/composables/markdown/useMarkdownHotkeys.spec.ts +791 -0
  49. package/src/composables/markdown/useMarkdownHotkeys.ts +266 -0
  50. package/src/composables/markdown/useMarkdownSelection.ts +219 -0
  51. package/src/composables/markdown/useMarkdownSync.ts +549 -0
  52. package/src/composables/useCodeViewerEditor.spec.ts +655 -0
  53. package/src/composables/useCodeViewerEditor.ts +174 -20
  54. package/src/helpers/formats/index.ts +1 -1
  55. package/src/helpers/formats/markdown/escapeHtml.ts +15 -0
  56. package/src/helpers/formats/markdown/escapeSequences.ts +60 -0
  57. package/src/helpers/formats/markdown/htmlToMarkdown/convertHeadings.ts +41 -0
  58. package/src/helpers/formats/markdown/htmlToMarkdown/index.spec.ts +489 -0
  59. package/src/helpers/formats/markdown/htmlToMarkdown/index.ts +412 -0
  60. package/src/helpers/formats/markdown/index.ts +92 -0
  61. package/src/helpers/formats/markdown/linePatterns.spec.ts +495 -0
  62. package/src/helpers/formats/markdown/linePatterns.ts +172 -0
  63. package/src/helpers/formats/markdown/parseInline.ts +124 -0
  64. package/src/helpers/formats/markdown/render/index.ts +92 -0
  65. package/src/helpers/formats/markdown/render/renderFootnotes.ts +30 -0
  66. package/src/helpers/formats/markdown/render/renderList.ts +69 -0
  67. package/src/helpers/formats/markdown/render/renderTable.ts +38 -0
  68. package/src/helpers/formats/markdown/state.ts +58 -0
  69. package/src/helpers/formats/markdown/tokenize/extractDefinitions.ts +39 -0
  70. package/src/helpers/formats/markdown/tokenize/index.ts +139 -0
  71. package/src/helpers/formats/markdown/tokenize/parseBlockquote.ts +34 -0
  72. package/src/helpers/formats/markdown/tokenize/parseCodeBlock.ts +85 -0
  73. package/src/helpers/formats/markdown/tokenize/parseDefinitionList.ts +88 -0
  74. package/src/helpers/formats/markdown/tokenize/parseHeading.ts +65 -0
  75. package/src/helpers/formats/markdown/tokenize/parseHorizontalRule.ts +22 -0
  76. package/src/helpers/formats/markdown/tokenize/parseList.ts +119 -0
  77. package/src/helpers/formats/markdown/tokenize/parseParagraph.ts +59 -0
  78. package/src/helpers/formats/markdown/tokenize/parseTable.ts +70 -0
  79. package/src/helpers/formats/markdown/tokenize/parseTaskList.ts +47 -0
  80. package/src/helpers/formats/markdown/tokenize/utils.ts +25 -0
  81. package/src/helpers/formats/markdown/types.ts +63 -0
  82. package/src/styles/danx.scss +1 -0
  83. package/src/styles/themes/danx/markdown.scss +96 -0
  84. package/src/test/helpers/editorTestUtils.spec.ts +296 -0
  85. package/src/test/helpers/editorTestUtils.ts +253 -0
  86. package/src/test/helpers/index.ts +1 -0
  87. package/src/test/setup.test.ts +12 -0
  88. package/src/test/setup.ts +12 -0
  89. package/vitest.config.ts +19 -0
  90. package/src/helpers/formats/renderMarkdown.ts +0 -338
@@ -1,338 +0,0 @@
1
- /**
2
- * Lightweight markdown to HTML renderer
3
- * Zero external dependencies, XSS-safe by default
4
- */
5
-
6
- export interface MarkdownRenderOptions {
7
- sanitize?: boolean; // XSS protection (default: true)
8
- }
9
-
10
- /**
11
- * Escape HTML entities to prevent XSS
12
- */
13
- function escapeHtml(text: string): string {
14
- return text
15
- .replace(/&/g, "&")
16
- .replace(/</g, "&lt;")
17
- .replace(/>/g, "&gt;")
18
- .replace(/"/g, "&quot;")
19
- .replace(/'/g, "&#039;");
20
- }
21
-
22
- /**
23
- * Token types for block-level parsing
24
- */
25
- export type BlockToken =
26
- | { type: "heading"; level: number; content: string }
27
- | { type: "code_block"; language: string; content: string }
28
- | { type: "blockquote"; content: string }
29
- | { type: "ul"; items: string[] }
30
- | { type: "ol"; items: string[]; start: number }
31
- | { type: "hr" }
32
- | { type: "paragraph"; content: string };
33
-
34
- /**
35
- * Parse inline markdown elements within text
36
- * Order matters: more specific patterns first
37
- */
38
- export function parseInline(text: string, sanitize: boolean = true): string {
39
- if (!text) return "";
40
-
41
- // Escape HTML if sanitizing (before applying markdown)
42
- let result = sanitize ? escapeHtml(text) : text;
43
-
44
- // Images: ![alt](url) - must be before links
45
- result = result.replace(
46
- /!\[([^\]]*)\]\(([^)]+)\)/g,
47
- '<img src="$2" alt="$1" />'
48
- );
49
-
50
- // Links: [text](url)
51
- result = result.replace(
52
- /\[([^\]]+)\]\(([^)]+)\)/g,
53
- '<a href="$2">$1</a>'
54
- );
55
-
56
- // Inline code: `code` (escape the content again if already escaped)
57
- result = result.replace(/`([^`]+)`/g, "<code>$1</code>");
58
-
59
- // Bold + Italic: ***text*** or ___text___
60
- result = result.replace(/\*\*\*([^*]+)\*\*\*/g, "<strong><em>$1</em></strong>");
61
- result = result.replace(/___([^_]+)___/g, "<strong><em>$1</em></strong>");
62
-
63
- // Bold: **text** or __text__
64
- result = result.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>");
65
- result = result.replace(/__([^_]+)__/g, "<strong>$1</strong>");
66
-
67
- // Italic: *text* or _text_ (but not inside words for underscores)
68
- // For asterisks, match any single asterisk pairs
69
- result = result.replace(/\*([^*]+)\*/g, "<em>$1</em>");
70
- // For underscores, only match at word boundaries
71
- result = result.replace(/(^|[^a-zA-Z0-9])_([^_]+)_([^a-zA-Z0-9]|$)/g, "$1<em>$2</em>$3");
72
-
73
- return result;
74
- }
75
-
76
- /**
77
- * Tokenize markdown into block-level elements
78
- */
79
- export function tokenizeBlocks(markdown: string): BlockToken[] {
80
- const tokens: BlockToken[] = [];
81
- const lines = markdown.split("\n");
82
- let i = 0;
83
-
84
- while (i < lines.length) {
85
- const line = lines[i];
86
- const trimmedLine = line.trim();
87
-
88
- // Skip empty lines between blocks
89
- if (!trimmedLine) {
90
- i++;
91
- continue;
92
- }
93
-
94
- // Code blocks: ```language ... ```
95
- if (trimmedLine.startsWith("```")) {
96
- const language = trimmedLine.slice(3).trim();
97
- const contentLines: string[] = [];
98
- i++;
99
-
100
- while (i < lines.length && !lines[i].trim().startsWith("```")) {
101
- contentLines.push(lines[i]);
102
- i++;
103
- }
104
-
105
- tokens.push({
106
- type: "code_block",
107
- language,
108
- content: contentLines.join("\n")
109
- });
110
-
111
- // Skip closing ```
112
- if (i < lines.length) i++;
113
- continue;
114
- }
115
-
116
- // Headings: # through ######
117
- const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
118
- if (headingMatch) {
119
- tokens.push({
120
- type: "heading",
121
- level: headingMatch[1].length,
122
- content: headingMatch[2]
123
- });
124
- i++;
125
- continue;
126
- }
127
-
128
- // Horizontal rules: ---, ***, ___
129
- if (/^(-{3,}|\*{3,}|_{3,})$/.test(trimmedLine)) {
130
- tokens.push({ type: "hr" });
131
- i++;
132
- continue;
133
- }
134
-
135
- // Blockquotes: > text
136
- if (trimmedLine.startsWith(">")) {
137
- const quoteLines: string[] = [];
138
-
139
- while (i < lines.length && lines[i].trim().startsWith(">")) {
140
- // Remove the leading > and optional space
141
- quoteLines.push(lines[i].trim().replace(/^>\s?/, ""));
142
- i++;
143
- }
144
-
145
- tokens.push({
146
- type: "blockquote",
147
- content: quoteLines.join("\n")
148
- });
149
- continue;
150
- }
151
-
152
- // Unordered lists: -, *, +
153
- if (/^[-*+]\s+/.test(trimmedLine)) {
154
- const items: string[] = [];
155
-
156
- while (i < lines.length) {
157
- const listLine = lines[i].trim();
158
- const listMatch = listLine.match(/^[-*+]\s+(.+)$/);
159
-
160
- if (listMatch) {
161
- items.push(listMatch[1]);
162
- i++;
163
- } else if (listLine === "") {
164
- // Empty line might end the list or just be spacing
165
- i++;
166
- // Check if next non-empty line continues the list
167
- const nextNonEmpty = lines.slice(i).find((l) => l.trim() !== "");
168
- if (!nextNonEmpty || !/^[-*+]\s+/.test(nextNonEmpty.trim())) {
169
- break;
170
- }
171
- } else {
172
- break;
173
- }
174
- }
175
-
176
- tokens.push({ type: "ul", items });
177
- continue;
178
- }
179
-
180
- // Ordered lists: 1., 2., etc.
181
- const orderedMatch = trimmedLine.match(/^(\d+)\.\s+(.+)$/);
182
- if (orderedMatch) {
183
- const items: string[] = [];
184
- const startNum = parseInt(orderedMatch[1], 10);
185
-
186
- while (i < lines.length) {
187
- const listLine = lines[i].trim();
188
- const listMatch = listLine.match(/^\d+\.\s+(.+)$/);
189
-
190
- if (listMatch) {
191
- items.push(listMatch[1]);
192
- i++;
193
- } else if (listLine === "") {
194
- i++;
195
- // Check if next non-empty line continues the list
196
- const nextNonEmpty = lines.slice(i).find((l) => l.trim() !== "");
197
- if (!nextNonEmpty || !/^\d+\.\s+/.test(nextNonEmpty.trim())) {
198
- break;
199
- }
200
- } else {
201
- break;
202
- }
203
- }
204
-
205
- tokens.push({ type: "ol", items, start: startNum });
206
- continue;
207
- }
208
-
209
- // Paragraph: collect consecutive non-empty lines
210
- const paragraphLines: string[] = [];
211
-
212
- while (i < lines.length) {
213
- const pLine = lines[i];
214
- const pTrimmed = pLine.trim();
215
-
216
- // Stop on empty line or block-level element
217
- if (!pTrimmed) {
218
- i++;
219
- break;
220
- }
221
-
222
- // Check for block-level starters
223
- if (
224
- pTrimmed.startsWith("#") ||
225
- pTrimmed.startsWith("```") ||
226
- pTrimmed.startsWith(">") ||
227
- /^[-*+]\s+/.test(pTrimmed) ||
228
- /^\d+\.\s+/.test(pTrimmed) ||
229
- /^(-{3,}|\*{3,}|_{3,})$/.test(pTrimmed)
230
- ) {
231
- break;
232
- }
233
-
234
- paragraphLines.push(pLine);
235
- i++;
236
- }
237
-
238
- if (paragraphLines.length > 0) {
239
- tokens.push({
240
- type: "paragraph",
241
- content: paragraphLines.join("\n")
242
- });
243
- }
244
- }
245
-
246
- return tokens;
247
- }
248
-
249
- /**
250
- * Render tokens to HTML
251
- */
252
- function renderTokens(tokens: BlockToken[], sanitize: boolean): string {
253
- const htmlParts: string[] = [];
254
-
255
- for (const token of tokens) {
256
- switch (token.type) {
257
- case "heading": {
258
- const content = parseInline(token.content, sanitize);
259
- htmlParts.push(`<h${token.level}>${content}</h${token.level}>`);
260
- break;
261
- }
262
-
263
- case "code_block": {
264
- // Always escape code block content for safety
265
- const escapedContent = escapeHtml(token.content);
266
- const langAttr = token.language ? ` class="language-${escapeHtml(token.language)}"` : "";
267
- htmlParts.push(`<pre><code${langAttr}>${escapedContent}</code></pre>`);
268
- break;
269
- }
270
-
271
- case "blockquote": {
272
- // Recursively parse blockquote content
273
- const innerTokens = tokenizeBlocks(token.content);
274
- const innerHtml = renderTokens(innerTokens, sanitize);
275
- htmlParts.push(`<blockquote>${innerHtml}</blockquote>`);
276
- break;
277
- }
278
-
279
- case "ul": {
280
- const items = token.items
281
- .map((item) => `<li>${parseInline(item, sanitize)}</li>`)
282
- .join("");
283
- htmlParts.push(`<ul>${items}</ul>`);
284
- break;
285
- }
286
-
287
- case "ol": {
288
- const items = token.items
289
- .map((item) => `<li>${parseInline(item, sanitize)}</li>`)
290
- .join("");
291
- const startAttr = token.start !== 1 ? ` start="${token.start}"` : "";
292
- htmlParts.push(`<ol${startAttr}>${items}</ol>`);
293
- break;
294
- }
295
-
296
- case "hr": {
297
- htmlParts.push("<hr />");
298
- break;
299
- }
300
-
301
- case "paragraph": {
302
- const content = parseInline(token.content, sanitize);
303
- // Convert single newlines to <br> within paragraphs
304
- const withBreaks = content.replace(/\n/g, "<br />");
305
- htmlParts.push(`<p>${withBreaks}</p>`);
306
- break;
307
- }
308
- }
309
- }
310
-
311
- return htmlParts.join("\n");
312
- }
313
-
314
- /**
315
- * Convert markdown text to HTML
316
- *
317
- * Supports:
318
- * - Headings (# through ######)
319
- * - Paragraphs (double newlines)
320
- * - Code blocks (```language ... ```)
321
- * - Blockquotes (> text)
322
- * - Unordered lists (-, *, +)
323
- * - Ordered lists (1., 2., etc.)
324
- * - Horizontal rules (---, ***, ___)
325
- * - Bold (**text** or __text__)
326
- * - Italic (*text* or _text_)
327
- * - Bold+Italic (***text***)
328
- * - Inline code (`code`)
329
- * - Links [text](url)
330
- * - Images ![alt](url)
331
- */
332
- export function renderMarkdown(markdown: string, options?: MarkdownRenderOptions): string {
333
- if (!markdown) return "";
334
-
335
- const sanitize = options?.sanitize ?? true;
336
- const tokens = tokenizeBlocks(markdown);
337
- return renderTokens(tokens, sanitize);
338
- }