@dropsh/plugin-markdown 0.5.7 → 0.6.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.
@@ -0,0 +1,4 @@
1
+ import type { DropSHPlugin } from "dropsh/plugin";
2
+ import { renderMarkdown } from "./render-md.js";
3
+ export { renderMarkdown };
4
+ export declare function markdownPlugin(): DropSHPlugin;
@@ -0,0 +1,2 @@
1
+ import { type JsonApiDocument, type RenderContext } from "dropsh/plugin";
2
+ export declare function renderMarkdown(doc: JsonApiDocument, _ctx: RenderContext): string;
@@ -24,18 +24,21 @@ function relIds(rel) {
24
24
  return [`${data.type}/${data.id}`];
25
25
  return [];
26
26
  }
27
- // Flattens any attribute value to a single-line string for `label: value`
28
- // output. Text-field objects (`{ processed | value }`) collapse to their text;
29
- // other objects/arrays fall back to compact JSON.
30
- function fieldValue(v) {
27
+ // Extracts an attribute's text as-is. Long-text objects (`{ value, format,
28
+ // processed }`) resolve to their raw `value` (the markdown source) — never the
29
+ // `processed` HTML; `processed` remains the fallback for text objects that
30
+ // carry no raw value. Other objects/arrays fall back to compact JSON.
31
+ function fieldText(v) {
31
32
  if (isScalar(v))
32
- return yamlScalar(v);
33
+ return typeof v === "string" ? v : String(v);
33
34
  if (v && typeof v === "object") {
34
35
  const o = v;
36
+ if (typeof o.value === "string" && typeof o.format === "string")
37
+ return o.value;
35
38
  if (typeof o.processed === "string")
36
- return yamlScalar(o.processed);
39
+ return o.processed;
37
40
  if (typeof o.value === "string")
38
- return yamlScalar(o.value);
41
+ return o.value;
39
42
  return JSON.stringify(v);
40
43
  }
41
44
  return "";
@@ -45,7 +48,17 @@ function fieldValue(v) {
45
48
  function renderResource(res) {
46
49
  const lines = [`type: ${res.type}`, `id: ${res.id}`];
47
50
  for (const [k, v] of Object.entries(res.attributes ?? {})) {
48
- lines.push(`${k}: ${fieldValue(v)}`);
51
+ const text = fieldText(v);
52
+ if (text.includes("\n")) {
53
+ // Multi-line field content (descriptions, comment bodies) is emitted as
54
+ // a readable indented block, not a `\n`-escaped quoted one-liner.
55
+ lines.push(`${k}: |`);
56
+ for (const l of text.replace(/\n+$/, "").split("\n"))
57
+ lines.push(l === "" ? "" : ` ${l}`);
58
+ }
59
+ else {
60
+ lines.push(`${k}: ${yamlScalar(text)}`);
61
+ }
49
62
  }
50
63
  for (const [k, v] of Object.entries(res.relationships ?? {})) {
51
64
  const ids = relIds(v);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dropsh/plugin-markdown",
3
- "version": "0.5.7",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "main": "./dist/plugins/markdown/src/index.js",
6
6
  "types": "./dist/plugins/markdown/src/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "devDependencies": {
27
27
  "typescript": "^5.6.0",
28
28
  "vitest": "^2.1.0",
29
- "dropsh": "0.5.7"
29
+ "dropsh": "0.6.0"
30
30
  },
31
31
  "scripts": {
32
32
  "build": "tsc",