From fd29ed820e80a9365abe6e3a65eaee6b2409e6f2 Mon Sep 17 00:00:00 2001 From: Jiaxin Peng Date: Wed, 28 Aug 2024 20:26:06 +0100 Subject: [PATCH 1/2] fix code highlight issue --- CHANGELOG.md | 10 +++------- package.json | 2 +- src/upload/upload_general/Upload2NotionGeneral.ts | 13 +++++++++++++ src/upload/upload_next/Upload2NotionNext.ts | 13 +++++++++++++ src/upload/upoload_custom/Upload2NotionCustom.ts | 13 +++++++++++++ 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d94792..5c0ca52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,4 @@ -## Features - -- Support WebP format images. 支持 WebP 格式图片。 -- Support sync with long notes. 支持长文章同步。 - -Long articles or notes have been split into multiple parts, and the parts are synchronized in order. -长文章同步是通过将长文章或笔记拆分为多个部分,按顺序同步这些部分。 +## Fix +- Fix code block not being highlighted in Notion after syncing. +- 修复代码块同步之后,在 Notion 中未高亮的问题。 diff --git a/package.json b/package.json index 942147c..d627e73 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "share-to-notionnext", "version": "2.4.0", "type": "module", - "description": "Shares obsidian md file to notion with notion api for NotionNext web deploy, originally created by EasyChris/obsidian-to-notion.", + "description": "Share files to any Notion database using the Notion API, originally created by EasyChris/obsidian-to-notion.", "main": "main.js", "scripts": { "dev": "node esbuild.config.mjs", diff --git a/src/upload/upload_general/Upload2NotionGeneral.ts b/src/upload/upload_general/Upload2NotionGeneral.ts index 41d4471..977b9d8 100644 --- a/src/upload/upload_general/Upload2NotionGeneral.ts +++ b/src/upload/upload_general/Upload2NotionGeneral.ts @@ -58,6 +58,19 @@ export class Upload2NotionGeneral extends UploadBaseGeneral { notionAPI } = this.dbDetails; + // remove the annotations from the childArr if type is code block + childArr.forEach((block: any) => { + if (block.type === "code") { + block.code.rich_text.forEach(item => { + if (item.type === "text" && item.annotations) { + delete item.annotations; + } + } + ); + } + } + ); + // check the length of the childArr and split it into chunks of 100 const childArrLength = childArr.length; let extraArr: any[] = []; diff --git a/src/upload/upload_next/Upload2NotionNext.ts b/src/upload/upload_next/Upload2NotionNext.ts index 91df52a..a902b2f 100644 --- a/src/upload/upload_next/Upload2NotionNext.ts +++ b/src/upload/upload_next/Upload2NotionNext.ts @@ -82,6 +82,19 @@ export class Upload2NotionNext extends UploadBaseNext { ) { const {databaseID, notionAPI} = this.dbDetails; + // remove the annotations from the childArr if type is code block + childArr.forEach((block: any) => { + if (block.type === "code") { + block.code.rich_text.forEach(item => { + if (item.type === "text" && item.annotations) { + delete item.annotations; + } + } + ); + } + } + ); + // check the length of the childArr // if it is too long, split it into multiple pages const childArrLength = childArr.length; diff --git a/src/upload/upoload_custom/Upload2NotionCustom.ts b/src/upload/upoload_custom/Upload2NotionCustom.ts index 313f162..c64b46f 100644 --- a/src/upload/upoload_custom/Upload2NotionCustom.ts +++ b/src/upload/upoload_custom/Upload2NotionCustom.ts @@ -54,6 +54,19 @@ export class Upload2NotionCustom extends UploadBaseCustom { notionAPI } = this.dbDetails; + // remove the annotations from the childArr if type is code block + childArr.forEach((block: any) => { + if (block.type === "code") { + block.code.rich_text.forEach(item => { + if (item.type === "text" && item.annotations) { + delete item.annotations; + } + } + ); + } + } + ); + // check the length of the childArr and split it into chunks of 100 const childArrLength = childArr.length; let extraArr: any[] = []; From e8b16179160242f5eca64c1d483bebda3ee555bd Mon Sep 17 00:00:00 2001 From: Jiaxin Peng Date: Wed, 28 Aug 2024 20:30:05 +0100 Subject: [PATCH 2/2] fix item type error for iteration --- src/upload/upload_general/Upload2NotionGeneral.ts | 2 +- src/upload/upload_next/Upload2NotionNext.ts | 2 +- src/upload/upoload_custom/Upload2NotionCustom.ts | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/upload/upload_general/Upload2NotionGeneral.ts b/src/upload/upload_general/Upload2NotionGeneral.ts index 977b9d8..8f9201a 100644 --- a/src/upload/upload_general/Upload2NotionGeneral.ts +++ b/src/upload/upload_general/Upload2NotionGeneral.ts @@ -61,7 +61,7 @@ export class Upload2NotionGeneral extends UploadBaseGeneral { // remove the annotations from the childArr if type is code block childArr.forEach((block: any) => { if (block.type === "code") { - block.code.rich_text.forEach(item => { + block.code.rich_text.forEach((item: any) => { if (item.type === "text" && item.annotations) { delete item.annotations; } diff --git a/src/upload/upload_next/Upload2NotionNext.ts b/src/upload/upload_next/Upload2NotionNext.ts index a902b2f..832e163 100644 --- a/src/upload/upload_next/Upload2NotionNext.ts +++ b/src/upload/upload_next/Upload2NotionNext.ts @@ -85,7 +85,7 @@ export class Upload2NotionNext extends UploadBaseNext { // remove the annotations from the childArr if type is code block childArr.forEach((block: any) => { if (block.type === "code") { - block.code.rich_text.forEach(item => { + block.code.rich_text.forEach((item: any) => { if (item.type === "text" && item.annotations) { delete item.annotations; } diff --git a/src/upload/upoload_custom/Upload2NotionCustom.ts b/src/upload/upoload_custom/Upload2NotionCustom.ts index c64b46f..de64711 100644 --- a/src/upload/upoload_custom/Upload2NotionCustom.ts +++ b/src/upload/upoload_custom/Upload2NotionCustom.ts @@ -57,11 +57,11 @@ export class Upload2NotionCustom extends UploadBaseCustom { // remove the annotations from the childArr if type is code block childArr.forEach((block: any) => { if (block.type === "code") { - block.code.rich_text.forEach(item => { - if (item.type === "text" && item.annotations) { - delete item.annotations; + block.code.rich_text.forEach((item: any) => { + if (item.type === "text" && item.annotations) { + delete item.annotations; + } } - } ); } }