Skip to content

Commit

Permalink
fix: LaTeX format in exported markdown
Browse files Browse the repository at this point in the history
* fix: LaTeX format in exported markdown
* fix: copy issue
  • Loading branch information
dice2o committed Apr 26, 2023
1 parent 2adbf83 commit d13974c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 19 deletions.
4 changes: 2 additions & 2 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
productName: 'BingGPT',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.3',
version: '0.3.4',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand All @@ -56,7 +56,7 @@ module.exports = {
productName: 'BingGPT',
description: 'AI-powered copilot',
productDescription: 'AI-powered copilot',
version: '0.3.3',
version: '0.3.4',
categories: ['Utility'],
maintainer: 'dice2o',
homepage: 'https://github.com/dice2o/BingGPT',
Expand Down
15 changes: 5 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,9 @@ const createWindow = () => {
label: 'Reset',
visible: parameters.selectionText.trim().length === 0,
click: () => {
const session = mainWindow.webContents.session
session
.clearStorageData({
storages: ['localstorage', 'cookies'],
})
.then(() => {
mainWindow.reload()
})
mainWindow.webContents.session.clearStorageData().then(() => {
mainWindow.reload()
})
},
},
{
Expand All @@ -219,7 +214,7 @@ const createWindow = () => {
},
},
{
label: 'BingGPT v0.3.3',
label: 'BingGPT v0.3.4',
visible: parameters.selectionText.trim().length === 0,
click: () => {
shell.openExternal('https://github.com/dice2o/BingGPT/releases')
Expand All @@ -232,7 +227,7 @@ const createWindow = () => {
isDarkMode ? 'dark' : 'light'
}schemeovr=1&FORM=SHORUN&udscs=1&udsnav=1&setlang=${locale}&features=udssydinternal&clientscopes=windowheader,coauthor,chat,&udsframed=1`
const userAgent =
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.0.0'
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.0.0'
mainWindow.loadURL(bingUrl)
// Open links in default browser
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
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,7 +1,7 @@
{
"name": "binggpt",
"productName": "BingGPT",
"version": "0.3.3",
"version": "0.3.4",
"description": "AI-powered copilot",
"author": "dice2o",
"license": "Apache-2.0",
Expand Down
30 changes: 26 additions & 4 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,15 @@ window.addEventListener('DOMContentLoaded', () => {
const composeWrapper = document.getElementsByClassName(
'uds_coauthor_wrapper'
)[0]
const composeMain = document.getElementsByClassName('main')[0]
const composeMain = document.getElementsByClassName('sidebar')[0]
const insertBtn = document.getElementById('insert_button')
const previewText = document.getElementById('preview_text')
const previewOptions = document.getElementsByClassName('preview-options')[0]
if (composeWrapper) {
composeWrapper.style.cssText = 'margin-top: -64px'
}
if (composeMain) {
composeMain.style.cssText =
'height: calc(100% - 64px); margin-top: 64px; padding: 20px 10px'
composeMain.style.cssText = 'height: calc(100% - 64px); margin-top: 64px'
}
if (insertBtn) {
insertBtn.style.cssText = 'display: none'
Expand Down Expand Up @@ -338,9 +337,32 @@ const markdownHandler = (element) => {
return `> **${content}**`
},
})
turndownService.addRule('latex', {
filter: (node) => {
return node.classList.contains('katex-block')
},
replacement: (content, node) => {
return `$$${node.querySelector('annotation').innerHTML}$$`
},
})
turndownService.addRule('inlineLatex', {
filter: (node) => {
return node.classList.contains('katex')
},
replacement: (content, node) => {
return `$${node.querySelector('annotation').innerHTML}$`
},
})
const mdDataURL = Buffer.from(
turndownService.turndown(element),
turndownService.turndown(element) + '\n',
'utf-8'
).toString('base64')
ipcRenderer.send('export-data', 'md', mdDataURL)
}

// Fix copy issue
window.addEventListener('copy', (event) => {
const selection = document.getSelection()
event.clipboardData.setData('text/plain', selection.toString())
event.preventDefault()
})

0 comments on commit d13974c

Please sign in to comment.