【问题标题】:TinyMCE5: Remove <strong> from within all h1-h6 elementsTinyMCE5:从所有 h1-h6 元素中删除 <strong>
【发布时间】:2020-05-21 11:37:16
【问题描述】:

默认情况下,TinyMCE 允许h1--h6 元素包含&lt;strong&gt; 元素,但这是有问题的,因为对于某些字体,标题标签的默认强权重随后会通过额外权重添加,这看起来很糟糕。

我尝试过使用valid_children 选项:

valid_children : '-h1[strong],-h2[strong],-h3[strong],-h4[strong],-h5[strong],-h6[strong]'

但是,虽然这会阻止在 h1--h6 上实现 &lt;strong&gt;,但它通过删除 h1-h6 元素并用 p 元素替换这些元素来解决现有情况:

<h3><strong>Subtitle goes here</strong></h3>

转换成:

<p><strong>Subtitle goes here</strong></p>

然而,期望的行为是:

<h3>Subtitle goes here</h3>

如何实现?

【问题讨论】:

    标签: tinymce tinymce-5


    【解决方案1】:

    我尝试添加这些代码:

      formats: {
        h1: { block : 'h1', styles: { fontSize: '40px', 'font-weight': 'normal' }},
        h2: { block : 'h2', styles: { fontSize: '32px', 'font-weight': 'normal' }},
        h3: { block : 'h3', styles: { fontSize: '28px', 'font-weight': 'normal' }},
        h4: { block : 'h4', styles: { fontSize: '24px', 'font-weight': 'normal' }},
        h5: { block : 'h5', styles: { fontSize: '20px', 'font-weight': 'normal' }},
        h6: { block : 'h6', styles: { fontSize: '16px', 'font-weight': 'normal' }},
      },
    

    它适用于;

    <h3><strong>Subtitle goes here</strong></h3>
    

    它可以解决你的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-17
      • 2013-03-14
      • 1970-01-01
      • 1970-01-01
      • 2012-09-01
      • 1970-01-01
      相关资源
      最近更新 更多