Skip to content

Commit

Permalink
fix baserproject#1855 [CKEditor] aタグ内にブロック要素を置くと、勝手にaタグの外に吐き出される問題を解決
Browse files Browse the repository at this point in the history
  • Loading branch information
kato committed Jul 29, 2022
1 parent 2cf4507 commit 5577477
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/Baser/View/Helper/BcCkeditorHelper.php
Expand Up @@ -317,8 +317,27 @@ function _build($fieldName, $options = [])
$jscode .= "CKEDITOR.config.extraPlugins = 'draft,showprotected';";
$jscode .= "CKEDITOR.config.stylesCombo_stylesSet = '" . $editorStylesSet . "';";
$jscode .= "CKEDITOR.config.protectedSource.push( /<\?[\s\S]*?\?>/g );";
$jscode .= 'CKEDITOR.dtd.$removeEmpty["i"] = false;'; // 空「i」タグを消さないようにする
$jscode .= 'CKEDITOR.dtd.$removeEmpty["span"] = false;'; // 空「span」タグを消さないようにする
/* CkEditorの自動整形のコントロール /app/Config/setting.phpで上書き可能 */
if (Configure::read('CkeditorConfig.dtd')) {
$dtd = Configure::read('CkeditorConfig.dtd');
} else {
$dtd = [
// aタグ内に入れることを許可するブロック要素のタグ名リスト
'a' => ['div', 'h1', 'h2', 'h3', 'h4', 'h5', 'dl', 'p'],
// 空を許可する要素名リスト
'removeEmpty' => ['i', 'span'],
];
}
if (isset($dtd['a']) && !empty($dtd['a'])) { // aタグ内に入れることを許可するブロック要素を出力
foreach ($dtd['a'] as $a) {
$jscode .= is_string($a) ? 'CKEDITOR.dtd.a.'. $a.' = 1;' : '';
}
}
if (isset($dtd['removeEmpty']) && !empty($dtd['removeEmpty'])) { // 空を許可する要素を出力
foreach ($dtd['removeEmpty'] as $removeEmpty) {
$jscode .= is_string($removeEmpty) ? 'CKEDITOR.dtd.$removeEmpty["'.$removeEmpty .'"] = false;' : '';
}
}

if ($editorEnterBr) {
$jscode .= "CKEDITOR.config.enterMode = CKEDITOR.ENTER_BR;";
Expand Down

0 comments on commit 5577477

Please sign in to comment.