Skip to content

Commit 1663fab

Browse files
authored
Merge pull request #155 from WebCoder49/specialchars-and-findandreplace
Add special characters inside their generated spans so find and replace counts them
2 parents 3aeb959 + 4e1790c commit 1663fab

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

plugins/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Files: [prism-line-numbers.css](./prism-line-numbers.css) (NO JS FILE)
6161
Render special characters and control characters as a symbol
6262
with their hex code.
6363

64+
**Please note: This plugin is known to contain bugs, especially when used with highlight.js and/or other plugins. Please bear this in mind and look at the Issues if you want more details; fixes for the bugs are planned but not prioritised as much as those used in more common plugins or the core library.**
65+
6466
Files: [special-chars.js](./special-chars.js) / [special-chars.css](./special-chars.css)
6567

6668
[🚀 *CodePen Demo*](https://codepen.io/WebCoder49/pen/jOeYJbm)

plugins/special-chars.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
vertical-align: middle;
3838
outline: 0.1px solid currentColor;
3939

40+
/* Contain character for use by other plugins, but hide it */
41+
color: transparent;
42+
font-size: 0;
43+
4044
--hex-0: var(
4145
--code-input_special-chars_0);
4246
--hex-1: var(
@@ -91,4 +95,4 @@
9195
height: 1.5em;
9296
bottom: -1em;
9397
content: attr(data-hex3);
94-
}
98+
}

plugins/special-chars.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ codeInput.plugins.SpecialChars = class extends codeInput.Plugin {
100100

101101
// Create element with hex code
102102
let result = document.createElement("span");
103+
result.textContent = matchChar;
103104
result.classList.add("code-input_special-char");
104105
result.style.setProperty("--hex-0", "var(--code-input_special-chars_" + hexCode[0] + ")");
105106
result.style.setProperty("--hex-1", "var(--code-input_special-chars_" + hexCode[1] + ")");
@@ -189,4 +190,4 @@ codeInput.plugins.SpecialChars = class extends codeInput.Plugin {
189190

190191
return width;
191192
}
192-
}
193+
}

0 commit comments

Comments
 (0)