chatgpt-to-markdown 1.5.1 → 1.5.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +33 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -97,6 +97,7 @@ git push --follow-tags
97
97
 
98
98
  ## Release notes
99
99
 
100
+ - 1.5.2: 05 Aug 2024. Show tether_browsing_display summary
100
101
  - 1.5.1: 22 Mar 2024. Handle unicode filenames
101
102
  - 1.5.0: 28 Nov 2023. Handle `tether_browsing_display`, `tether_quote` and `system_error`
102
103
  - 1.4.0: 29 Oct 2023. Handle multi-modal text from Dall-E
package/index.js CHANGED
@@ -82,28 +82,39 @@ async function chatgptToMarkdown(json, sourceDir, { dateFormat } = { dateFormat:
82
82
  let content = node.message?.content;
83
83
  if (!content) return "";
84
84
  // Format the body based on the content type
85
- let body =
86
- content.content_type == "text"
87
- ? content.parts.join("\n")
88
- : content.content_type == "code"
89
- ? "```" + content.language.replace("unknown", "") + "\n" + content.text + "\n```"
90
- : content.content_type == "execution_output"
91
- ? "```\n" + content.text + "\n```"
92
- : content.content_type == "multimodal_text"
93
- ? content.parts
94
- .map((part) =>
95
- part.content_type === "image_asset_pointer"
96
- ? `Image (${part.width}x${part.height}): ${part?.metadata?.dalle?.prompt}\n\n`
97
- : `${part.content_type}\n\n`,
98
- )
99
- .join("")
100
- : content.content_type == "tether_browsing_display"
101
- ? "```\n" + content.result + "\n```"
102
- : content.content_type == "tether_quote"
103
- ? "```\n" + `${content.title} (${content.url})\n\n${content.text}` + "\n```"
104
- : content.content_type == "system_error"
105
- ? `${content.name}\n\n${content.text}\n\n`
106
- : content;
85
+ let body;
86
+ switch (content.content_type) {
87
+ case "text":
88
+ body = content.parts.join("\n");
89
+ break;
90
+ case "code":
91
+ body = "```" + content.language.replace("unknown", "") + "\n" + content.text + "\n```";
92
+ break;
93
+ case "execution_output":
94
+ body = "```\n" + content.text + "\n```";
95
+ break;
96
+ case "multimodal_text":
97
+ body = content.parts
98
+ .map((part) =>
99
+ part.content_type === "image_asset_pointer"
100
+ ? `Image (${part.width}x${part.height}): ${part?.metadata?.dalle?.prompt ?? ""}\n\n`
101
+ : `${part.content_type}\n\n`,
102
+ )
103
+ .join("");
104
+ break;
105
+ case "tether_browsing_display":
106
+ body = "```\n" + (content.summary ? `${content.summary}\n` : "") + content.result + "\n```";
107
+ break;
108
+ case "tether_quote":
109
+ body = "```\n" + `${content.title} (${content.url})\n\n${content.text}` + "\n```";
110
+ break;
111
+ case "system_error":
112
+ body = `${content.name}\n\n${content.text}\n\n`;
113
+ break;
114
+ default:
115
+ body = content;
116
+ break;
117
+ }
107
118
  // Ignore empty content
108
119
  if (!body.trim()) return "";
109
120
  // Indent user / tool messages. The sometimes contain code and whitespaces are relevant
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chatgpt-to-markdown",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
4
4
  "description": "Convert ChatGPT exported conversations.json to Markdown",
5
5
  "main": "index.js",
6
6
  "type": "module",