File tree Expand file tree Collapse file tree 1 file changed +31
-4
lines changed Expand file tree Collapse file tree 1 file changed +31
-4
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ import HTMLCodeBlockElement from 'html-code-block-element/dist/class/HTMLCodeBlo
114114Manual setup:
115115
116116``` js
117+ // 1. Import
117118import hljs from ' highlight.js/lib/core' ;
118119import javascript from ' highlight.js/lib/languages/javascript' ;
119120import HTMLCodeBlockElement from ' html-code-block-element/dist/class/HTMLCodeBlockElement' ;
@@ -122,13 +123,39 @@ import HTMLCodeBlockElement from 'html-code-block-element/dist/class/HTMLCodeBlo
122123// Support JavaScript
123124hljs .registerLanguage (' javascript' , javascript);
124125
125- // Set endgine
126- HTMLCodeBlockElement .endgine = hljs;
127126
128- // Define
127+ // 2. Set endgine
128+ /**
129+ * Example: Callback to be called internally
130+ * @param {string} src - Source code string for highlight
131+ * @param {{ language: string }} options - Option for highlight
132+ * @returns {{ markup: string }} - Object of the highlight result
133+ */
134+ HTMLCodeBlockElement .highlight = function (src , options ) {
135+ if (
136+ // Verifying the existence of a language
137+ options? .language &&
138+ hljs .getLanguage (options .language )
139+ ) {
140+ const {value } = hljs .highlight (
141+ src,
142+ options,
143+ );
144+
145+ return {
146+ markup: value,
147+ };
148+ }
149+
150+ return {
151+ markup: hljs .highlightAuto (src).value ,
152+ };
153+ }
154+
155+ // 3. Define
129156customElements .define (' code-block' , HTMLCodeBlockElement);
130157
131- // Use
158+ // 4. Use
132159const cbElm = new HTMLCodeBlockElement ();
133160` ` `
134161
You can’t perform that action at this time.
0 commit comments