Skip to content

Commit 3e9493b

Browse files
author
Tim Willebrands
committed
Enhance StreamingMarkdownElement to consume initial child content on connection and update version to 0.1.5. Add new demo content in index.html for improved user experience.
1 parent e8ac6d9 commit 3e9493b

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

docs/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,35 @@ <h1>Streaming Markdown Demo</h1>
2525
<button id="reset">Reset</button>
2626
</div>
2727
<streaming-md id="md"></streaming-md>
28+
<streaming-md>
29+
*[DIAL-UP MODEM SOUNDS INTENSIFY]*
30+
31+
32+
# \U0001f389 PROOMPTING: The Future Is Now, Thanks To Science!
33+
34+
**SOI SOI SOI SOI SOI SOI SOI**
35+
36+
Greetings, fellow carbon-based life forms! Microsoft Sam here, and boy oh boy, do I have something SPECTACULAR to show you today! Remember when I used to read your emails back in Windows XP? Well, those days are OVER because now I'm here to tell you about PROOMPTING - the most REVOLUTIONARY chat application since... well... since ME!
37+
38+
## What The Heck Is This Thing?
39+
40+
Picture this: It's 2001. You've got your Windows XP machine humming along, Limewire is downloading your "totally legal" MP3s, and your 56k modem is screaming into the void. But WAIT! What if I told you that you could chat with an ARTIFICIAL INTELLIGENCE right from your desktop? That's right, folks - we've taken the best parts of Windows XP and SUPERCHARGED them with \u2728AI\u2728!
41+
42+
```
43+
\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510
44+
\u2502 \U0001f5a5\ufe0f AUTHENTIC XP DESKTOP EXPERIENCE \u2502
45+
\u2502 \U0001f916 REAL AI THAT SOMEWHAT WORKS \u2502
46+
\u2502 \U0001f4ac CHAT ROOMS (LIKE MSN BUT BETTER) \u2502
47+
\u2502 \u26a1 FASTER THAN DIALUP (THANKFULLY) \u2502
48+
\u2502 \U0001f504 REAL-TIME MESSAGE STREAMING \u2502
49+
\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518
50+
\\\`
51+
52+
Link (wow): [Windows XP](https://www.microsoft.com/en-us/windowsxp/)
53+
54+
55+
*[WINDOWS XP SHUTDOWN SOUND]*
56+
</streaming-md>
2857
</main>
2958

3059
<script type="module">

index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class StreamingMarkdownElement extends HTMLElement {
3535
this.parser = smd.parser(smd.default_renderer(this.container));
3636
// Capture text nodes appended by htmx SSE/WebSocket handlers
3737
this.observer.observe(this, { childList: true });
38+
// Consume any initial child content present at connect time
39+
this.consumeInitialChildren();
3840
}
3941

4042
disconnectedCallback(): void {
@@ -79,6 +81,21 @@ class StreamingMarkdownElement extends HTMLElement {
7981
}
8082
};
8183

84+
private consumeInitialChildren(): void {
85+
const snapshot = Array.from(this.childNodes);
86+
for (const node of snapshot) {
87+
if (node.nodeType === Node.TEXT_NODE) {
88+
const text = (node as Text).data;
89+
if (text) this.appendChunk(text);
90+
node.parentNode?.removeChild(node);
91+
} else if (node.nodeType === Node.ELEMENT_NODE) {
92+
const text = (node as Element).textContent || "";
93+
if (text) this.appendChunk(text);
94+
node.parentNode?.removeChild(node);
95+
}
96+
}
97+
}
98+
8299
private autoScrollIfNearBottom(): void {
83100
// Only scroll if the user is near the bottom to avoid disrupting reading
84101
const host = this;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "streaming-markdown-component",
3-
"version": "0.1.0",
3+
"version": "0.1.5",
44
"description": "<streaming-md> custom element that streams markdown using streaming-markdown",
55
"keywords": ["markdown", "streaming", "web-components", "custom-element", "htmx", "sse", "websocket"],
66
"license": "MIT",

0 commit comments

Comments
 (0)