Skip to content

Commit

Permalink
Merge pull request #102 from WebCoder49/allow-language-attr-initially…
Browse files Browse the repository at this point in the history
…-unset

Allow language attribute to be changed after being unset
  • Loading branch information
WebCoder49 committed May 27, 2024
2 parents 493e3d7 + 781489e commit c9661d1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions code-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,15 @@ var codeInput = {
if (code.classList.contains(`language-${newValue}`)) break; // Already updated
}

if(oldValue !== null) {
// Case insensitive
oldValue = oldValue.toLowerCase();

// Case insensitive
oldValue = oldValue.toLowerCase();

// Remove old language class and add new
code.classList.remove("language-" + oldValue); // From codeElement
code.parentElement.classList.remove("language-" + oldValue); // From preElement
// Remove old language class and add new
code.classList.remove("language-" + oldValue); // From codeElement
code.parentElement.classList.remove("language-" + oldValue); // From preElement
}
// Add new language class
code.classList.remove("language-none"); // Prism
code.parentElement.classList.remove("language-none"); // Prism

Expand Down
2 changes: 1 addition & 1 deletion tests/hljs.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h4><a href="prism.html">Test for Prism.js</a></h4>

<details id="collapse-results"><summary>Test Results (Click to Open)</summary><pre id="test-results"></pre></details>
<form method="GET" action="https://google.com/search" target="_blank">
<code-input language="JavaScript" name="q">console.log("Hello, World!");
<code-input name="q">console.log("Hello, World!");
// A second line
// A third line with &lt;html> tags</code-input>
<input type="submit" value="Search Google For Code"/>
Expand Down
2 changes: 1 addition & 1 deletion tests/prism.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h4><a href="hljs.html">Test for highlight.js</a></h4>

<details id="collapse-results"><summary>Test Results (Click to Open)</summary><pre id="test-results"></pre></details>
<form method="GET" class="line-numbers" action="https://google.com/search" target="_blank">
<code-input language="JavaScript" name="q">console.log("Hello, World!");
<code-input name="q">console.log("Hello, World!");
// A second line
// A third line with &lt;html> tags</code-input>
<input type="submit" value="Search Google For Code"/>
Expand Down
4 changes: 2 additions & 2 deletions tests/tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ console.log("I've got another line!", 2 &lt; 3, "should be true.");`);
if(!isHLJS) {
// Highlight.js has autodetect plugin that should make this fail, so don't run these tests with it.
testAssertion("Core", "Language attribute Initial value",
codeInputElement.codeElement.classList.contains("language-javascript")
!codeInputElement.codeElement.classList.contains("language-javascript")
&& !codeInputElement.codeElement.classList.contains("language-html"),
`Language set to JavaScript but code element's class name is ${codeInputElement.codeElement.className}.`);
`Language unset but code element's class name is ${codeInputElement.codeElement.className}.`);

codeInputElement.setAttribute("language", "HTML");

Expand Down

0 comments on commit c9661d1

Please sign in to comment.