0

使用 TinyMCE 4,我已经按照此处的说明配置了插件的paste_as_text选项。paste

它按预期工作,例如:

<p>&nbsp;</p>
<h1 dir="ltr" style="line-height: 1.38; margin-top: 20pt; margin-bottom: 6pt;"><span style="font-size: 20pt; font-family: Arial; color: #000000; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Requirements</span></h1>
<h3 dir="ltr" style="line-height: 1.38; margin-top: 16pt; margin-bottom: 4pt;"><span style="font-size: 14pt; font-family: Arial; color: #434343; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Nav Bar/Header</span></h3>
<ul style="margin-top: 0pt; margin-bottom: 0pt;">
<li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: #000000; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre;">
<p dir="ltr" style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 11pt; color: #000000; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Change EAT | DRINK to DISCOVER but keep this as the existing dropdown everywhere</span></p>
</li>
<li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: #000000; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre;">
<p dir="ltr" style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 11pt; color: #000000; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Change WATCH | READ to WATCH but keep this as the existing dropdown everywhere</span></p>
</li>
<li dir="ltr" style="list-style-type: disc; font-size: 11pt; font-family: Arial; color: #000000; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre;">
<p dir="ltr" style="line-height: 1.38; margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 11pt; color: #000000; font-variant-numeric: normal; font-variant-east-asian: normal; vertical-align: baseline; white-space: pre-wrap;">Keep EXPERIENCE as the existing dropdown everywhere</span></p>
</li>
</ul>

变成:

<p>Requirements<br />Nav Bar/Header<br />Change EAT | DRINK to DISCOVER but keep this as the existing dropdown everywhere<br />Change WATCH | READ to WATCH but keep this as the existing dropdown everywhere<br />Keep EXPERIENCE as the existing dropdown everywhere</p>

但是由于当我尝试设置第一行的样式时,所有的行都在一个单一<p>的行中,例如将其更改为Heading 1,因此所有文本都被格式化为那个。

我怎样才能避免这种情况?

4

1 回答 1

1

基于您选择粘贴为文本这一事实,您无法真正避免这种情况。

粘贴为文本将删除所有 HMTL 标记并仅返回“文本”,正如功能名称所暗示的那样。

然后,当您对标题 1 进行格式化之类的操作时,TinyMCE 正在获取光标所在的块并将该块转换为<h1>.

这按设计工作。

如果您只想将部分内容转换为标题,则首先需要将其放在自己的块中。通常,按下Enter会在 TinyMCE 中启动一个新块(段落),因此在您想要的文本之前和之后执行此操作会将其移动到自己的块中。

于 2019-06-10T13:18:46.027 回答