回答編集履歴
2
追記修正
answer
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
完全に同じようにしようとすると「属性」等のチェックや置き換えでいろいろ面倒そうですが...
|
16
16
|
|
17
|
-
手抜きコードだとこんな感じでしょうか。これをベースにチャレンジしてみてください。
|
17
|
+
手抜きコードだとこんな感じでしょうか。これをベースにチャレンジしてみてください。(画像のテーマは、twentynineteen です。)
|
18
18
|
|
19
19
|
```
|
20
20
|
function my_filter_syntax_highlight_185228( $content ) {
|
1
追記
answer
CHANGED
@@ -5,4 +5,41 @@
|
|
5
5
|
|
6
6
|
[crayon_wp.class.php#L268](https://github.com/aramk/crayon-syntax-highlighter/blob/abd3046995efe77f0b9d6cd33da8d9db22dab886/crayon_wp.class.php#L268) で、一致する部分を探して、[public static function class_tag($matches)](https://github.com/aramk/crayon-syntax-highlighter/blob/abd3046995efe77f0b9d6cd33da8d9db22dab886/crayon_wp.class.php#L773) で、置き換えています。
|
7
7
|
|
8
|
-
[Highlighting Code Block のソースコード](https://plugins.trac.wordpress.org/browser/highlighting-code-block/trunk/highlighting-code-block.php) を見た感じでは、全ての `<pre>`タグ を置き換える処理はしていないようなので、同じような感じですべての `pre`タグを置き換えたいのであれば、[Filter_Reference/the_content](https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content) あたりを利用して、「Crayon Syntax Highlighter」が置き換えているようなコードを自分で作成するしかないと思います。
|
8
|
+
[Highlighting Code Block のソースコード](https://plugins.trac.wordpress.org/browser/highlighting-code-block/trunk/highlighting-code-block.php) を見た感じでは、全ての `<pre>`タグ を置き換える処理はしていないようなので、同じような感じですべての `pre`タグを置き換えたいのであれば、[Filter_Reference/the_content](https://codex.wordpress.org/Plugin_API/Filter_Reference/the_content) あたりを利用して、「Crayon Syntax Highlighter」が置き換えているようなコードを自分で作成するしかないと思います。
|
9
|
+
|
10
|
+
----
|
11
|
+
(2019.04.19 18:12 追記)
|
12
|
+
|
13
|
+
手抜きですが `<pre>〜</pre>` を `<div class="hcb_wrap"><pre class="prism line-numbers">〜</pre></div>` に置き換えれば見た目を近づける事はできそうです。
|
14
|
+
|
15
|
+
完全に同じようにしようとすると「属性」等のチェックや置き換えでいろいろ面倒そうですが...
|
16
|
+
|
17
|
+
手抜きコードだとこんな感じでしょうか。これをベースにチャレンジしてみてください。
|
18
|
+
|
19
|
+
```
|
20
|
+
function my_filter_syntax_highlight_185228( $content ) {
|
21
|
+
|
22
|
+
if ( is_single() && in_the_loop() && is_main_query() ) {
|
23
|
+
$content = preg_replace_callback( "|<pre>(.*?)</pre>|su",
|
24
|
+
function( $matches ){
|
25
|
+
return '<div class="hcb_wrap"><pre class="prism line-numbers"><code>'.$matches[1].'</code></pre></div>';
|
26
|
+
},
|
27
|
+
$content );
|
28
|
+
}
|
29
|
+
return $content;
|
30
|
+
}
|
31
|
+
|
32
|
+
add_filter( 'the_content', 'my_filter_syntax_highlight_185228' );
|
33
|
+
```
|
34
|
+
|
35
|
+
投稿内容:
|
36
|
+
|
37
|
+

|
38
|
+
|
39
|
+
before:
|
40
|
+
|
41
|
+

|
42
|
+
|
43
|
+
after: (上記コードの実行例)
|
44
|
+
|
45
|
+

|