回答編集履歴
2
懸念事項を追加
answer
CHANGED
@@ -26,4 +26,10 @@
|
|
26
26
|
currentNode.parentElement.insertBefore(template.content,currentNode);
|
27
27
|
currentNode.parentElement.removeChild(currentNode)
|
28
28
|
}
|
29
|
-
```
|
29
|
+
```
|
30
|
+
|
31
|
+
---
|
32
|
+
|
33
|
+
なお、DOMの構造が変わるので、思わぬレイアウトになる場合があります。
|
34
|
+
|
35
|
+
たとえば、[https://jsfiddle.net/Lhankor_Mhy/L061v9yc/3/](https://jsfiddle.net/Lhankor_Mhy/L061v9yc/3/)
|
1
質問の追記に合わせて追記
answer
CHANGED
@@ -1,2 +1,29 @@
|
|
1
1
|
ご質問のご希望から外れますが、CSSのunicode-rangeを使うと、アルファベットだけフォントを変えるというようなことが可能です。
|
2
|
-
[unicode-range - CSS: カスケーディングスタイルシート | MDN](https://developer.mozilla.org/ja/docs/Web/CSS/@font-face/unicode-range)
|
2
|
+
[unicode-range - CSS: カスケーディングスタイルシート | MDN](https://developer.mozilla.org/ja/docs/Web/CSS/@font-face/unicode-range)
|
3
|
+
|
4
|
+
---
|
5
|
+
|
6
|
+
# 質問の追記に合わせて追記
|
7
|
+
|
8
|
+
既にフォントを使い分けているご様子なので、JavaScriptで処理する方法を提示します。
|
9
|
+
サンプルを置いておきます。
|
10
|
+
|
11
|
+
[https://jsfiddle.net/Lhankor_Mhy/L061v9yc/](https://jsfiddle.net/Lhankor_Mhy/L061v9yc/)
|
12
|
+
|
13
|
+
```js
|
14
|
+
const nodeIterator = document.createNodeIterator(
|
15
|
+
document.getElementById('target'),
|
16
|
+
NodeFilter.SHOW_TEXT,
|
17
|
+
{
|
18
|
+
acceptNode(node) {
|
19
|
+
return !node.parentElement.classList.contains('alphabet');
|
20
|
+
}
|
21
|
+
}
|
22
|
+
);
|
23
|
+
while (currentNode = nodeIterator.nextNode()) {
|
24
|
+
const template = document.createElement( 'template' )
|
25
|
+
template.innerHTML = currentNode.nodeValue.replace(/(\w+)/g,'<span class="alphabet">$1</span>');
|
26
|
+
currentNode.parentElement.insertBefore(template.content,currentNode);
|
27
|
+
currentNode.parentElement.removeChild(currentNode)
|
28
|
+
}
|
29
|
+
```
|