@@ -222,38 +222,19 @@ var codeInput = {
222222 * For adding small pieces of functionality, please see `codeInput.plugins`.
223223 */
224224 templates : {
225+ // (Source code for class templates after var codeInput = ... so they can extend the codeInput.Template class)
225226 /**
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(...)`
230228 */
231229 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 ) ;
239231 } ,
232+
240233 /**
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(...)`
245235 */
246236 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 ) ;
257238 } ,
258239
259240 /**
@@ -318,7 +299,7 @@ var codeInput = {
318299 } ,
319300
320301 /**
321- * @deprecated Please use `new codeInput.Template()`
302+ * @deprecated Please use `new codeInput.Template(... )`
322303 */
323304 custom ( highlight = function ( ) { } , preElementStyled = true , isCode = true , includeCodeInputInHighlightFunc = false , plugins = [ ] ) {
324305 return {
@@ -1058,4 +1039,55 @@ var codeInput = {
10581039 }
10591040}
10601041
1042+ {
1043+ // Templates are defined here after the codeInput variable is set, because they reference it by extending codeInput.Template.
1044+
1045+ /**
1046+ * A template that uses Prism.js syntax highlighting (https://prismjs.com/).
1047+ */
1048+ class Prism extends codeInput . Template { // Dependency: Prism.js (https://prismjs.com/)
1049+ /**
1050+ * Constructor to create a template that uses Prism.js syntax highlighting (https://prismjs.com/)
1051+ * @param {Object } prism Import Prism.js, then after that import pass the `Prism` object as this parameter.
1052+ * @param {codeInput.Plugin[] } plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
1053+ * @returns {codeInput.Template } template object
1054+ */
1055+ constructor ( prism , plugins = [ ] ) {
1056+ super (
1057+ prism . highlightElement , // highlight
1058+ true , // preElementStyled
1059+ true , // isCode
1060+ false , // includeCodeInputInHighlightFunc
1061+ plugins
1062+ ) ;
1063+ }
1064+ } ;
1065+ codeInput . templates . Prism = Prism ;
1066+
1067+ /**
1068+ * A template that uses highlight.js syntax highlighting (https://highlightjs.org/).
1069+ */
1070+ class Hljs extends codeInput . Template { // Dependency: Highlight.js (https://highlightjs.org/)
1071+ /**
1072+ * Constructor to create a template that uses highlight.js syntax highlighting (https://highlightjs.org/)
1073+ * @param {Object } hljs Import highlight.js, then after that import pass the `hljs` object as this parameter.
1074+ * @param {codeInput.Plugin[] } plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
1075+ * @returns {codeInput.Template } template object
1076+ */
1077+ constructor ( hljs , plugins = [ ] ) {
1078+ super (
1079+ function ( codeElement ) {
1080+ codeElement . removeAttribute ( "data-highlighted" ) ;
1081+ hljs . highlightElement ( codeElement ) ;
1082+ } , // highlight
1083+ false , // preElementStyled
1084+ true , // isCode
1085+ false , // includeCodeInputInHighlightFunc
1086+ plugins
1087+ ) ;
1088+ }
1089+ } ;
1090+ codeInput . templates . Hljs = Hljs ;
1091+ }
1092+
10611093customElements . define ( "code-input" , codeInput . CodeInput ) ;
0 commit comments