[英]php library that can merge stylesheet with inline style
I am working with html document generated from Micrsoft Word 2007/2010. 我正在使用从Micrsoft Word 2007/2010生成的html文档。 Besides generating incredibly dirty html, word also has the tendency of using both block and inline style.
除了生成令人难以置信的脏HTML之外,单词还具有使用块和内联样式的趋势。 I am looking for a php library would merge block into already existing inline style element.
我正在寻找一个PHP库将块合并到已经存在的内联样式元素。
Edit The goal is to construct a html block preserve the original formatting and editable in WYSIWYG editor like tinyMCE 编辑目标是构建一个html块保留原始格式,并在WYSIWYG编辑器中编辑,如tinyMCE
Example 例
If the original html is: 如果原始的html是:
<html>
<head>
<style>
.normaltext {color:black;font-weight:normal;font-size:10pt}
.important {color:red;font-weight:bold;font-size:11pt}
</style>
<body>
<p class="normaltext" style="font-family:arial">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
In ut erat id dui mollis faucibus. Mauris eu neque et eros tempus placerat.
<span class="important">Nam in purus nisi</span>, vitae dictum ligula.
Morbi mattis eros eget diam vulputate imperdiet.
<span class="important" style="color:green">Integer</span> a metus eros.
Sed iaculis porta imperdiet.
</p>
</body>
</html>
Should become: 应该成为:
<html>
<head>
<body>
<p style="font-family:arial;color:black;font-weight:normal;font-size:10pt">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
In ut erat id dui mollis faucibus. Mauris eu neque et eros tempus placerat.
<span style="color:red;font-weight:bold;font-size:11pt">Nam in purus nisi</span>, vitae dictum ligula.
Morbi mattis eros eget diam vulputate imperdiet.
<span style="color:green;font-weight:bold;font-size:11pt">Integer</span> a metus eros.
Sed iaculis porta imperdiet.
</p>
</body>
</html>
请参阅CssToInlineStyles项目,它完全符合您的要求。
Check out: 查看:
Porting code from either of the sources to PHP, or using any of the available APIs should do the trick of getting your CSS styling inline. 将代码从任一源代码移植到PHP,或者使用任何可用的API,都可以将CSS样式内联到内联。
I finally managed to get it to work. 我终于设法让它发挥作用。 The code is based off of http://blog.verkoyen.eu/blog/p/detail/convert-css-to-inline-styles-with-php with once simple change: Moving the line
该代码基于http://blog.verkoyen.eu/blog/p/detail/convert-css-to-inline-styles-with-php , 只需进行一次简单的更改:移动线
// add new properties into the list
foreach($rule['properties'] as $key => $value) $properties[$key] = $value;
up to the begining of the loop, right after where $properties is declared. 在声明$ properties之后,直到循环的开始。
To make this work for WordPress however, one additional change is needed. 但是,要使其适用于WordPress,需要进行一项额外的更改。 DomDocument replace &nbps;
DomDocument替换&nbps; from the document with blanks, which breaks WordPress update statement and lead to cotent being cut off.
从具有空白的文档,打破WordPress更新声明,导致强大的被切断。 Please refer to my other question for the solution: DOMDocument->saveHTML() converting
有关解决方案,请参阅我的其他问题: DOMDocument-> saveHTML()转换&nbsp; to space
到太空
This problem is detailed in https://wordpress.stackexchange.com/questions/48692/post-content-getting-cut-off-on-blank-space-on-wpdb-update . https://wordpress.stackexchange.com/questions/48692/post-content-getting-cut-off-on-blank-space-on-wpdb-update中详细介绍了此问题。 If you know why this is happening for WordPress, please post your answer there as I would very much like to find out why it is happening.
如果您知道为什么WordPress会发生这种情况,请在那里发布您的答案,因为我非常想知道它为什么会发生。
不,但尝试这一点,复制和粘贴从word到http://ckeditor.com/或tinymce等确实清理它很多,认为它仍然不完美它会让你更接近。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.