You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by ro...@apache.org on 2024/12/02 03:35:03 UTC

(incubator-answer-plugins) branch dev updated (03339f4 -> c92642e)

This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a change to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git


    from 03339f4  chore: Sync Plugin Info
     new fa8e5f6  refactor(hooks): improve code readability and update default theme
     new c92642e  chore(render-markdown-codehighlight): bump version to 0.2.0

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 render-markdown-codehighlight/hooks.ts  | 47 ++++++++++++++++++++++-----------
 render-markdown-codehighlight/info.yaml |  2 +-
 2 files changed, 32 insertions(+), 17 deletions(-)


(incubator-answer-plugins) 02/02: chore(render-markdown-codehighlight): bump version to 0.2.0

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git

commit c92642ea24d5732086bfbfc09c91db51550240ad
Author: robin <ro...@rnode.me>
AuthorDate: Mon Dec 2 11:33:52 2024 +0800

    chore(render-markdown-codehighlight): bump version to 0.2.0
---
 render-markdown-codehighlight/info.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/render-markdown-codehighlight/info.yaml b/render-markdown-codehighlight/info.yaml
index 8de459b..5e60175 100644
--- a/render-markdown-codehighlight/info.yaml
+++ b/render-markdown-codehighlight/info.yaml
@@ -17,6 +17,6 @@
 
 slug_name: render_markdown_codehighlight
 type: render
-version: 0.1.2
+version: 0.2.0
 author: Chen Jiaji, Zhu Xuanlyu
 link: https://github.com/apache/incubator-answer-plugins/tree/main/render-markdown-codehighlight


(incubator-answer-plugins) 01/02: refactor(hooks): improve code readability and update default theme

Posted by ro...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

robin0716 pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git

commit fa8e5f61853f29ef563244690e5af23b0c155b07
Author: robin <ro...@rnode.me>
AuthorDate: Mon Dec 2 11:32:59 2024 +0800

    refactor(hooks): improve code readability and update default theme
---
 render-markdown-codehighlight/hooks.ts | 47 ++++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 16 deletions(-)

diff --git a/render-markdown-codehighlight/hooks.ts b/render-markdown-codehighlight/hooks.ts
index 3b5c51c..37e1d31 100644
--- a/render-markdown-codehighlight/hooks.ts
+++ b/render-markdown-codehighlight/hooks.ts
@@ -27,20 +27,27 @@ const get = async (url: string) => {
   const { data } = await response.json();
   return data;
 };
-
-const useHighlightCode: FC<pluginHookProps> = (props: HTMLElement | null | {
-  current: HTMLElement | null;
-}, request: Request = {
-  get
-}) => {
-  const [selectTheme, setSelectTheme] = useState<string>('default');
+const useHighlightCode: FC<pluginHookProps> = (
+  props:
+    | HTMLElement
+    | null
+    | {
+      current: HTMLElement | null;
+    },
+  request: Request = {
+    get,
+  },
+) => {
+  const [selectTheme, setSelectTheme] = useState<string>('stackoverflow');
 
   // Fetch theme from API
   useEffect(() => {
-    request.get('/answer/api/v1/render/config')
+    request
+      .get('/answer/api/v1/render/config')
       .then((result) => {
-        console.log('Fetched theme:', result.select_theme);
-        setSelectTheme(result.select_theme);
+        if (result.select_theme) {
+          setSelectTheme(result.select_theme);
+        }
       })
       .catch((error) => {
         console.error('Error fetching theme:', error);
@@ -58,7 +65,9 @@ const useHighlightCode: FC<pluginHookProps> = (props: HTMLElement | null | {
     }
 
     const applyThemeCSS = async (theme: string) => {
-      const existingStyleElement = document.querySelector('style[data-theme-style="highlight"]');
+      const existingStyleElement = document.querySelector(
+        'style[data-theme-style="highlight"]',
+      );
       if (existingStyleElement) existingStyleElement.remove();
 
       const styleElement = document.createElement('style');
@@ -81,24 +90,30 @@ const useHighlightCode: FC<pluginHookProps> = (props: HTMLElement | null | {
     };
 
     // Get and apply the initial theme
-    const currentTheme = document.documentElement.getAttribute('data-bs-theme') || 'light';
+    const currentTheme =
+      document.documentElement.getAttribute('data-bs-theme') || 'light';
     applyThemeCSS(currentTheme);
 
     // Observe DOM changes (e.g., code block content changes)
     const contentObserver = new MutationObserver(() => {
-      const newTheme = document.documentElement.getAttribute('data-bs-theme') || 'light';
-      console.log('Detected code content change, reapplying syntax highlighting, current theme:', newTheme);
+      const newTheme =
+        document.documentElement.getAttribute('data-bs-theme') || 'light';
+      console.log(
+        'Detected code content change, reapplying syntax highlighting, current theme:',
+        newTheme,
+      );
       applyThemeCSS(newTheme);
     });
 
     contentObserver.observe(element, {
       childList: true, // Observe changes to child elements
-      subtree: true,   // Observe the entire subtree
+      subtree: true, // Observe the entire subtree
     });
 
     // Observe theme changes
     const themeObserver = new MutationObserver(() => {
-      const newTheme = document.documentElement.getAttribute('data-bs-theme') || 'light';
+      const newTheme =
+        document.documentElement.getAttribute('data-bs-theme') || 'light';
       console.log('Detected theme change:', newTheme);
       applyThemeCSS(newTheme);
     });