This is an automated email from the ASF dual-hosted git repository.
jeffreyh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new 69d71fc126 [fix]:Fixed the problem of invalid bolding in markdown
documents (#1679)
69d71fc126 is described below
commit 69d71fc1265b4e920f95a50631c1cfec1f2fd5fa
Author: yangon <[email protected]>
AuthorDate: Mon Jan 6 11:47:53 2025 +0800
[fix]:Fixed the problem of invalid bolding in markdown documents (#1679)
Co-authored-by: liyang <[email protected]>
---
config/markdown-bold-plugin.js | 73 ++++++++++++++++++++++++++++++++++++++++++
docusaurus.config.js | 2 ++
package.json | 1 +
3 files changed, 76 insertions(+)
diff --git a/config/markdown-bold-plugin.js b/config/markdown-bold-plugin.js
new file mode 100644
index 0000000000..d622b2a2c8
--- /dev/null
+++ b/config/markdown-bold-plugin.js
@@ -0,0 +1,73 @@
+const { visit } = require('unist-util-visit');
+
+function getFirstBoldContent(str, startIdx = 0) {
+ const strArr = str.split("");
+ for (let i = startIdx; i < strArr.length; i++) {
+ if (
+ strArr[i - 1] !== "*" &&
+ strArr[i] === "*" &&
+ strArr[i + 1] === "*" &&
+ strArr[i + 2] !== "*"
+ ) {
+ // start with **
+ let j;
+ for (j = i + 2; j < strArr.length; j++) {
+ if (
+ strArr[j - 1] !== "*" &&
+ strArr[j] === "*" &&
+ strArr[j + 1] === "*" &&
+ strArr[j + 2] !== "*"
+ ) {
+ // end with **
+ return {
+ start: i,
+ end: j,
+ };
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+const plugin = options => {
+ const transformer = async (ast, file) => {
+ visit(ast, 'text', (node, index, parent) => {
+ if (getFirstBoldContent(node.value)) {
+ const { start, end } = getFirstBoldContent(node.value);
+ const value = node.value.slice(start + 2, end);
+ parent.children[index] = {
+ type: 'strong',
+ children: [
+ {
+ value: value,
+ type: 'text',
+ },
+ ],
+ };
+ const [boldBefore, , boldAfter] = node.value.split('**');
+ let hasBoldBefore = !!boldBefore;
+ if (boldBefore) {
+ parent.children.splice(index, 0, {
+ type: 'text',
+ value: boldBefore,
+ });
+ }
+ if (boldAfter) {
+ parent.children.splice(hasBoldBefore ? index + 2 : index +
1, 0, {
+ type: 'text',
+ value: boldAfter,
+ });
+ }
+ console.warn(
+ `The bold syntax of "${value}" in "${file.path}" is
invalid and is being automatically optimized`,
+ );
+ }
+ });
+ };
+ return transformer;
+};
+
+module.exports = {
+ markdownBoldPlugin: plugin,
+};
diff --git a/docusaurus.config.js b/docusaurus.config.js
index ae20ee8a89..001906b688 100644
--- a/docusaurus.config.js
+++ b/docusaurus.config.js
@@ -3,6 +3,7 @@ const { ssrTemplate } = require('./config/ssrTemplate');
const customDocusaurusPlugin = require('./config/custom-docusaurus-plugin');
const versionsPlugin = require('./config/versions-plugin');
const VERSIONS = require('./versions.json');
+const { markdownBoldPlugin } = require('./config/markdown-bold-plugin');
const lightCodeTheme = themes.dracula;
const logoImg = 'https://cdnd.selectdb.com/images/logo.svg';
@@ -161,6 +162,7 @@ const config = {
// },
showLastUpdateAuthor: false,
showLastUpdateTime: false,
+ remarkPlugins: [markdownBoldPlugin],
},
blog: {
blogTitle: 'Apache Doris - Blog | Latest news and events ',
diff --git a/package.json b/package.json
index 11dd798cb4..63d8aeb1b8 100644
--- a/package.json
+++ b/package.json
@@ -41,6 +41,7 @@
"sass-migrator": "^2.2.1",
"swiper": "^9.0.5",
"tailwindcss": "^3.3.6",
+ "unist-util-visit": "^5.0.0",
"vitpress-generate-pdf": "^1.1.4"
},
"devDependencies": {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]