11import React , { useMemo } from 'react' ;
2- import { renderToString } from 'react-dom/server' ;
2+ // import { renderToString } from 'react-dom/server';
33import { HLJSOptions , HLJSPlugin } from 'highlight.js' ;
44import hljs from 'highlight.js/lib/core' ; // Skip highlight's auto-registering
55import hljsDefineGraphQL from 'highlightjs-graphql' ;
@@ -52,16 +52,6 @@ function initializeSyntaxHighlighting() {
5252 hljsDefineGraphQL ( hljs ) ;
5353 } else {
5454 hljs . registerLanguage ( language , languageParsers [ language ] ) ;
55-
56- // const kwds = ['shaneeza'];
57-
58- // hljs.getLanguage(language).keywords.custom = ['testing'];
59- // const built_in = hljs.getLanguage(language);
60- // console.log({ language, built_in });
61-
62- // hljs.getLanguage(language).keywords.built_in = [
63- // ...new Set([...built_in, ...kwds]),
64- // ];
6555 }
6656 } ) ;
6757
@@ -71,23 +61,6 @@ function initializeSyntaxHighlighting() {
7161 } as Partial < HLJSOptions > ) ;
7262
7363 hljs . addPlugin ( renderingPlugin as HLJSPlugin ) ;
74-
75- // hljs.addPlugin({
76- // 'before:highlight': results => {
77- // console.log('🍓🍓🍓', { code: results.code });
78- // results.code = results.code.replace(
79- // /datetime/g,
80- // '<div class="highlighted">datetime</div>',
81- // );
82- // },
83- // });
84-
85- // in after:highlight, the code is already a react component so I don't think I can modify it
86- // hljs.addPlugin({
87- // 'after:highlight': results => {
88- // console.log('🍓🍓🍓', { results });
89- // },
90- // });
9164}
9265
9366const codeStyles = css `
@@ -133,12 +106,17 @@ function Syntax({
133106 highlightedContent . react
134107 ) ;
135108
136- const string = renderToString ( content ) . replace (
137- / _ s h a n e e z a _ / g,
138- '<span class="highlighted">shaneeza</span>' ,
139- ) ;
109+ /**
110+ * This is a workaround to add a custom class to any word wrapped in a underscore. E.g. _highlight_
111+ */
112+ // const updatedStringWithCustomClass = renderToString(
113+ // content as ReactElement,
114+ // ).replace(
115+ // /_(\w+)_/g,
116+ // (_, word) => `<span class="lg-highlight-custom">${word}</span>`,
117+ // );
140118
141- console . log ( { beforeString : renderToString ( content ) , string } ) ;
119+ // console.log({ beforeString: renderToString(content), updatedStringWithCustomClass });
142120
143121 const { theme, darkMode } = useDarkMode ( ) ;
144122
@@ -174,8 +152,10 @@ function Syntax({
174152 border-spacing : 0 ;
175153 ` }
176154 >
177- { /* <tbody>{content}</tbody> */ }
178- < tbody dangerouslySetInnerHTML = { { __html : string } } />
155+ < tbody > { content } </ tbody >
156+ { /* <tbody
157+ dangerouslySetInnerHTML={{ __html: updatedStringWithCustomClass }}
158+ /> */ }
179159 </ table >
180160 </ code >
181161 </ SyntaxContext . Provider >
0 commit comments