chatgpt-to-markdown 1.4.0 → 1.5.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.
- package/README.md +1 -0
- package/index.js +8 -2
- package/index.test.js +43 -0
- 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.0: 28 Nov 2023. Handle `tether_browsing_display`, `tether_quote` and `system_error`
|
100
101
|
- 1.4.0: 29 Oct 2023. Handle multi-modal text from Dall-E
|
101
102
|
- 1.3.0: 29 Sep 2023. Set create and update dates from chat
|
102
103
|
- 1.2.0: 28 Sep 2023. Added test cases
|
package/index.js
CHANGED
@@ -33,8 +33,8 @@ function wrapHtmlTagsInBackticks(text) {
|
|
33
33
|
function indent(str) {
|
34
34
|
return str
|
35
35
|
.split("\n")
|
36
|
-
.map((v) => ` ${v}`)
|
37
|
-
.join("
|
36
|
+
.map((v) => ` ${v}\n`)
|
37
|
+
.join("");
|
38
38
|
}
|
39
39
|
|
40
40
|
const dateFormat = new Intl.DateTimeFormat("en-US", {
|
@@ -96,6 +96,12 @@ async function chatgptToMarkdown(json, sourceDir, { dateFormat } = { dateFormat:
|
|
96
96
|
: `${part.content_type}\n\n`,
|
97
97
|
)
|
98
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`
|
99
105
|
: content;
|
100
106
|
// Ignore empty content
|
101
107
|
if (!body.trim()) return "";
|
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
|
{
|