How do I handle code highlighting issues?

Source: Internet
Author: User
For code highlighting, is it processed before the database is written, or is it not written to the database and then processed to the front end after it is read out?

Please advise.

Reply content:

For code highlighting, is it processed before the database is written, or is it not written to the database and then processed to the front end after it is read out?

Please advise.

It is recommended that you read the processing, the database only need to record the original data.

code highlighting is essentially what the presentation layer should handle, and only the code snippet inside should be placed on the persistence layer .

General, your paragraph of text, a piece of code, how should display AH? What kind of font should I use? These should be the performance layers .

Given the general situation, of course there are special cases, such as those rich text editor, will be the user edit the style of the store into the database.

For example SF only saves the original content (I like this way, my blog is also), and then read out the content for a unified display. Do the content and display phase separation.

As for the QQ space, blogs, forums, generally will be CSS together with HTML previously saved to the database, give the editor enough flexibility, you can write a variety of things, such as bright blind ball text flashing.

I prefer to only record content in the database .

Usually in the front-end processing, such as Segmentfault with open-source highlight.js

Read the main meaning is iron heart ready to put on the back end did.

Obviously, it is better to write to the database before processing it, because it does not have to be highlighted each time it is read, and is processed only once when it is written.

Do not write to the database, read out and then deal with the words, more elegant. Because the database should only record content, storage and highlighting should be orthogonal to separate. This also facilitates future maintenance and modification.

Highlight the code with Google's Prettify.js

  • 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.