Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #227

Merged
merged 3 commits into from
Sep 20, 2024
Merged

Dev #227

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions render-markdown-codehighlight/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@

import { useEffect, useState } from 'react';
import hljs from 'highlight.js';
import { themeStyles } from './themeStyles'
import { themeStyles } from './themeStyles';


const useHighlightCode = (element: HTMLElement | null) => {
const useHighlightCode = (props: HTMLElement | null | {
current: HTMLElement | null;
}) => {
const [selectTheme, setSelectTheme] = useState<string>('default');

// Fetch theme from API
Expand All @@ -39,7 +41,14 @@ const useHighlightCode = (element: HTMLElement | null) => {
}, []);

useEffect(() => {
if (!element) return;
let element;
if (props instanceof HTMLElement) {
element = props;
} else if (props && props.current instanceof HTMLElement) {
element = props.current;
} else {
return;
}

const applyThemeCSS = async (theme: string) => {
const existingStyleElement = document.querySelector('style[data-theme-style="highlight"]');
Expand Down Expand Up @@ -96,10 +105,9 @@ const useHighlightCode = (element: HTMLElement | null) => {
contentObserver.disconnect();
themeObserver.disconnect();
};
}, [element, selectTheme]);
}, [props, selectTheme]);

return null;
};

export { useHighlightCode };

2 changes: 1 addition & 1 deletion render-markdown-codehighlight/info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@

slug_name: render_markdown_codehighlight
type: render
version: 0.0.3
version: 0.0.4
author: Chen Jiaji, Zhu Xuanlyu
link: https://github.com/apache/incubator-answer-plugins/tree/main/render-markdown-codehighlight
2 changes: 1 addition & 1 deletion render-markdown-codehighlight/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "render-markdown-codehighlight",
"version": "0.0.3",
"version": "0.0.4",
"description": "",
"type": "module",
"files": [
Expand Down
Loading