diff --git a/code-input.css b/code-input.css index 01505a6..c1c2f37 100644 --- a/code-input.css +++ b/code-input.css @@ -58,8 +58,9 @@ code-input:not(.code-input_pre-element-styled) pre code, code-input.code-input_p code-input:not(.code-input_pre-element-styled) pre, code-input.code-input_pre-element-styled pre code { /* Remove all margin and padding from others */ - margin: 0px!important; - padding: 0px!important; + margin: 0!important; + padding: 0!important; + border: 0!important; } code-input textarea, code-input pre, code-input pre * { diff --git a/code-input.d.ts b/code-input.d.ts index 0612a6a..3875451 100644 --- a/code-input.d.ts +++ b/code-input.d.ts @@ -298,7 +298,7 @@ export class Template { * Constructor to create a custom template instance. Pass this into `codeInput.registerTemplate` to use it. * I would strongly recommend using the built-in simpler template `codeInput.templates.prism` or `codeInput.templates.hljs`. * @param {(codeElement: HTMLElement) => void} highlight - a callback to highlight the code, that takes an HTML `` element inside a `
` element as a parameter
-   * @param {boolean} preElementStyled - is the `
` element CSS-styled as well as the `` element? If true, `
` element's scrolling is synchronised; if false, `` element's scrolling is synchronised.
+   * @param {boolean} preElementStyled - is the `
` element CSS-styled (if so set to true), or the `` element (false)?
    * @param {boolean} isCode - is this for writing code? If true, the code-input's lang HTML attribute can be used, and the `` element will be given the class name 'language-[lang attribute's value]'.
    * @param {false} includeCodeInputInHighlightFunc - Setting this to true passes the `` element as a second argument to the highlight function.
    * @param {boolean} autoDisableDuplicateSearching - Leaving this as true uses code-input's default fix for preventing duplicate results in Ctrl+F searching from the input and result elements, and setting this to false indicates your highlighting function implements its own fix. The default fix works by moving text content from elements to CSS `::before` pseudo-elements after highlighting.
@@ -312,7 +312,7 @@ export class Template {
    * Constructor to create a custom template instance. Pass this into `codeInput.registerTemplate` to use it.
    * I would strongly recommend using the built-in simpler template `codeInput.templates.prism` or `codeInput.templates.hljs`.
    * @param {(codeElement: HTMLElement, codeInput: CodeInput) => void} highlight - a callback to highlight the code, that takes an HTML `` element inside a `
` element as a parameter
-   * @param {boolean} preElementStyled - is the `
` element CSS-styled as well as the `` element? If true, `
` element's scrolling is synchronised; if false, `` element's scrolling is synchronised.
+   * @param {boolean} preElementStyled - is the `
` element CSS-styled (if so set to true), or the `` element (false)?
    * @param {boolean} isCode - is this for writing code? If true, the code-input's lang HTML attribute can be used, and the `` element will be given the class name 'language-[lang attribute's value]'.
    * @param {true} includeCodeInputInHighlightFunc - Setting this to true passes the `` element as a second argument to the highlight function.
    * @param {boolean} autoDisableDuplicateSearching - Leaving this as true uses code-input's default fix for preventing duplicate results in Ctrl+F searching from the input and result elements, and setting this to false indicates your highlighting function implements its own fix. The default fix works by moving text content from elements to CSS `::before` pseudo-elements after highlighting.
@@ -360,9 +360,10 @@ export namespace templates {
     * Constructor to create a template that uses Prism.js syntax highlighting (https://prismjs.com/)
     * @param {Object} prism Import Prism.js, then after that import pass the `Prism` object as this parameter.
     * @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
+    * @param {boolean} preElementStyled - Defaults to true, which should be right for most themes. If the styling is broken, change to false. (See `codeInput.Template` constructor's definition.)
     * @returns template object
     */
-    constructor(prism: Object, plugins?: Plugin[])
+    constructor(prism: Object, plugins?: Plugin[], preElementStyled?: boolean)
   }
   // ESM-SUPPORT-END-TEMPLATE-prism Do not (re)move this - it's needed for ESM generation
   /**
@@ -378,9 +379,10 @@ export namespace templates {
     * Constructor to create a template that uses highlight.js syntax highlighting (https://highlightjs.org/)
     * @param {Object} hljs Import highlight.js, then after that import pass the `hljs` object as this parameter.
     * @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
+    * @param {boolean} preElementStyled - Defaults to false, which should be right for most themes. If the styling is broken, change to true. (See `codeInput.Template` constructor's definition.)
     * @returns template object
     */
-    constructor(hljs: Object, plugins?: Plugin[])
+    constructor(hljs: Object, plugins?: Plugin[], preElementStyled?: boolean)
   }
   // ESM-SUPPORT-END-TEMPLATE-hljs Do not (re)move this - it's needed for ESM generation
   /**
diff --git a/code-input.js b/code-input.js
index 4b391c8..606d550 100644
--- a/code-input.js
+++ b/code-input.js
@@ -162,7 +162,7 @@ var codeInput = {
          * Constructor to create a custom template instance. Pass this into `codeInput.registerTemplate` to use it.
          * I would strongly recommend using the built-in simpler template `codeInput.templates.prism` or `codeInput.templates.hljs`.
          * @param {(codeElement: HTMLCodeElement, codeInput?: codeInput.CodeInput) => void} highlight - a callback to highlight the code, that takes an HTML `` element inside a `
` element as a parameter
-         * @param {boolean} preElementStyled - is the `
` element CSS-styled as well as the `` element? If true, `
` element's scrolling is synchronised; if false, `` element's scrolling is synchronised.
+         * @param {boolean} preElementStyled - is the `
` element CSS-styled (if so set to true), or the `` element (false)?
          * @param {boolean} isCode - is this for writing code? If true, the code-input's lang HTML attribute can be used, and the `` element will be given the class name 'language-[lang attribute's value]'.
          * @param {boolean} includeCodeInputInHighlightFunc - Setting this to true passes the `` element as a second argument to the highlight function.
          * @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.Plugin`
@@ -1049,12 +1049,13 @@ var codeInput = {
         * Constructor to create a template that uses Prism.js syntax highlighting (https://prismjs.com/)
         * @param {Object} prism Import Prism.js, then after that import pass the `Prism` object as this parameter.
         * @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
+        * @param {boolean} preElementStyled - Defaults to true, which should be right for most themes. If the styling is broken, change to false. (See `codeInput.Template` constructor's definition.)
         * @returns {codeInput.Template} template object
         */
-        constructor(prism, plugins = []) {
+        constructor(prism, plugins = [], preElementStyled = true) {
             super(
                 prism.highlightElement, // highlight
-                true, // preElementStyled
+                preElementStyled, // preElementStyled
                 true, // isCode
                 false, // includeCodeInputInHighlightFunc
                 plugins
@@ -1073,15 +1074,16 @@ var codeInput = {
          * Constructor to create a template that uses highlight.js syntax highlighting (https://highlightjs.org/)
          * @param {Object} hljs Import highlight.js, then after that import pass the `hljs` object as this parameter.
          * @param {codeInput.Plugin[]} plugins - An array of plugin objects to add extra features - see `codeInput.plugins`
+         * @param {boolean} preElementStyled - Defaults to false, which should be right for most themes. If the styling is broken, change to true. (See `codeInput.Template` constructor's definition.)
          * @returns {codeInput.Template} template object
          */
-        constructor(hljs, plugins = []) {
+        constructor(hljs, plugins = [], preElementStyled = false) {
             super(
                 function(codeElement) {
                     codeElement.removeAttribute("data-highlighted");
                     hljs.highlightElement(codeElement);
                 }, // highlight
-                false, // preElementStyled
+                preElementStyled, // preElementStyled
                 true, // isCode
                 false, // includeCodeInputInHighlightFunc
                 plugins
diff --git a/plugins/prism-line-numbers.css b/plugins/prism-line-numbers.css
index e8c4c0c..14c5729 100644
--- a/plugins/prism-line-numbers.css
+++ b/plugins/prism-line-numbers.css
@@ -4,9 +4,9 @@
  * https://prismjs.com/plugins/line-numbers/
  * Files: prism-line-numbers.css
  */
-/* Update padding to match line-numbers plugin, and decrease width likewise */
-code-input.line-numbers textarea, code-input.line-numbers.code-input_pre-element-styled pre,
-.line-numbers code-input textarea, .line-numbers code-input.code-input_pre-element-styled pre {
+/* Update padding to match line-numbers plugin */
+code-input.line-numbers textarea, code-input.line-numbers.code-input_pre-element-styled pre, code-input.line-numbers:not(.code-input_pre-element-styled) pre code,
+.line-numbers code-input textarea, .line-numbers code-input.code-input_pre-element-styled pre, .line-numbers code-input:not(.code-input_pre-element-styled) pre code {
   padding-left: max(3.8em, var(--padding, 16px))!important;
 }
 
diff --git a/tests/i18n.html b/tests/i18n.html
index ed6321d..968f719 100644
--- a/tests/i18n.html
+++ b/tests/i18n.html
@@ -58,8 +58,8 @@
         
 
         
+