简体   繁体   English

从文本中删除内联样式

[英]Remove inline styles from text

I'm using Trumbowyg which is a javascript text editor. 我正在使用Trumbowyg ,它是一个javascript文本编辑器。 My problem is, when I paste text from another site into the editor, it adopts the style of the text from that site. 我的问题是,当我将另一个站点中的文本粘贴到编辑器中时,它采用了该站点中文本的样式。 How can I prevent this? 我该如何预防?

My editor is rendered in my Django template like this: 我的编辑器在Django模板中的呈现方式如下:

{{ post.content }}

Is there a template tag I can use to remove HTML? 是否可以删除HTML的模板标签? Because the external styling is inline styles, eg <span style='font-family: Arial;font-size:30px' etc..? 因为外部样式是嵌入式样式,例如<span style='font-family: Arial;font-size:30px'等。

To remove styles from a formatted paste (styles pasted from clipboard) in Trumbowyg , set the removeformatPasted option to true : 要从Trumbowyg中从格式化的粘贴(从剪贴板粘贴的样式)中删除样式,请将removeformatPasted选项设置为true

$('.trumbowyg').trumbowyg({
  removeformatPasted: true
});

But also keep in mind: 但也要记住:

  • In order to use this option, you need to define a font size in your CSS or use a reset like normalize. 为了使用此选项,您需要在CSS中定义字体大小或使用类似normalize 的重置

  • Remove format pasted is not active by default (set to false ). 默认情况下,粘贴的删除格式不处于活动状态(设置为false )。

You want to remove HTML tags? 您要删除HTML标签吗? If yes just use: 如果是,请使用:

{{ post.content|striptags }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM