@ampless/runtime 1.0.0-alpha.53 → 1.0.0-alpha.55

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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Post, MediaMetadata, AmplessPlugin, ContentFieldRenderer, PluginPublicRenderContext, Config, ThemeModule, ThemeManifest, PluginPackageManifest } from 'ampless';
1
+ import { Post, MediaMetadata, AmplessPlugin, ContentFieldRenderer, PluginPublicRenderContext, TiptapNodeMarkdownAdapters, Config, ThemeModule, ThemeManifest, PluginPackageManifest } from 'ampless';
2
2
  export { Config, Post, ThemeManifest } from 'ampless';
3
3
  import { Metadata } from 'next';
4
4
  import { ReactNode } from 'react';
@@ -219,6 +219,13 @@ declare function markdownToHtml(md: string): string;
219
219
  * shape but produces markdown syntax. Loses anything markdown can't
220
220
  * express (data attributes, image display modes, custom marks).
221
221
  *
222
+ * `opts.nodeAdapters` lets callers supply per-nodeType serialisers —
223
+ * the admin post-form passes the registry populated by
224
+ * `installAdminTiptapNodeMarkdown` so that plugin-registered embed nodes
225
+ * (e.g. `amplessYoutube`) are serialised to bare URL lines instead of
226
+ * falling through with empty children. Callers that omit `opts` get the
227
+ * original behaviour unchanged.
228
+ *
222
229
  * Notes on info loss:
223
230
  * - underline / highlight are not in GFM, so they fall back to the
224
231
  * literal `<u>` / `<mark>` HTML tags (preserved as-is across round trips).
@@ -229,7 +236,9 @@ declare function markdownToHtml(md: string): string;
229
236
  * hasn't emitted JSON yet (the body is still the HTML we handed it).
230
237
  * Route through htmlToMarkdown so the content survives.
231
238
  */
232
- declare function tiptapToMarkdown(doc: unknown): string;
239
+ declare function tiptapToMarkdown(doc: unknown, opts?: {
240
+ nodeAdapters?: TiptapNodeMarkdownAdapters;
241
+ }): string;
233
242
  /**
234
243
  * Regex-based HTML -> Markdown converter. Handles the tag set the
235
244
  * editor produces (`<p>` `<h1>`-`<h6>` `<strong>` `<em>` `<a>`
package/dist/index.js CHANGED
@@ -606,12 +606,19 @@ function tiptapToHtml(doc) {
606
606
  function markdownToHtml(md) {
607
607
  return renderMarkdownString(md);
608
608
  }
609
- function tiptapToMarkdown(doc) {
609
+ function tiptapToMarkdown(doc, opts) {
610
610
  if (typeof doc === "string") return htmlToMarkdown(doc);
611
611
  const node = doc;
612
- return tiptapNodeToMarkdown(node).trim() + "\n";
613
- }
614
- function tiptapNodeToMarkdown(node) {
612
+ return tiptapNodeToMarkdown(node, opts ?? {}).trim() + "\n";
613
+ }
614
+ function tiptapNodeToMarkdown(node, opts) {
615
+ const adapter = opts.nodeAdapters?.[node.type];
616
+ if (adapter) {
617
+ const out = adapter(node);
618
+ if (typeof out === "string") {
619
+ return "\n" + out + "\n\n";
620
+ }
621
+ }
615
622
  if (node.type === "text") {
616
623
  let txt = node.text ?? "";
617
624
  for (const mark of node.marks ?? []) {
@@ -625,7 +632,7 @@ function tiptapNodeToMarkdown(node) {
625
632
  }
626
633
  return txt;
627
634
  }
628
- const children = (node.content ?? []).map(tiptapNodeToMarkdown).join("");
635
+ const children = (node.content ?? []).map((c) => tiptapNodeToMarkdown(c, opts)).join("");
629
636
  switch (node.type) {
630
637
  case "doc":
631
638
  return children;
@@ -659,7 +666,7 @@ function tiptapNodeToMarkdown(node) {
659
666
  return `![${alt}](${src})`;
660
667
  }
661
668
  case "table":
662
- return tiptapTableToMarkdown(node);
669
+ return tiptapTableToMarkdown(node, opts);
663
670
  case "taskList":
664
671
  return children + "\n";
665
672
  case "taskItem": {
@@ -674,7 +681,7 @@ function tiptapNodeToMarkdown(node) {
674
681
  return children;
675
682
  }
676
683
  }
677
- function tiptapTableToMarkdown(node) {
684
+ function tiptapTableToMarkdown(node, opts) {
678
685
  const rows = node.content ?? [];
679
686
  if (rows.length === 0) return "";
680
687
  const renderedRows = [];
@@ -683,7 +690,7 @@ function tiptapTableToMarkdown(node) {
683
690
  const row = rows[i];
684
691
  const cells = row.content ?? [];
685
692
  const cellTexts = cells.map((c) => {
686
- const inner = (c.content ?? []).map(tiptapNodeToMarkdown).join("");
693
+ const inner = (c.content ?? []).map((n) => tiptapNodeToMarkdown(n, opts)).join("");
687
694
  return inner.replace(/\n+$/, "").replace(/\n/g, "<br>").replace(/\|/g, "\\|");
688
695
  });
689
696
  renderedRows.push(cellTexts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampless/runtime",
3
- "version": "1.0.0-alpha.53",
3
+ "version": "1.0.0-alpha.55",
4
4
  "description": "Public-side runtime for ampless: post fetching, theme dispatch, middleware, public route handlers",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -50,8 +50,8 @@
50
50
  "marked": "^18.0.4",
51
51
  "sanitize-html": "^2.17.4",
52
52
  "tailwind-merge": "^3.6.0",
53
- "@ampless/plugin-og-image": "0.2.0-alpha.44",
54
- "ampless": "1.0.0-alpha.44"
53
+ "@ampless/plugin-og-image": "0.2.0-alpha.46",
54
+ "ampless": "1.0.0-alpha.46"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@aws-amplify/adapter-nextjs": "^1",