Fixed the font inconsistency problem of website articles by using Python regular expressions.

Source: Internet
Author: User

The font defined under the large frame of the website, including the font size and color.ArticleIt may be text copied from other websites. The copy process also retains the font description information. When the document is displayed on the page, the font defined in the document is used by default. If the font in the document does not exist, the global font defined under the big frame is displayed. Therefore, the content of the website may look messy. Some articles have a large font and some others have a small font and are not beautiful. Just fine if it can be unified!

I am not familiar with HTML, CSS, and so on. I don't know if I can set it to invalidate the font content defined in the article.

Stupid people have a stupid way to modify the article in a unified manner and delete all users' font definitions! Haha! If it is manually completed, this is a very heavy task. First, you need to preview the page. If it is not uniform, modify the font. Fortunately, the editor has a "clear format" option and select all text, click OK, and then save ...... Also very troublesome

If you only want to modify the font, the most convenient way is to directly modify the database, extract the articles from the database, delete the labels related to the font, and then write them back to the database.

I checked the HTML reference manual. There are two ways to define the font:

1. Use the <font> label, for example:

 <  P  >  <  Font  Size  = "2" Face  = "Verdana"  >  This is a paragraph.  </  Font  >  </  P  >  <  P  >  <  Font  Size  = "3" Face  = "Times"  >  This is another paragraph.  </  Font  >  </  P  > 

This method is not recommended.

2. Use the style definition, for example:

<PStyle= "Font-family: verdana; font-size: 80%; color: Green">This is a paragraph with some text in it.</P>

You only need to delete the definition part of the font, and use the python Regular Expression module to replace it with no pressure:

DefFormat (data ):'''Delete all font and style labels'''P= Re. Compile (R'<Font. *?> | </Font> | style = \".*? \"') RET= P. sub ('', Data)IfRET! =Data:ReturnRETElse:ReturnNone

Python to handle database-related operations to pay attention to update the data method, you can refer to this article: http://www.cnblogs.com/ma6174/archive/2013/02/21/2920126.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.