chatgpt-to-markdown 1.4.0 → 1.5.1
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/README.md +2 -0
- package/index.js +21 -14
- package/index.test.js +43 -0
- 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.1: 22 Mar 2024. Handle unicode filenames
|
101
|
+
- 1.5.0: 28 Nov 2023. Handle `tether_browsing_display`, `tether_quote` and `system_error`
|
100
102
|
- 1.4.0: 29 Oct 2023. Handle multi-modal text from Dall-E
|
101
103
|
- 1.3.0: 29 Sep 2023. Set create and update dates from chat
|
102
104
|
- 1.2.0: 28 Sep 2023. Added test cases
|
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
|
}
|
@@ -33,8 +34,8 @@ function wrapHtmlTagsInBackticks(text) {
|
|
33
34
|
function indent(str) {
|
34
35
|
return str
|
35
36
|
.split("\n")
|
36
|
-
.map((v) => ` ${v}`)
|
37
|
-
.join("
|
37
|
+
.map((v) => ` ${v}\n`)
|
38
|
+
.join("");
|
38
39
|
}
|
39
40
|
|
40
41
|
const dateFormat = new Intl.DateTimeFormat("en-US", {
|
@@ -85,18 +86,24 @@ async function chatgptToMarkdown(json, sourceDir, { dateFormat } = { dateFormat:
|
|
85
86
|
content.content_type == "text"
|
86
87
|
? content.parts.join("\n")
|
87
88
|
: content.content_type == "code"
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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;
|
100
107
|
// Ignore empty content
|
101
108
|
if (!body.trim()) return "";
|
102
109
|
// Indent user / tool messages. The sometimes contain code and whitespaces are relevant
|
package/index.test.js
CHANGED
@@ -47,6 +47,7 @@ describe("chatgptToMarkdown", () => {
|
|
47
47
|
|
48
48
|
Hello
|
49
49
|
|
50
|
+
|
50
51
|
`);
|
51
52
|
});
|
52
53
|
|
@@ -129,6 +130,48 @@ describe("chatgptToMarkdown", () => {
|
|
129
130
|
expect(fileContent).not.toContain("## user (John)");
|
130
131
|
});
|
131
132
|
|
133
|
+
it("should handle tether_browsing_display content", async () => {
|
134
|
+
const json = [
|
135
|
+
{
|
136
|
+
title: "Test Conversation",
|
137
|
+
create_time: 1630454400,
|
138
|
+
update_time: 1630458000,
|
139
|
+
mapping: {
|
140
|
+
0: {
|
141
|
+
message: {
|
142
|
+
author: { role: "tool", name: "browser" },
|
143
|
+
content: { content_type: "tether_browsing_display", result: "L0: x" },
|
144
|
+
},
|
145
|
+
},
|
146
|
+
},
|
147
|
+
},
|
148
|
+
];
|
149
|
+
await chatgptToMarkdown(json, tempDir);
|
150
|
+
const fileContent = await fs.readFile(path.join(tempDir, "Test Conversation.md"), "utf8");
|
151
|
+
expect(fileContent).toContain("```\nL0: x\n```");
|
152
|
+
});
|
153
|
+
|
154
|
+
it("should handle tether_quote content", async () => {
|
155
|
+
const json = [
|
156
|
+
{
|
157
|
+
title: "Test Conversation",
|
158
|
+
create_time: 1630454400,
|
159
|
+
update_time: 1630458000,
|
160
|
+
mapping: {
|
161
|
+
0: {
|
162
|
+
message: {
|
163
|
+
author: { role: "tool", name: "browser" },
|
164
|
+
content: { content_type: "tether_quote", url: "x.com", domain: "x.com", title: "T", text: "X" },
|
165
|
+
},
|
166
|
+
},
|
167
|
+
},
|
168
|
+
},
|
169
|
+
];
|
170
|
+
await chatgptToMarkdown(json, tempDir);
|
171
|
+
const fileContent = await fs.readFile(path.join(tempDir, "Test Conversation.md"), "utf8");
|
172
|
+
expect(fileContent).toContain("```\nT (x.com)\n\nX\n```");
|
173
|
+
});
|
174
|
+
|
132
175
|
it("should handle multimodal_text content", async () => {
|
133
176
|
const json = [
|
134
177
|
{
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "chatgpt-to-markdown",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.5.1",
|
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.
|
26
|
+
"prettier": "^3.2.5"
|
27
27
|
}
|
28
28
|
}
|