@@ -222,38 +222,19 @@ var codeInput = {
222
222
* For adding small pieces of functionality, please see `codeInput.plugins`.
223
223
*/
224
224
templates : {
225
+ // (Source code for class templates after var codeInput = ... so they can extend the codeInput.Template class)
225
226
/**
226
- * Constructor to create a template that uses Prism.js syntax highlighting (https://prismjs.com/)
227
- * @param {Object } prism Import Prism.js, then after that import pass the `Prism` object as this parameter.
228
- * @param {codeInput.Plugin[] } plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
229
- * @returns {codeInput.Template } template object
227
+ * @deprecated Please use `new codeInput.templates.Prism(...)`
230
228
*/
231
229
prism ( prism , plugins = [ ] ) { // Dependency: Prism.js (https://prismjs.com/)
232
- return new codeInput . Template (
233
- prism . highlightElement , // highlight
234
- true , // preElementStyled
235
- true , // isCode
236
- false , // includeCodeInputInHighlightFunc
237
- plugins
238
- ) ;
230
+ return new codeInput . templates . Prism ( prism , plugins ) ;
239
231
} ,
232
+
240
233
/**
241
- * Constructor to create a template that uses highlight.js syntax highlighting (https://highlightjs.org/)
242
- * @param {Object } hljs Import highlight.js, then after that import pass the `hljs` object as this parameter.
243
- * @param {codeInput.Plugin[] } plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
244
- * @returns {codeInput.Template } template object
234
+ * @deprecated Please use `new codeInput.templates.Hljs(...)`
245
235
*/
246
236
hljs ( hljs , plugins = [ ] ) { // Dependency: Highlight.js (https://highlightjs.org/)
247
- return new codeInput . Template (
248
- function ( codeElement ) {
249
- codeElement . removeAttribute ( "data-highlighted" ) ;
250
- hljs . highlightElement ( codeElement ) ;
251
- } , // highlight
252
- false , // preElementStyled
253
- true , // isCode
254
- false , // includeCodeInputInHighlightFunc
255
- plugins
256
- ) ;
237
+ return new codeInput . templates . Hljs ( hljs , plugins ) ;
257
238
} ,
258
239
259
240
/**
@@ -318,7 +299,7 @@ var codeInput = {
318
299
} ,
319
300
320
301
/**
321
- * @deprecated Please use `new codeInput.Template()`
302
+ * @deprecated Please use `new codeInput.Template(... )`
322
303
*/
323
304
custom ( highlight = function ( ) { } , preElementStyled = true , isCode = true , includeCodeInputInHighlightFunc = false , plugins = [ ] ) {
324
305
return {
@@ -1058,4 +1039,59 @@ var codeInput = {
1058
1039
}
1059
1040
}
1060
1041
1042
+ {
1043
+ // Templates are defined here after the codeInput variable is set, because they reference it by extending codeInput.Template.
1044
+
1045
+ // ESM-SUPPORT-START-TEMPLATE-prism Do not (re)move this - it's needed for ESM generation!
1046
+ /**
1047
+ * A template that uses Prism.js syntax highlighting (https://prismjs.com/).
1048
+ */
1049
+ class Prism extends codeInput . Template { // Dependency: Prism.js (https://prismjs.com/)
1050
+ /**
1051
+ * Constructor to create a template that uses Prism.js syntax highlighting (https://prismjs.com/)
1052
+ * @param {Object } prism Import Prism.js, then after that import pass the `Prism` object as this parameter.
1053
+ * @param {codeInput.Plugin[] } plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
1054
+ * @returns {codeInput.Template } template object
1055
+ */
1056
+ constructor ( prism , plugins = [ ] ) {
1057
+ super (
1058
+ prism . highlightElement , // highlight
1059
+ true , // preElementStyled
1060
+ true , // isCode
1061
+ false , // includeCodeInputInHighlightFunc
1062
+ plugins
1063
+ ) ;
1064
+ }
1065
+ } ;
1066
+ // ESM-SUPPORT-END-TEMPLATE-prism Do not (re)move this - it's needed for ESM generation!
1067
+ codeInput . templates . Prism = Prism ;
1068
+
1069
+ // ESM-SUPPORT-START-TEMPLATE-hljs Do not (re)move this - it's needed for ESM generation!
1070
+ /**
1071
+ * A template that uses highlight.js syntax highlighting (https://highlightjs.org/).
1072
+ */
1073
+ class Hljs extends codeInput . Template { // Dependency: Highlight.js (https://highlightjs.org/)
1074
+ /**
1075
+ * Constructor to create a template that uses highlight.js syntax highlighting (https://highlightjs.org/)
1076
+ * @param {Object } hljs Import highlight.js, then after that import pass the `hljs` object as this parameter.
1077
+ * @param {codeInput.Plugin[] } plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
1078
+ * @returns {codeInput.Template } template object
1079
+ */
1080
+ constructor ( hljs , plugins = [ ] ) {
1081
+ super (
1082
+ function ( codeElement ) {
1083
+ codeElement . removeAttribute ( "data-highlighted" ) ;
1084
+ hljs . highlightElement ( codeElement ) ;
1085
+ } , // highlight
1086
+ false , // preElementStyled
1087
+ true , // isCode
1088
+ false , // includeCodeInputInHighlightFunc
1089
+ plugins
1090
+ ) ;
1091
+ }
1092
+ } ;
1093
+ // ESM-SUPPORT-END-TEMPLATE-hljs Do not (re)move this - it's needed for ESM generation!
1094
+ codeInput . templates . Hljs = Hljs ;
1095
+ }
1096
+
1061
1097
customElements . define ( "code-input" , codeInput . CodeInput ) ;
0 commit comments