From 033b124b902d14d91ef3e9635d36a154fde94b71 Mon Sep 17 00:00:00 2001 From: liding Date: Mon, 1 Jul 2024 16:11:27 +0800 Subject: [PATCH 1/6] Add new processing rule. --- .../article/article_body/ArticleBody.astro | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/components/article/article_body/ArticleBody.astro b/src/components/article/article_body/ArticleBody.astro index 9901f0c..198183f 100644 --- a/src/components/article/article_body/ArticleBody.astro +++ b/src/components/article/article_body/ArticleBody.astro @@ -2,25 +2,32 @@ // get rendered ArticleBodyContent HTML const html = await Astro.slots.render("default"); -// If some lines are not started with ASCII character, -// join them to their previous line. -// This is important. -// Because I add one newline character to wrap Chinese. +// rule: +// 1. If a line belongs to the area where the line break should be kept. +// 2. If a line ends with [a-zA-Z] add a space to the end of the line. +// 3. If a line does not start in ASCII chars, join it to the previous line. +// This is important in using one newline character to wrap Chinese. const arr = html.split("\n"); let articleHTMLFinal = arr[0]; -// Whether the current line belongs to the area where -// the line break should be kept. let remainIntactArea = false; for (let i = 1; i < arr.length; i++) { + // The first line of the HTML string is a table-of-content head recognized by + // remark-toc so it can be ignored. + if (arr[i].charAt(arr[i].length - 1).match(/[a-zA-Z]/) !== null) { + arr[i] += " "; + } + // Check if the current line belongs to some block area. if (arr[i].match(/^( Date: Wed, 31 Jul 2024 20:46:24 +0800 Subject: [PATCH 2/6] Add new processing rule and improve comments. --- .../article/article_body/ArticleBody.astro | 39 +++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/components/article/article_body/ArticleBody.astro b/src/components/article/article_body/ArticleBody.astro index 198183f..392ecc5 100644 --- a/src/components/article/article_body/ArticleBody.astro +++ b/src/components/article/article_body/ArticleBody.astro @@ -3,25 +3,42 @@ const html = await Astro.slots.render("default"); // rule: -// 1. If a line belongs to the area where the line break should be kept. -// 2. If a line ends with [a-zA-Z] add a space to the end of the line. -// 3. If a line does not start in ASCII chars, join it to the previous line. +// 1. If a line belongs to the area where the line break should be kept, +// do not process this line. +// 2. If a line ends with [a-zA-Z], add a space to the end of this line. +// 3. If a line ends without [a-zA-Z] and its next line starts with [a-zA-Z], +// add a heading space to the next line. +// 4. If a line does not start in ASCII chars, join it to its previous line. // This is important in using one newline character to wrap Chinese. const arr = html.split("\n"); let articleHTMLFinal = arr[0]; let remainIntactArea = false; +// The first line of the HTML string is a table-of-content head recognized by +// remark-toc so it can be ignored. for (let i = 1; i < arr.length; i++) { - // The first line of the HTML string is a table-of-content head recognized by - // remark-toc so it can be ignored. - if (arr[i].charAt(arr[i].length - 1).match(/[a-zA-Z]/) !== null) { - arr[i] += " "; - } // Check if the current line belongs to some block area. if (arr[i].match(/^( Date: Tue, 6 Aug 2024 11:00:42 +0800 Subject: [PATCH 3/6] Add new processing rule and improve comments. --- .../article/article_body/ArticleBody.astro | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/components/article/article_body/ArticleBody.astro b/src/components/article/article_body/ArticleBody.astro index 392ecc5..93af240 100644 --- a/src/components/article/article_body/ArticleBody.astro +++ b/src/components/article/article_body/ArticleBody.astro @@ -9,6 +9,10 @@ const html = await Astro.slots.render("default"); // 3. If a line ends without [a-zA-Z] and its next line starts with [a-zA-Z], // add a heading space to the next line. // 4. If a line does not start in ASCII chars, join it to its previous line. +// 5. If a line starts with or , add a heading space to this +// line. +// 6. If a line ends with or , add a tailing space to this +// line. // This is important in using one newline character to wrap Chinese. const arr = html.split("\n"); let articleHTMLFinal = arr[0]; @@ -16,6 +20,7 @@ let remainIntactArea = false; // The first line of the HTML string is a table-of-content head recognized by // remark-toc so it can be ignored. for (let i = 1; i < arr.length; i++) { + // rule 1 // Check if the current line belongs to some block area. if (arr[i].match(/^(|)/) !== null){ + arr[i] = " " + arr[i]; + } + // rule 6 + if (arr[i].match(/(<\/em>|<\/strong>)$/) !== null){ + arr[i] = arr[i] + " "; + } // -------- combine lines + // rule 4 if ( // ( // If the first character is not ascii character, From c323698b2a870904456a2fdd11e1d2b1049d02bd Mon Sep 17 00:00:00 2001 From: liding Date: Wed, 7 Aug 2024 18:01:36 +0800 Subject: [PATCH 4/6] Update a rule. --- .../article/article_body/ArticleBody.astro | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/article/article_body/ArticleBody.astro b/src/components/article/article_body/ArticleBody.astro index 93af240..be5e52b 100644 --- a/src/components/article/article_body/ArticleBody.astro +++ b/src/components/article/article_body/ArticleBody.astro @@ -9,10 +9,10 @@ const html = await Astro.slots.render("default"); // 3. If a line ends without [a-zA-Z] and its next line starts with [a-zA-Z], // add a heading space to the next line. // 4. If a line does not start in ASCII chars, join it to its previous line. -// 5. If a line starts with or , add a heading space to this -// line. -// 6. If a line ends with or , add a tailing space to this -// line. +// 5. If a line starts with or or , add a heading space to +// this line. +// 6. If a line ends with or or , add a tailing space to +// this line. // This is important in using one newline character to wrap Chinese. const arr = html.split("\n"); let articleHTMLFinal = arr[0]; @@ -47,11 +47,11 @@ for (let i = 1; i < arr.length; i++) { arr[i] += " "; } // rule 5 - if (arr[i].match(/^(|)/) !== null){ + if (arr[i].match(/^(||)/) !== null){ arr[i] = " " + arr[i]; } // rule 6 - if (arr[i].match(/(<\/em>|<\/strong>)$/) !== null){ + if (arr[i].match(/(<\/em>|<\/strong>|<\/a>)$/) !== null){ arr[i] = arr[i] + " "; } // -------- combine lines From 9cf9745d49aab0fba9b0aaaf533c07d08f23e013 Mon Sep 17 00:00:00 2001 From: liding Date: Sat, 12 Oct 2024 21:04:57 +0800 Subject: [PATCH 5/6] Format all code using prettier. --- .prettierrc.mjs | 12 +++ .vscode/settings.json | 11 +++ package-lock.json | 62 +++++++++++++- package.json | 2 + src/components/Footer.astro | 1 + src/components/HTMLCommonHead.astro | 2 +- src/components/Nav.astro | 1 + .../article/CollectionSummary.astro | 14 ++-- .../article/article_body/ArticleBody.astro | 17 ++-- src/components/tool/ToolNav.astro | 19 ++--- .../unit_conversion/DataUnitConversion.vue | 80 ++++++++++--------- .../UnitConversionWrapper.astro | 2 +- .../unit_conversion/WeightUnitConversion.vue | 50 ++++++------ src/layouts/DefaultLayout.astro | 4 +- src/pages/article/blog/[...blog].astro | 2 +- src/pages/article/note/[...note].astro | 2 +- .../translation/[...translation].astro | 2 +- src/styles/global.css | 17 +++- 18 files changed, 199 insertions(+), 101 deletions(-) create mode 100644 .prettierrc.mjs create mode 100644 .vscode/settings.json diff --git a/.prettierrc.mjs b/.prettierrc.mjs new file mode 100644 index 0000000..aa2deee --- /dev/null +++ b/.prettierrc.mjs @@ -0,0 +1,12 @@ +/** @type {import("prettier").Config} */ +export default { + plugins: ['prettier-plugin-astro'], + overrides: [ + { + files: '*.astro', + options: { + parser: 'astro', + }, + }, + ], +}; \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a6d1c00 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "[json]": { + "editor.tabSize": 2 + }, + "[javascript]": { + "editor.tabSize": 2 + }, + "[typescript]": { + "editor.tabSize": 2 + } +} diff --git a/package-lock.json b/package-lock.json index c65cb9b..1c894e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,8 @@ "astro": "^4.9.2", "bignumber.js": "^9.1.2", "pinyin-pro": "^3.22.0", + "prettier": "^3.3.3", + "prettier-plugin-astro": "^0.14.1", "remark-toc": "^9.0.0", "typescript": "^5.4.5", "vue": "^3.4.29" @@ -58,9 +60,10 @@ } }, "node_modules/@astrojs/compiler": { - "version": "2.8.0", - "resolved": "https://registry.npmmirror.com/@astrojs/compiler/-/compiler-2.8.0.tgz", - "integrity": "sha512-yrpD1WRGqsJwANaDIdtHo+YVjvIOFAjC83lu5qENIgrafwZcJgSXDuwVMXOgok4tFzpeKLsFQ6c3FoUdloLWBQ==" + "version": "2.10.3", + "resolved": "https://registry.npmmirror.com/@astrojs/compiler/-/compiler-2.10.3.tgz", + "integrity": "sha512-bL/O7YBxsFt55YHU021oL+xz+B/9HvGNId3F9xURN16aeqDK9juHGktdkCSXz+U4nqFACq6ZFvWomOzhV+zfPw==", + "license": "MIT" }, "node_modules/@astrojs/internal-helpers": { "version": "0.4.0", @@ -5400,6 +5403,35 @@ "node": ">=8.15" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmmirror.com/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-plugin-astro": { + "version": "0.14.1", + "resolved": "https://registry.npmmirror.com/prettier-plugin-astro/-/prettier-plugin-astro-0.14.1.tgz", + "integrity": "sha512-RiBETaaP9veVstE4vUwSIcdATj6dKmXljouXc/DDNwBSPTp8FRkLGDSGFClKsAFeeg+13SB0Z1JZvbD76bigJw==", + "license": "MIT", + "dependencies": { + "@astrojs/compiler": "^2.9.1", + "prettier": "^3.0.0", + "sass-formatter": "^0.7.6" + }, + "engines": { + "node": "^14.15.0 || >=16.0.0" + } + }, "node_modules/prismjs": { "version": "1.29.0", "resolved": "https://registry.npmmirror.com/prismjs/-/prismjs-1.29.0.tgz", @@ -6114,6 +6146,21 @@ "queue-microtask": "^1.2.2" } }, + "node_modules/s.color": { + "version": "0.0.15", + "resolved": "https://registry.npmmirror.com/s.color/-/s.color-0.0.15.tgz", + "integrity": "sha512-AUNrbEUHeKY8XsYr/DYpl+qk5+aM+DChopnWOPEzn8YKzOhv4l2zH6LzZms3tOZP3wwdOyc0RmTciyi46HLIuA==", + "license": "MIT" + }, + "node_modules/sass-formatter": { + "version": "0.7.9", + "resolved": "https://registry.npmmirror.com/sass-formatter/-/sass-formatter-0.7.9.tgz", + "integrity": "sha512-CWZ8XiSim+fJVG0cFLStwDvft1VI7uvXdCNJYXhDvowiv+DsbD1nXLiQ4zrE5UBvj5DWZJ93cwN0NX5PMsr1Pw==", + "license": "MIT", + "dependencies": { + "suf-log": "^2.5.3" + } + }, "node_modules/sax": { "version": "1.4.1", "resolved": "https://registry.npmmirror.com/sax/-/sax-1.4.1.tgz", @@ -6395,6 +6442,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/suf-log": { + "version": "2.5.3", + "resolved": "https://registry.npmmirror.com/suf-log/-/suf-log-2.5.3.tgz", + "integrity": "sha512-KvC8OPjzdNOe+xQ4XWJV2whQA0aM1kGVczMQ8+dStAO6KfEB140JEVQ9dE76ONZ0/Ylf67ni4tILPJB41U0eow==", + "license": "MIT", + "dependencies": { + "s.color": "0.0.15" + } + }, "node_modules/superjson": { "version": "2.2.1", "resolved": "https://registry.npmmirror.com/superjson/-/superjson-2.2.1.tgz", diff --git a/package.json b/package.json index 69f7e5e..063bc7a 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ "astro": "^4.9.2", "bignumber.js": "^9.1.2", "pinyin-pro": "^3.22.0", + "prettier": "^3.3.3", + "prettier-plugin-astro": "^0.14.1", "remark-toc": "^9.0.0", "typescript": "^5.4.5", "vue": "^3.4.29" diff --git a/src/components/Footer.astro b/src/components/Footer.astro index f831500..cf39222 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -1,4 +1,5 @@ --- + ---