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