@diegopluna/narvi 0.1.0 → 0.2.0
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 +102 -41
- package/dist/base.css +2 -2
- package/dist/color.d.ts +1 -1
- package/dist/color.js +1 -1
- package/dist/components/activity/ActivityContent.svelte +3 -15
- package/dist/components/activity/ActivityStep.svelte +12 -12
- package/dist/components/activity/ActivityThought.svelte +4 -4
- package/dist/components/activity/ActivityTrigger.svelte +3 -3
- package/dist/components/app-shell/AppShellBar.svelte +89 -0
- package/dist/components/app-shell/AppShellBar.svelte.d.ts +20 -0
- package/dist/components/app-shell/AppShellHeader.svelte +17 -16
- package/dist/components/app-shell/AppShellHeader.svelte.d.ts +2 -2
- package/dist/components/app-shell/AppShellMain.svelte +4 -20
- package/dist/components/app-shell/AppShellPanel.svelte +21 -19
- package/dist/components/app-shell/AppShellPanes.svelte +58 -0
- package/dist/components/app-shell/AppShellPanes.svelte.d.ts +11 -0
- package/dist/components/app-shell/AppShellRail.svelte +85 -0
- package/dist/components/app-shell/AppShellRail.svelte.d.ts +11 -0
- package/dist/components/app-shell/AppShellRoot.svelte +50 -24
- package/dist/components/app-shell/AppShellRoot.svelte.d.ts +8 -6
- package/dist/components/app-shell/AppShellSheet.svelte +95 -0
- package/dist/components/app-shell/AppShellSheet.svelte.d.ts +17 -0
- package/dist/components/app-shell/AppShellSidebar.svelte +37 -61
- package/dist/components/app-shell/AppShellSidebar.svelte.d.ts +1 -5
- package/dist/components/app-shell/AppShellToggle.svelte +62 -23
- package/dist/components/app-shell/AppShellToggle.svelte.d.ts +2 -0
- package/dist/components/app-shell/context.d.ts +6 -0
- package/dist/components/app-shell/index.d.ts +9 -1
- package/dist/components/app-shell/index.js +5 -1
- package/dist/components/approval/Approval.svelte +91 -19
- package/dist/components/approval/Approval.svelte.d.ts +7 -0
- package/dist/components/avatar/AvatarFallback.svelte +1 -2
- package/dist/components/avatar/AvatarRoot.svelte +2 -2
- package/dist/components/badge/Badge.svelte +5 -5
- package/dist/components/button/Button.svelte +219 -40
- package/dist/components/button/Button.svelte.d.ts +38 -2
- package/dist/components/card/Card.svelte +15 -26
- package/dist/components/change-stats/ChangeStats.svelte +1 -2
- package/dist/components/changes-summary/ChangesSummary.svelte +14 -15
- package/dist/components/checkbox/Checkbox.svelte +18 -15
- package/dist/components/checkbox/Checkbox.svelte.d.ts +5 -0
- package/dist/components/code/Code.svelte +1 -2
- package/dist/components/collapsible/CollapsibleTrigger.svelte +2 -2
- package/dist/components/command/CommandItem.svelte +1 -1
- package/dist/components/command/styles.d.ts +3 -2
- package/dist/components/command/styles.js +13 -10
- package/dist/components/composer/ComposerAttachButton.svelte +1 -1
- package/dist/components/composer/ComposerAttachment.svelte +9 -12
- package/dist/components/composer/ComposerModelPicker.svelte +18 -20
- package/dist/components/composer/ComposerRoot.svelte +8 -7
- package/dist/components/composer/ComposerSubmit.svelte +8 -15
- package/dist/components/composer/ComposerTextarea.svelte +1 -1
- package/dist/components/composer/ComposerToggle.svelte +9 -11
- package/dist/components/composer/ComposerTray.svelte +78 -0
- package/dist/components/composer/ComposerTray.svelte.d.ts +15 -0
- package/dist/components/composer/index.d.ts +3 -1
- package/dist/components/composer/index.js +3 -2
- package/dist/components/conversation/ConversationContent.svelte +3 -2
- package/dist/components/conversation/ConversationEmpty.svelte +1 -1
- package/dist/components/conversation/ConversationScrollButton.svelte +3 -3
- package/dist/components/dialog/ConfirmDialog.svelte +1 -1
- package/dist/components/dialog/styles.d.ts +2 -3
- package/dist/components/dialog/styles.js +5 -6
- package/dist/components/divider/Divider.svelte +3 -3
- package/dist/components/empty-state/EmptyState.svelte +4 -5
- package/dist/components/field/Field.svelte +4 -4
- package/dist/components/frame/Frame.svelte +6 -7
- package/dist/components/frame/Frame.svelte.d.ts +1 -1
- package/dist/components/heading/Heading.svelte +2 -2
- package/dist/components/kbd/Kbd.svelte +12 -7
- package/dist/components/link/Link.svelte +7 -3
- package/dist/components/link/Link.svelte.d.ts +4 -1
- package/dist/components/markdown/Markdown.svelte +714 -0
- package/dist/components/markdown/Markdown.svelte.d.ts +80 -0
- package/dist/components/markdown/MarkdownBlock.svelte +231 -0
- package/dist/components/markdown/MarkdownBlock.svelte.d.ts +11 -0
- package/dist/components/markdown/MarkdownBlocks.svelte +115 -0
- package/dist/components/markdown/MarkdownBlocks.svelte.d.ts +15 -0
- package/dist/components/markdown/MarkdownCode.svelte +583 -0
- package/dist/components/markdown/MarkdownCode.svelte.d.ts +23 -0
- package/dist/components/markdown/MarkdownDiagram.svelte +310 -0
- package/dist/components/markdown/MarkdownDiagram.svelte.d.ts +6 -0
- package/dist/components/markdown/MarkdownFile.svelte +134 -0
- package/dist/components/markdown/MarkdownFile.svelte.d.ts +19 -0
- package/dist/components/markdown/MarkdownFootnotes.svelte +61 -0
- package/dist/components/markdown/MarkdownFootnotes.svelte.d.ts +8 -0
- package/dist/components/markdown/MarkdownFresh.svelte +69 -0
- package/dist/components/markdown/MarkdownFresh.svelte.d.ts +6 -0
- package/dist/components/markdown/MarkdownHtml.svelte +72 -0
- package/dist/components/markdown/MarkdownHtml.svelte.d.ts +7 -0
- package/dist/components/markdown/MarkdownImage.svelte +150 -0
- package/dist/components/markdown/MarkdownImage.svelte.d.ts +8 -0
- package/dist/components/markdown/MarkdownInlines.svelte +225 -0
- package/dist/components/markdown/MarkdownInlines.svelte.d.ts +7 -0
- package/dist/components/markdown/MarkdownLink.svelte +120 -0
- package/dist/components/markdown/MarkdownLink.svelte.d.ts +25 -0
- package/dist/components/markdown/MarkdownMath.svelte +138 -0
- package/dist/components/markdown/MarkdownMath.svelte.d.ts +7 -0
- package/dist/components/markdown/MarkdownTable.svelte +265 -0
- package/dist/components/markdown/MarkdownTable.svelte.d.ts +17 -0
- package/dist/components/markdown/caret.d.ts +14 -0
- package/dist/components/markdown/caret.js +67 -0
- package/dist/components/markdown/context.d.ts +93 -0
- package/dist/components/markdown/context.js +128 -0
- package/dist/components/markdown/copy.d.ts +13 -0
- package/dist/components/markdown/copy.js +74 -0
- package/dist/components/markdown/hidden.d.ts +12 -0
- package/dist/components/markdown/hidden.js +31 -0
- package/dist/components/markdown/kept.d.ts +32 -0
- package/dist/components/markdown/kept.js +71 -0
- package/dist/components/markdown/labels.d.ts +46 -0
- package/dist/components/markdown/labels.js +35 -0
- package/dist/components/markdown/save.d.ts +11 -0
- package/dist/components/markdown/save.js +58 -0
- package/dist/components/markdown/scrollable.d.ts +24 -0
- package/dist/components/markdown/scrollable.js +152 -0
- package/dist/components/markdown/static.d.ts +37 -0
- package/dist/components/markdown/static.js +233 -0
- package/dist/components/markdown/styles.d.ts +328 -0
- package/dist/components/markdown/styles.js +302 -0
- package/dist/components/menu/MenuRadioItem.svelte +3 -3
- package/dist/components/menu/index.d.ts +23 -0
- package/dist/components/menu/index.js +3 -1
- package/dist/components/message/MessageAction.svelte +22 -2
- package/dist/components/message/MessageAction.svelte.d.ts +9 -0
- package/dist/components/message/MessageContent.svelte +2 -3
- package/dist/components/message/MessageCopy.svelte +62 -3
- package/dist/components/message/MessageCopy.svelte.d.ts +17 -1
- package/dist/components/message/MessageHeader.svelte +3 -3
- package/dist/components/message/MessagePending.svelte +1 -1
- package/dist/components/message/MessageTime.svelte +1 -1
- package/dist/components/notice/Notice.svelte +14 -10
- package/dist/components/plan/Plan.svelte +22 -17
- package/dist/components/progress/Progress.svelte +31 -33
- package/dist/components/questionnaire/Questionnaire.svelte +19 -22
- package/dist/components/queued-message/QueuedMessage.svelte +14 -7
- package/dist/components/rail/RailItem.svelte +37 -34
- package/dist/components/rail/RailItem.svelte.d.ts +3 -1
- package/dist/components/rail/RailRoot.svelte +18 -4
- package/dist/components/rail/RailRoot.svelte.d.ts +1 -1
- package/dist/components/rail/RailSeparator.svelte +17 -0
- package/dist/components/rail/RailSeparator.svelte.d.ts +18 -0
- package/dist/components/rail/index.d.ts +2 -1
- package/dist/components/rail/index.js +2 -1
- package/dist/components/reasoning/ReasoningContent.svelte +4 -8
- package/dist/components/reasoning/ReasoningTrigger.svelte +2 -2
- package/dist/components/resize-handle/ResizeHandle.svelte +2 -3
- package/dist/components/segmented/SegmentedControl.svelte +7 -8
- package/dist/components/select/Select.svelte +1 -1
- package/dist/components/separator/Separator.svelte +1 -1
- package/dist/components/settings-row/SettingsRow.svelte +5 -5
- package/dist/components/shimmer/Shimmer.svelte +34 -21
- package/dist/components/sidebar/SidebarContent.svelte +1 -1
- package/dist/components/sidebar/SidebarFolder.svelte +142 -0
- package/dist/components/sidebar/SidebarFolder.svelte.d.ts +19 -0
- package/dist/components/sidebar/SidebarFooter.svelte +1 -1
- package/dist/components/sidebar/SidebarGroup.svelte +36 -32
- package/dist/components/sidebar/SidebarGroup.svelte.d.ts +3 -3
- package/dist/components/sidebar/SidebarHeader.svelte +12 -6
- package/dist/components/sidebar/SidebarHeader.svelte.d.ts +4 -1
- package/dist/components/sidebar/SidebarItem.svelte +26 -32
- package/dist/components/sidebar/SidebarRoot.svelte +62 -0
- package/dist/components/sidebar/SidebarRoot.svelte.d.ts +14 -0
- package/dist/components/sidebar/index.d.ts +5 -1
- package/dist/components/sidebar/index.js +3 -1
- package/dist/components/skeleton/Skeleton.svelte +26 -15
- package/dist/components/slider/Slider.svelte +11 -10
- package/dist/components/spinner/Spinner.svelte +4 -11
- package/dist/components/status-indicator/StatusIndicator.svelte +1 -1
- package/dist/components/suggestions/SuggestionsItem.svelte +5 -5
- package/dist/components/switch/Switch.svelte +9 -14
- package/dist/components/tab-strip/TabStrip.svelte +340 -0
- package/dist/components/tab-strip/TabStrip.svelte.d.ts +31 -0
- package/dist/components/tabs/Tabs.svelte +13 -9
- package/dist/components/tabs/Tabs.svelte.d.ts +4 -0
- package/dist/components/text/Text.svelte +31 -23
- package/dist/components/text/Text.svelte.d.ts +8 -4
- package/dist/components/toast/Toaster.svelte +5 -5
- package/dist/components/tool/ToolContent.svelte +3 -8
- package/dist/components/tool/ToolSection.svelte +4 -5
- package/dist/components/tool/ToolTrigger.svelte +10 -9
- package/dist/components/tooltip/TooltipContent.svelte +3 -3
- package/dist/components/work-fold/WorkFold.svelte +5 -9
- package/dist/index.d.ts +16 -8
- package/dist/index.js +17 -10
- package/dist/internal/Code.svelte +3 -4
- package/dist/internal/Glyph.svelte +16 -0
- package/dist/internal/Glyph.svelte.d.ts +6 -0
- package/dist/internal/Tile.svelte +17 -37
- package/dist/internal/control.d.ts +4 -4
- package/dist/internal/control.js +20 -17
- package/dist/internal/layer.d.ts +3 -5
- package/dist/internal/layer.js +10 -12
- package/dist/internal/markers.stylex.d.ts +8 -0
- package/dist/internal/markers.stylex.js +4 -0
- package/dist/internal/plugin-order.d.ts +8 -0
- package/dist/internal/plugin-order.js +16 -0
- package/dist/internal/roving.js +5 -2
- package/dist/internal/shared.d.ts +8 -1
- package/dist/internal/shared.js +21 -5
- package/dist/internal/sx.d.ts +1 -1
- package/dist/internal/toggle.d.ts +1 -2
- package/dist/internal/toggle.js +8 -12
- package/dist/internal/visible.d.ts +32 -0
- package/dist/internal/visible.js +44 -0
- package/dist/markdown/ast.d.ts +209 -0
- package/dist/markdown/ast.js +10 -0
- package/dist/markdown/blocks.d.ts +177 -0
- package/dist/markdown/blocks.js +1489 -0
- package/dist/markdown/code-info.d.ts +10 -0
- package/dist/markdown/code-info.js +16 -0
- package/dist/markdown/common.d.ts +25 -0
- package/dist/markdown/common.js +107 -0
- package/dist/markdown/diagrams.d.ts +2 -0
- package/dist/markdown/diagrams.js +18 -0
- package/dist/markdown/file-paths.d.ts +29 -0
- package/dist/markdown/file-paths.js +80 -0
- package/dist/markdown/files.d.ts +16 -0
- package/dist/markdown/files.js +133 -0
- package/dist/markdown/highlight.d.ts +30 -0
- package/dist/markdown/highlight.js +127 -0
- package/dist/markdown/html.d.ts +23 -0
- package/dist/markdown/html.js +289 -0
- package/dist/markdown/images.d.ts +15 -0
- package/dist/markdown/images.js +45 -0
- package/dist/markdown/index.d.ts +12 -0
- package/dist/markdown/index.js +5 -0
- package/dist/markdown/inlines.d.ts +48 -0
- package/dist/markdown/inlines.js +1714 -0
- package/dist/markdown/math.d.ts +2 -0
- package/dist/markdown/math.js +22 -0
- package/dist/markdown/parse.d.ts +81 -0
- package/dist/markdown/parse.js +204 -0
- package/dist/markdown/plugin.d.ts +178 -0
- package/dist/markdown/plugin.js +160 -0
- package/dist/markdown/sanitize.d.ts +78 -0
- package/dist/markdown/sanitize.js +522 -0
- package/dist/markdown/share.d.ts +12 -0
- package/dist/markdown/share.js +59 -0
- package/dist/markdown/table.d.ts +13 -0
- package/dist/markdown/table.js +60 -0
- package/dist/preset.d.ts +40 -16
- package/dist/preset.js +169 -51
- package/dist/tokens.stylex.d.ts +55 -37
- package/dist/tokens.stylex.js +107 -62
- package/dist/typography.d.ts +48 -0
- package/dist/typography.js +55 -0
- package/dist/vite.d.ts +7 -1
- package/dist/vite.js +27 -2
- package/package.json +53 -6
- package/skills/building-ui/SKILL.md +242 -0
- package/skills/building-ui/references/components.md +207 -0
- package/skills/markdown/SKILL.md +452 -0
- package/skills/markdown/references/plugins.md +103 -0
- package/skills/setup/SKILL.md +191 -0
- package/skills/styling/SKILL.md +269 -0
- package/skills/theming/SKILL.md +184 -0
- package/dist/internal/loop.d.ts +0 -35
- package/dist/internal/loop.js +0 -72
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { defaultLinkPolicy } from './plugin.js';
|
|
2
|
+
const reUnsafe = /[&<>"]/g;
|
|
3
|
+
const replacements = {
|
|
4
|
+
'&': '&',
|
|
5
|
+
'<': '<',
|
|
6
|
+
'>': '>',
|
|
7
|
+
'"': '"'
|
|
8
|
+
};
|
|
9
|
+
export function escapeHtml(s) {
|
|
10
|
+
return s.replace(reUnsafe, (c) => replacements[c]);
|
|
11
|
+
}
|
|
12
|
+
const reTagFilter = /<(?=\/?(?:title|textarea|style|xmp|iframe|noembed|noframes|script|plaintext)\b)/gi;
|
|
13
|
+
class Writer {
|
|
14
|
+
options;
|
|
15
|
+
// Pieces, joined at the end. One growing string would be searched from its start each
|
|
16
|
+
// time a line ending is asked about, and a document of many blocks would crawl.
|
|
17
|
+
parts = [];
|
|
18
|
+
last = '';
|
|
19
|
+
get out() {
|
|
20
|
+
return this.parts.join('');
|
|
21
|
+
}
|
|
22
|
+
write(s) {
|
|
23
|
+
if (s === '')
|
|
24
|
+
return;
|
|
25
|
+
this.parts.push(s);
|
|
26
|
+
this.last = s;
|
|
27
|
+
}
|
|
28
|
+
footnoteOrder = new Map();
|
|
29
|
+
footnoteUses = new Map();
|
|
30
|
+
defined = new Set();
|
|
31
|
+
constructor(options) {
|
|
32
|
+
this.options = options;
|
|
33
|
+
}
|
|
34
|
+
cr() {
|
|
35
|
+
if (this.parts.length > 0 && !this.last.endsWith('\n'))
|
|
36
|
+
this.write('\n');
|
|
37
|
+
}
|
|
38
|
+
raw(s) {
|
|
39
|
+
if (!this.options.rawHtml) {
|
|
40
|
+
this.write(escapeHtml(s));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
this.write(this.options.tagFilter ? s.replace(reTagFilter, '<') : s);
|
|
44
|
+
}
|
|
45
|
+
blocks(blocks, tight = false) {
|
|
46
|
+
for (const block of blocks)
|
|
47
|
+
this.block(block, tight);
|
|
48
|
+
}
|
|
49
|
+
block(block, tight = false) {
|
|
50
|
+
switch (block.type) {
|
|
51
|
+
case 'paragraph':
|
|
52
|
+
// A preview can hold back all of a paragraph's text
|
|
53
|
+
if (block.children.length === 0)
|
|
54
|
+
break;
|
|
55
|
+
if (tight) {
|
|
56
|
+
this.inlines(block.children);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.cr();
|
|
60
|
+
this.write('<p>');
|
|
61
|
+
this.inlines(block.children);
|
|
62
|
+
this.write('</p>');
|
|
63
|
+
this.cr();
|
|
64
|
+
}
|
|
65
|
+
break;
|
|
66
|
+
case 'heading':
|
|
67
|
+
this.cr();
|
|
68
|
+
this.write(`<h${block.depth}>`);
|
|
69
|
+
this.inlines(block.children);
|
|
70
|
+
this.write(`</h${block.depth}>`);
|
|
71
|
+
this.cr();
|
|
72
|
+
break;
|
|
73
|
+
case 'thematicBreak':
|
|
74
|
+
this.cr();
|
|
75
|
+
this.write('<hr />');
|
|
76
|
+
this.cr();
|
|
77
|
+
break;
|
|
78
|
+
case 'blockquote':
|
|
79
|
+
this.cr();
|
|
80
|
+
this.write('<blockquote>');
|
|
81
|
+
this.cr();
|
|
82
|
+
this.blocks(block.children);
|
|
83
|
+
this.cr();
|
|
84
|
+
this.write('</blockquote>');
|
|
85
|
+
this.cr();
|
|
86
|
+
break;
|
|
87
|
+
case 'list': {
|
|
88
|
+
const tag = block.ordered ? 'ol' : 'ul';
|
|
89
|
+
this.cr();
|
|
90
|
+
this.write(block.ordered && block.start !== null && block.start !== 1
|
|
91
|
+
? `<ol start="${block.start}">`
|
|
92
|
+
: `<${tag}>`);
|
|
93
|
+
this.cr();
|
|
94
|
+
for (const item of block.children)
|
|
95
|
+
this.item(item, block.tight);
|
|
96
|
+
this.cr();
|
|
97
|
+
this.write(`</${tag}>`);
|
|
98
|
+
this.cr();
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case 'listItem':
|
|
102
|
+
this.item(block, tight);
|
|
103
|
+
break;
|
|
104
|
+
case 'code': {
|
|
105
|
+
this.cr();
|
|
106
|
+
const lang = block.lang ? ` class="language-${escapeHtml(block.lang)}"` : '';
|
|
107
|
+
this.write(`<pre><code${lang}>${escapeHtml(block.value)}</code></pre>`);
|
|
108
|
+
this.cr();
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
case 'html':
|
|
112
|
+
this.cr();
|
|
113
|
+
this.raw(block.value);
|
|
114
|
+
this.cr();
|
|
115
|
+
break;
|
|
116
|
+
case 'math':
|
|
117
|
+
this.cr();
|
|
118
|
+
this.write(`<div class="math math-display">${escapeHtml(block.value)}</div>`);
|
|
119
|
+
this.cr();
|
|
120
|
+
break;
|
|
121
|
+
case 'table': {
|
|
122
|
+
this.cr();
|
|
123
|
+
this.write('<table>\n<thead>\n');
|
|
124
|
+
const [head, ...body] = block.children;
|
|
125
|
+
const cells = (row, tag) => {
|
|
126
|
+
this.write('<tr>\n');
|
|
127
|
+
row.children.forEach((cell, i) => {
|
|
128
|
+
const align = block.align[i];
|
|
129
|
+
this.write(align ? `<${tag} align="${align}">` : `<${tag}>`);
|
|
130
|
+
this.inlines(cell.children);
|
|
131
|
+
this.write(`</${tag}>\n`);
|
|
132
|
+
});
|
|
133
|
+
this.write('</tr>\n');
|
|
134
|
+
};
|
|
135
|
+
cells(head, 'th');
|
|
136
|
+
this.write('</thead>\n');
|
|
137
|
+
if (body.length > 0) {
|
|
138
|
+
this.write('<tbody>\n');
|
|
139
|
+
for (const row of body)
|
|
140
|
+
cells(row, 'td');
|
|
141
|
+
this.write('</tbody>\n');
|
|
142
|
+
}
|
|
143
|
+
this.write('</table>');
|
|
144
|
+
this.cr();
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case 'footnoteDefinition':
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
item(item, tight) {
|
|
152
|
+
this.cr();
|
|
153
|
+
this.write('<li>');
|
|
154
|
+
if (item.checked !== null) {
|
|
155
|
+
this.write(`<input type="checkbox"${item.checked ? ' checked=""' : ''} disabled="" /> `);
|
|
156
|
+
}
|
|
157
|
+
this.blocks(item.children, tight);
|
|
158
|
+
this.write('</li>');
|
|
159
|
+
this.cr();
|
|
160
|
+
}
|
|
161
|
+
inlines(inlines) {
|
|
162
|
+
for (const node of inlines)
|
|
163
|
+
this.inline(node);
|
|
164
|
+
}
|
|
165
|
+
inline(node) {
|
|
166
|
+
switch (node.type) {
|
|
167
|
+
case 'text':
|
|
168
|
+
this.write(escapeHtml(node.value));
|
|
169
|
+
break;
|
|
170
|
+
case 'softBreak':
|
|
171
|
+
this.write('\n');
|
|
172
|
+
break;
|
|
173
|
+
case 'break':
|
|
174
|
+
this.write('<br />\n');
|
|
175
|
+
break;
|
|
176
|
+
case 'emphasis':
|
|
177
|
+
this.write('<em>');
|
|
178
|
+
this.inlines(node.children);
|
|
179
|
+
this.write('</em>');
|
|
180
|
+
break;
|
|
181
|
+
case 'strong':
|
|
182
|
+
this.write('<strong>');
|
|
183
|
+
this.inlines(node.children);
|
|
184
|
+
this.write('</strong>');
|
|
185
|
+
break;
|
|
186
|
+
case 'delete':
|
|
187
|
+
this.write('<del>');
|
|
188
|
+
this.inlines(node.children);
|
|
189
|
+
this.write('</del>');
|
|
190
|
+
break;
|
|
191
|
+
case 'inlineCode':
|
|
192
|
+
this.write(`<code>${escapeHtml(node.value)}</code>`);
|
|
193
|
+
break;
|
|
194
|
+
case 'inlineHtml':
|
|
195
|
+
this.raw(node.value);
|
|
196
|
+
break;
|
|
197
|
+
case 'custom':
|
|
198
|
+
this.inlines(node.children);
|
|
199
|
+
break;
|
|
200
|
+
case 'inlineMath':
|
|
201
|
+
this.write(`<span class="math ${node.display ? 'math-display' : 'math-inline'}">${escapeHtml(node.value)}</span>`);
|
|
202
|
+
break;
|
|
203
|
+
case 'link': {
|
|
204
|
+
const href = this.options.safeLinks ? defaultLinkPolicy.href(node.url, node) : node.url;
|
|
205
|
+
// A link still waiting for its address is its words
|
|
206
|
+
if (href === null || node.pending) {
|
|
207
|
+
this.inlines(node.children);
|
|
208
|
+
break;
|
|
209
|
+
}
|
|
210
|
+
this.write(`<a href="${escapeHtml(href)}"${node.title ? ` title="${escapeHtml(node.title)}"` : ''}>`);
|
|
211
|
+
this.inlines(node.children);
|
|
212
|
+
this.write('</a>');
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
case 'image': {
|
|
216
|
+
const src = this.options.safeLinks ? defaultLinkPolicy.image(node.url, node) : node.url;
|
|
217
|
+
if (src === null) {
|
|
218
|
+
this.write(escapeHtml(node.alt));
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
this.write(`<img src="${escapeHtml(src)}" alt="${escapeHtml(node.alt)}"${node.title ? ` title="${escapeHtml(node.title)}"` : ''} />`);
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case 'footnoteReference': {
|
|
225
|
+
const key = node.label.toLowerCase();
|
|
226
|
+
// A reference to a footnote that was never defined is text
|
|
227
|
+
if (!this.defined.has(key)) {
|
|
228
|
+
this.write(escapeHtml(`[^${node.label}]`));
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
let n = this.footnoteOrder.get(key);
|
|
232
|
+
if (n === undefined)
|
|
233
|
+
this.footnoteOrder.set(key, (n = this.footnoteOrder.size + 1));
|
|
234
|
+
const use = (this.footnoteUses.get(key) ?? 0) + 1;
|
|
235
|
+
this.footnoteUses.set(key, use);
|
|
236
|
+
const id = escapeHtml(key);
|
|
237
|
+
this.write(`<sup class="footnote-ref"><a href="#fn-${id}" id="fnref-${id}${use > 1 ? `-${use}` : ''}" data-footnote-ref>${n}</a></sup>`);
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
footnotes(doc) {
|
|
243
|
+
// The first definition of a label counts. Notes are written in the order they are first
|
|
244
|
+
// referred to, and a note may refer to another, which then joins the end of the list.
|
|
245
|
+
const notes = new Map();
|
|
246
|
+
for (const note of doc.footnotes) {
|
|
247
|
+
const key = note.label.toLowerCase();
|
|
248
|
+
if (!notes.has(key))
|
|
249
|
+
notes.set(key, note);
|
|
250
|
+
}
|
|
251
|
+
const written = [];
|
|
252
|
+
for (let number = 1; number <= this.footnoteOrder.size; number++) {
|
|
253
|
+
const key = [...this.footnoteOrder].find(([, n]) => n === number)[0];
|
|
254
|
+
const note = notes.get(key);
|
|
255
|
+
if (!note)
|
|
256
|
+
continue;
|
|
257
|
+
if (written.length === 0) {
|
|
258
|
+
this.cr();
|
|
259
|
+
this.write('<section class="footnotes" data-footnotes>\n<ol>\n');
|
|
260
|
+
}
|
|
261
|
+
written.push(key);
|
|
262
|
+
const id = escapeHtml(key);
|
|
263
|
+
this.write(`<li id="fn-${id}">\n`);
|
|
264
|
+
this.blocks(note.children);
|
|
265
|
+
const uses = this.footnoteUses.get(key) ?? 1;
|
|
266
|
+
let back = '';
|
|
267
|
+
for (let i = 1; i <= uses; i++) {
|
|
268
|
+
back += ` <a href="#fnref-${id}${i > 1 ? `-${i}` : ''}" class="footnote-backref" data-footnote-backref aria-label="Back to reference ${number}">↩</a>`;
|
|
269
|
+
}
|
|
270
|
+
// The back links go at the end of the last paragraph
|
|
271
|
+
const n = this.parts.length;
|
|
272
|
+
if (n >= 2 && this.parts[n - 1] === '\n' && this.parts[n - 2] === '</p>')
|
|
273
|
+
this.parts.splice(n - 2, 0, back);
|
|
274
|
+
else
|
|
275
|
+
this.write(back.trim() + '\n');
|
|
276
|
+
this.write('</li>\n');
|
|
277
|
+
}
|
|
278
|
+
if (written.length > 0)
|
|
279
|
+
this.write('</ol>\n</section>\n');
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
export function toHtml(doc, options = {}) {
|
|
283
|
+
const writer = new Writer({ rawHtml: true, tagFilter: true, safeLinks: false, ...options });
|
|
284
|
+
for (const f of doc.footnotes)
|
|
285
|
+
writer.defined.add(f.label.toLowerCase());
|
|
286
|
+
writer.blocks(doc.children);
|
|
287
|
+
writer.footnotes(doc);
|
|
288
|
+
return writer.out;
|
|
289
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type MarkdownPlugin } from './plugin.js';
|
|
2
|
+
export type ImagesOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* Whether an image loads without asking. It is given the address as written, read as a
|
|
5
|
+
* browser reads it. The default allows none.
|
|
6
|
+
*/
|
|
7
|
+
allow?: (url: string) => boolean;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* For `allow`: whether an address is on the page's own site: relative to it, or an `http(s)` address with
|
|
11
|
+
* the page's own origin. Anything else is another site, including `//host/…`, which on a
|
|
12
|
+
* `file:` page shares the page's "origin" and is not on this machine at all.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sameOrigin(url: string): boolean;
|
|
15
|
+
export declare function images(options?: ImagesOptions): MarkdownPlugin;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Images that wait for a click, for Narvi's Markdown.
|
|
3
|
+
*
|
|
4
|
+
* An image is requested as soon as it is shown, so text written by a model, or by anyone
|
|
5
|
+
* else, can send data out through an image's address, or make a request to the app's own
|
|
6
|
+
* site with the person's cookies. With this plugin, an image the app has not allowed shows
|
|
7
|
+
* as a button that names its host, and loads only when pressed.
|
|
8
|
+
*
|
|
9
|
+
* import { images } from '@diegopluna/narvi/markdown/images';
|
|
10
|
+
* const plugins = [images({ allow: (url) => url.startsWith('https://cdn.example.com/') })];
|
|
11
|
+
*
|
|
12
|
+
* By default no image loads at once. Pass `allow: sameOrigin` to let the page's own site
|
|
13
|
+
* through. An `<img>` in raw HTML is held the same way, and the app's `links.image` policy
|
|
14
|
+
* still decides which addresses may load at all, and from where.
|
|
15
|
+
*/
|
|
16
|
+
import MarkdownImage from '../components/markdown/MarkdownImage.svelte';
|
|
17
|
+
import { readUrl, withProps } from './plugin.js';
|
|
18
|
+
/**
|
|
19
|
+
* For `allow`: whether an address is on the page's own site: relative to it, or an `http(s)` address with
|
|
20
|
+
* the page's own origin. Anything else is another site, including `//host/…`, which on a
|
|
21
|
+
* `file:` page shares the page's "origin" and is not on this machine at all.
|
|
22
|
+
*/
|
|
23
|
+
export function sameOrigin(url) {
|
|
24
|
+
const read = readUrl(url);
|
|
25
|
+
if (read.kind === 'relative')
|
|
26
|
+
return true;
|
|
27
|
+
if (read.kind !== 'scheme' || (read.scheme !== 'http' && read.scheme !== 'https'))
|
|
28
|
+
return false;
|
|
29
|
+
if (typeof location === 'undefined')
|
|
30
|
+
return false;
|
|
31
|
+
try {
|
|
32
|
+
return new URL(read.url).origin === location.origin;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function images(options = {}) {
|
|
39
|
+
const allow = options.allow ?? (() => false);
|
|
40
|
+
return {
|
|
41
|
+
name: 'images',
|
|
42
|
+
// An `<img>` in raw HTML is drawn by the same component, so it waits for a click too
|
|
43
|
+
components: { image: withProps(MarkdownImage, { allow }) }
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narvi's Markdown engine: an incremental CommonMark and GFM parser, for text that streams.
|
|
3
|
+
*
|
|
4
|
+
* The `Markdown` component, exported from `@diegopluna/narvi`, renders it. This entry point is
|
|
5
|
+
* for working with the document itself: parsing, streaming, writing HTML, and plugins.
|
|
6
|
+
*/
|
|
7
|
+
export type * from './ast.js';
|
|
8
|
+
export { MarkdownStream, parse, type ParseOptions } from './parse.js';
|
|
9
|
+
export { escapeHtml, toHtml, type HtmlOptions } from './html.js';
|
|
10
|
+
export { inlineText, tableToCsv, tableToMarkdown } from './table.js';
|
|
11
|
+
export { defaultLinkPolicy, mapInlines, mapText, readUrl, withProps, type HighlightStream, type HighlightToken, type Highlighter, type LinkPolicy, type MarkdownPlugin, type NodeProps, type PluginComponent, type StaticPart, type StaticTools, type ResolvedLinkPolicy } from './plugin.js';
|
|
12
|
+
export { groupBlockHtml, groupInlineHtml, sanitizeHtml, type HtmlElement, type HtmlGroup, type HtmlInlineElement, type HtmlMarkdown, type HtmlNode, type HtmlText, type RenderBlock, type RenderInline, type UrlPolicy } from './sanitize.js';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MarkdownStream, parse } from './parse.js';
|
|
2
|
+
export { escapeHtml, toHtml } from './html.js';
|
|
3
|
+
export { inlineText, tableToCsv, tableToMarkdown } from './table.js';
|
|
4
|
+
export { defaultLinkPolicy, mapInlines, mapText, readUrl, withProps } from './plugin.js';
|
|
5
|
+
export { groupBlockHtml, groupInlineHtml, sanitizeHtml } from './sanitize.js';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The inline parser: the text of one block in, inline nodes out.
|
|
3
|
+
*
|
|
4
|
+
* It follows the CommonMark spec's algorithm for emphasis and links (a delimiter stack and a
|
|
5
|
+
* bracket stack), as commonmark.js (BSD-2-Clause) implements it, plus the GFM extensions:
|
|
6
|
+
* strikethrough, autolinks without angle brackets, and footnote references.
|
|
7
|
+
*
|
|
8
|
+
* Every reference label the text looks up and does not find is reported in `missed`, so the
|
|
9
|
+
* block parser can convert this text again if that definition turns up later in the stream.
|
|
10
|
+
*/
|
|
11
|
+
import type { Definition, Inline } from './ast.js';
|
|
12
|
+
export type InlineContext = {
|
|
13
|
+
definitions: ReadonlyMap<string, Definition>;
|
|
14
|
+
/** Footnote labels that have a definition, normalized and prefixed with `^`. */
|
|
15
|
+
footnotes: ReadonlySet<string>;
|
|
16
|
+
gfm: boolean;
|
|
17
|
+
/** Formulas: `$x$`, `$$x$$`, `\\(x\\)` and `\\[x\\]`. */
|
|
18
|
+
math?: boolean;
|
|
19
|
+
/** Whether one tilde on each side strikes text through, as well as two. */
|
|
20
|
+
singleTilde?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type InlineResult = {
|
|
23
|
+
children: Inline[];
|
|
24
|
+
missed: Set<string>;
|
|
25
|
+
};
|
|
26
|
+
export declare function looksLikeCharClass(value: string): boolean;
|
|
27
|
+
export declare function looksLikeTex(value: string): boolean;
|
|
28
|
+
export declare function parseInlines(content: string, context: InlineContext): InlineResult;
|
|
29
|
+
/**
|
|
30
|
+
* Makes the end of text that is still being written read as it most likely will: a link
|
|
31
|
+
* waiting for its destination shows as its text, a half-written tag, entity or image is held
|
|
32
|
+
* back, an open code span runs to the end, and emphasis that has started is closed. Text
|
|
33
|
+
* that is complete is returned unchanged. Only ever used on the last, unfinished block.
|
|
34
|
+
*
|
|
35
|
+
* Every rule here is a guess about what comes next, so each one fires only where a wrong
|
|
36
|
+
* guess is unlikely: `a<b` is not a tag, `arr[i` is not a link, and `3*4` is not emphasis.
|
|
37
|
+
*/
|
|
38
|
+
export declare function tidyTail(content: string, context: InlineContext): string;
|
|
39
|
+
/**
|
|
40
|
+
* Reads a link reference definition at the start of `s`: `[label]: destination "title"`.
|
|
41
|
+
* Returns where it ends (after its line ending), or null when `s` does not start with one.
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseReferenceDefinition(s: string): {
|
|
44
|
+
label: string;
|
|
45
|
+
url: string;
|
|
46
|
+
title: string | null;
|
|
47
|
+
end: number;
|
|
48
|
+
} | null;
|