マークダウンでのエスケープの修正

This commit is contained in:
2026-04-24 19:53:45 +09:00
parent 119f9f48b6
commit 7492790a9c

View File

@@ -275,39 +275,39 @@ class Markdown {
$patterns = [ $patterns = [
// 数式 // 数式
'/\$\$([^$]+)\$\$/u' => function($matches): string { '/(?<!\\\\)\$\$([^$]+)\$\$/u' => function($matches): string {
$placeholder = "{{ALG".count($this->algebraicPlaceholder).'ALG}}'; $placeholder = "{{ALG".count($this->algebraicPlaceholder).'ALG}}';
$this->algebraicPlaceholder[$placeholder] = $matches[1]; $this->algebraicPlaceholder[$placeholder] = $matches[1];
return $placeholder; return $placeholder;
}, },
// 太字 // 太字
'/\*\*(.+?)\*\*/u' => '<strong>$1</strong>', '/(?<!\\\\)\*\*(.+?)\*\*/u' => '<strong>$1</strong>',
// 斜体 // 斜体
'/\*(.+?)\*/u' => '<em>$1</em>', '/(?<!\\\\)\*(.+?)\*/u' => '<em>$1</em>',
// 下線 // 下線
'/\_(.+?)\_/u' => '<u>$1</u>', '/(?<!\\\\)_(.+?)_/u' => '<u>$1</u>',
// 取り消し線 // 取り消し線
'/\~(.+?)\~/u' => '<s>$1</s>', '/(?<!\\\\)~(.+?)~/u' => '<s>$1</s>',
// Blink (with speed) // Blink (with speed)
'/!:\((.+?)\)(.+?):!/u' => '<span class="blink" style="animation-duration: $1s;">$2</span>', '/(?<!\\\\)!:\((.+?)\)(.+?):!/u' => '<span class="blink" style="animation-duration: $1s;">$2</span>',
// Blink // Blink
'/!:(.+?):!/u' => '<span class="blink">$1</span>', '/(?<!\\\\)!:(.+?):!/u' => '<span class="blink">$1</span>',
// フォントの大きさ // フォントの大きさ
'/\^\((.+?)\)(.+?)\^/u' => '<span style="font-size: $1px;">$2</span>', '/(?<!\\\\)\^\((.+?)\)(.+?)\^/u' => '<span style="font-size: $1px;">$2</span>',
// フォントカラー // フォントカラー
'/\%\((.+?)\)(.+?)\%/u' => '<span style="color: #$1;">$2</span>', '/(?<!\\\\)\%\((.+?)\)(.+?)\%/u' => '<span style="color: #$1;">$2</span>',
// 画像 // 画像
'/\!\[(.*?)(?:#([^\]]*))?\]\((.+?)\)/u' => '<img style="width: 100%; $2" src="$3" alt="$1" />', '/(?<!\\\\)\!\[(.*?)(?:#([^\]]*))?\]\((.+?)\)/u' => '<img style="width: 100%; $2" src="$3" alt="$1" />',
// 音楽 // 音楽
'/\$\[([^\]]+)\]\(([^\)]+)\)/u' => '<audio controls><source src="$2" type="$1" /></audio>', '/(?<!\\\\)\$\[([^\]]+)\]\(([^\)]+)\)/u' => '<audio controls><source src="$2" type="$1" /></audio>',
// 動画 // 動画
'/\#\[([^\]]+)\]\(([^\)]+)\)/u' => '<video style="max-width: 100%;" controls><source src="$2" type="$1" /></video>', '/(?<!\\\\)\#\[([^\]]+)\]\(([^\)]+)\)/u' => '<video style="max-width: 100%;" controls><source src="$2" type="$1" /></video>',
// リンク // リンク
'/\[(.+?)\]\((.+?)\)/u' => '<a href="$2">$1</a>', '/(?<!\\\\)\[(.+?)\]\((.+?)\)/u' => '<a href="$2">$1</a>',
// 振り仮名 // 振り仮名
'/\&lt;(.+?)\&gt;\((.+?)\)/u' => '<ruby>$1<rp>(</rp><rt>$2</rt><rp>)</rp></ruby>', '/(?<!\\\\)&lt;(.+?)&gt;\((.+?)\)/u' => '<ruby>$1<rp>(</rp><rt>$2</rt><rp>)</rp></ruby>',
// インラインコード // インラインコード
'/`(.+?)`/u' => '<code>$1</code>', '/(?<!\\\\)`(.+?)`/u' => '<code>$1</code>',
]; ];
foreach ($patterns as $pattern => $replacement) { foreach ($patterns as $pattern => $replacement) {
@@ -325,6 +325,8 @@ class Markdown {
$text = str_replace($placeholder, $this->parseAlgebraic($expr), $text); $text = str_replace($placeholder, $this->parseAlgebraic($expr), $text);
} }
$text = preg_replace('/\\\\(.)/u', '$1', $text);
return $text; return $text;
} }