@aparte/core 0.17.1 → 0.17.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.
@@ -1416,11 +1416,12 @@ class AparteConfig {
1416
1416
  * Set an incremental (streaming) Markdown renderer provider. Optional —
1417
1417
  * when set, the chat bubble uses it to render the assistant message
1418
1418
  * token-by-token DURING streaming (incremental parse + DOM append, O(n)),
1419
- * instead of re-parsing the whole string on every token. When the turn ends,
1420
- * a registered one-shot `setMarkdownProvider` re-renders the finished message
1421
- * at full fidelity; with no one-shot provider registered, what the streaming
1422
- * renderer drew is kept (sanitised), rather than replaced by the built-in
1423
- * escape-and-line-break fallback.
1419
+ * instead of re-parsing the whole string on every token. With no one-shot
1420
+ * `setMarkdownProvider` registered, it also renders a COMPLETE string
1421
+ * (`renderMarkdown`): a restored reply, a non-streaming provider's answer, a
1422
+ * stored segment — so a reply renders the same however it arrived. A registered
1423
+ * one-shot provider takes over for those, and re-renders the finished message
1424
+ * at full fidelity.
1424
1425
  */
1425
1426
  setStreamingMarkdownProvider(fn) {
1426
1427
  this._streamingMarkdownProvider = fn;
@@ -2034,8 +2035,16 @@ class AparteConfig {
2034
2035
  return val === void 0 ? "" : val;
2035
2036
  }
2036
2037
  /**
2037
- * Render Markdown to HTML
2038
- * Fallback: Escapes HTML and converts newlines to <br>
2038
+ * Render a complete Markdown string to HTML: the one-shot provider when one is
2039
+ * registered, else the incremental provider run over the whole string, else core's
2040
+ * default (escape + `<br>`).
2041
+ *
2042
+ * The middle step is what makes the incremental provider enough on its own. Without
2043
+ * it a reply rendered two ways depending on how it arrived: rich while it streamed,
2044
+ * escaped source once it came back complete — a restored conversation, a
2045
+ * non-streaming provider, a stored segment. Same parser, same sanitizer, so the two
2046
+ * cannot disagree. It needs a `document` to write into; without one (a server render)
2047
+ * the default answers, as before.
2039
2048
  */
2040
2049
  renderMarkdown(raw) {
2041
2050
  if (this._markdownProvider) {
@@ -2044,6 +2053,16 @@ class AparteConfig {
2044
2053
  } catch (error) {
2045
2054
  console.warn("[AparteConfig] Markdown provider failed, using fallback:", error);
2046
2055
  }
2056
+ } else if (this._streamingMarkdownProvider && typeof document !== "undefined") {
2057
+ try {
2058
+ const target = document.createElement("div");
2059
+ const renderer = this._streamingMarkdownProvider(target);
2060
+ renderer.write(raw);
2061
+ renderer.end();
2062
+ return this.sanitizeHtml(target.innerHTML);
2063
+ } catch (error) {
2064
+ console.warn("[AparteConfig] Streaming Markdown provider failed on a complete string, using fallback:", error);
2065
+ }
2047
2066
  }
2048
2067
  return this._defaultMarkdownRenderer(raw);
2049
2068
  }
@@ -6996,4 +7015,4 @@ export {
6996
7015
  collectRendererStyles as y,
6997
7016
  contentToText as z
6998
7017
  };
6999
- //# sourceMappingURL=dialog-triggers-CJWw0P3l.js.map
7018
+ //# sourceMappingURL=dialog-triggers-DwTGKWeU.js.map