Currently, I am using github. comerusevparsedown to parse Markdown. There are two options: 1. parsing before inserting the database 2. Better to parse the output. Now I am using a https://github.com/erusev/parsedown to parse Markdown.
There are two options:
1. parsing before database insertion
2. Output Parsing
Which is better?
Reply content:
Currently I am using a https://github.com/erusev/parsedown to parse Markdown
There are two options:
1. parsing before database insertion
2. Output Parsing
Which is better?
Parsing at output time. By the way, if pseudo-static files are available, real static files can be generated, so that the html generated will be requested next time, and the database will not be read and the parsing process will be followed, when updating data, you only need to delete the original static file and re-generate the file by triggering the access again.
You can useCache (the simplest File Format)
Method, first detection when accessingcache
Whether the directory contains the corresponding html file that has been generated. If yes, the file is output directly. when data is updated in the background, the file is deleted.cache
Or directly clear the corresponding files in the directory.cache
Directory, which will be generated again during the next access.
Use frontendjs
PairMarkdown
To parse the content, the browser needs to load the correspondingjs
,js
To complete the conversion, it takes time in the middle, and the page loading needs to be parsed.Markdown
Js file (one moreHTTP
Request), instead of generating the correspondinghtml
File. It will be used directly next time.
And you don't have to consider whether the browser supports js :)
Of course, it is parsed during output (it can be cached)
What should I do if you want to edit it before parsing it into the database?
I reversed it again?
The overall consideration is of course two copies. One copy for md and one copy for parsing. Take the parsed copy for the presentation.
Of course, the output will also be parsed. However, the bottleneck of computer resources is generally in computing power. Why is it a waste of presentation.
Parse the outputmarked.js
You can.
You can also consider front-end resolution.
If the parsed data is stored, the original text cannot be edited as described in another answer.
If two copies are saved, the synchronization will take up more space.
In front-end parsing, these problems do not exist. In any case, the front-end should also look at the preview version during editing. It is better to put all the work on the front-end, and the back-end should only save the original.