chatgpt-to-markdown 1.5.0 → 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 +2 -0
  2. package/index.js +34 -22
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -97,6 +97,8 @@ git push --follow-tags
97
97
 
98
98
  ## Release notes
99
99
 
100
+ - 1.5.2: 05 Aug 2024. Show tether_browsing_display summary
101
+ - 1.5.1: 22 Mar 2024. Handle unicode filenames
100
102
  - 1.5.0: 28 Nov 2023. Handle `tether_browsing_display`, `tether_quote` and `system_error`
101
103
  - 1.4.0: 29 Oct 2023. Handle multi-modal text from Dall-E
102
104
  - 1.3.0: 29 Sep 2023. Set create and update dates from chat
package/index.js CHANGED
@@ -9,6 +9,7 @@ import path from "path";
9
9
  function sanitizeFileName(title) {
10
10
  return title
11
11
  .replace(/[<>:"\/\\|?*\n]/g, " ")
12
+ .replace(/[^\w\s]/gi, " ")
12
13
  .replace(/\s+/g, " ")
13
14
  .trim();
14
15
  }
@@ -81,28 +82,39 @@ async function chatgptToMarkdown(json, sourceDir, { dateFormat } = { dateFormat:
81
82
  let content = node.message?.content;
82
83
  if (!content) return "";
83
84
  // Format the body based on the content type
84
- let body =
85
- content.content_type == "text"
86
- ? content.parts.join("\n")
87
- : content.content_type == "code"
88
- ? "```" + content.language.replace("unknown", "") + "\n" + content.text + "\n```"
89
- : content.content_type == "execution_output"
90
- ? "```\n" + content.text + "\n```"
91
- : content.content_type == "multimodal_text"
92
- ? content.parts
93
- .map((part) =>
94
- part.content_type === "image_asset_pointer"
95
- ? `Image (${part.width}x${part.height}): ${part?.metadata?.dalle?.prompt}\n\n`
96
- : `${part.content_type}\n\n`,
97
- )
98
- .join("")
99
- : content.content_type == "tether_browsing_display"
100
- ? "```\n" + content.result + "\n```"
101
- : content.content_type == "tether_quote"
102
- ? "```\n" + `${content.title} (${content.url})\n\n${content.text}` + "\n```"
103
- : content.content_type == "system_error"
104
- ? `${content.name}\n\n${content.text}\n\n`
105
- : 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
+ }
106
118
  // Ignore empty content
107
119
  if (!body.trim()) return "";
108
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.0",
3
+ "version": "1.5.2",
4
4
  "description": "Convert ChatGPT exported conversations.json to Markdown",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -23,6 +23,6 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "jest": "^29.7.0",
26
- "prettier": "^3.0.3"
26
+ "prettier": "^3.2.5"
27
27
  }
28
28
  }