Skip to content

Commit

Permalink
Adapt to new ChatGPT HTML format (Aug 2023) (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsh9 committed Aug 16, 2023
1 parent 479e825 commit aebd2c8
Show file tree
Hide file tree
Showing 22 changed files with 90 additions and 31 deletions.
2 changes: 1 addition & 1 deletion dist/minimizedChatGptToMarkdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "ChatGPT to Markdown",
"version": "0.0.5",
"version": "0.0.6",
"description": "A Chrome extension to save ChatGPT Q&A page as markdown",
"permissions": ["activeTab", "scripting"],
"action": {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chatgpt-to-markdown",
"version": "0.0.5",
"version": "0.0.6",
"description": "Save ChatGPT Q&A page as markdown",
"scripts": {
"build": "npx webpack --mode production",
Expand Down
6 changes: 3 additions & 3 deletions src/utils/consoleSave.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ module.exports = function (console, fileType) {
let filename = title
? title
.trim()
.replace(/["]/g, "'") // replace double quote with single quote
.replace(/[\\/:*?"<>|]/g, '-') // replace non-filename-elegible symbols with "-"
.replace(/\.$/, '') // remove dot at the end
.replace(/["]/g, "'") // replace double quote with single quote
.replace(/[\\/:*?"<>|]/g, '-') // replace non-filename-elegible symbols with "-"
.replace(/\.$/, '') // remove dot at the end
: 'chatGPT';
if (fileType.toLowerCase() === 'json') {
filename += '.json';
Expand Down
14 changes: 6 additions & 8 deletions src/utils/parseNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@ const blockQuoteUtils = require('./blockQuoteUtils');
function parseNode(node, level) {
var nodeMarkdown = '';

if (node.nodeType === Node.TEXT_NODE) {
nodeMarkdown += getHorizontalRules();
nodeMarkdown += `## Question\n\n`;
nodeMarkdown += node.textContent;
nodeMarkdown += '\n\n';
}

if (node.nodeType === Node.ELEMENT_NODE) {
const childNodes = node.childNodes;

if (node.className == 'empty:hidden') {
nodeMarkdown += getHorizontalRules();
nodeMarkdown += `\n\n## Question\n\n`;
}

if (node.className.includes('markdown prose')) {
nodeMarkdown += `## Answer\n\n`;
nodeMarkdown += `\n\n## Answer\n\n`;
}

if (node.tagName === 'OL') {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/parseElements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ global.Node = {
};

test.each([
['2023_08_new_format.html', '2023_08_new_format.md'],
['plain_paragraphs.html', 'plain_paragraphs.md'],
['block_quotes_0.html', 'block_quotes_0.md'],
['block_quotes_1.html', 'block_quotes_1.md'],
Expand Down
4 changes: 4 additions & 0 deletions tests/utils/test_cases/2023_08_new_format.html

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions tests/utils/test_cases/2023_08_new_format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Question

Hi ChatGPT!

## Answer

Hello! How can I assist you today?

----------

## Question

What version are you?

## Answer

I am based on the GPT-4 architecture. How can I help you today?

----------

## Question

Just want to casually chat with you.

## Answer

Of course! Casual chats are always welcome. What's on your mind? Anything you're curious about or want to discuss?

----------

## Question

Which number is bigger? 1234^5678 or 5678^1234?

## Answer

To determine which number is larger, 123456781234^{5678}12345678 or 567812345678^{1234}56781234, we can use logarithms.

Let's compare the natural logarithms (ln) of the two numbers:

A = ln(123456781234^{5678}12345678)
B = ln(567812345678^{1234}56781234)

Using the properties of logarithms, these become:

A = 5678 * ln(1234)
B = 1234 * ln(5678)

Now, let's compute each value:

A ≈ 5678 * 7.118016 = 40405.28
B ≈ 1234 * 8.644121 = 10672.68

Clearly, A is much larger than B.

This means that the logarithm of 123456781234^{5678}12345678 is much larger than the logarithm of 567812345678^{1234}56781234. Since the natural logarithm function is increasing, this means 123456781234^{5678}12345678 is larger than 567812345678^{1234}56781234.
2 changes: 1 addition & 1 deletion tests/utils/test_cases/block_quotes_0.html

Large diffs are not rendered by default.

Loading

0 comments on commit aebd2c8

Please sign in to comment.