Home > Article > Backend Development > Regarding the front-end display problem when the markdown editor replaces the ordinary visual editor, how do you solve it?
As per the title, I now have two ideas:
The first one is to use js for front-end processing. The disadvantage is that it is not friendly to search engines. I personally feel that search engines may not have high affinity for markdown text.
The second method is to convert the markdown text into HTML when outputting, so as to ensure the consistency of the code. The code output from the backend to the frontend is all HTML, but there is a bug in this method. If it is your own framework, you can change it wildly. Make it support markdown conversion, but if you develop plug-ins for others, or the development framework is already ready, it will be difficult to convert large areas in the view. How to deal with it.
I have already implemented the first one in the Chanzhi markdown editor extension. Recently I have been thinking about how to control the content output simply and effectively. I have encountered problems:
1. How to judge that the content of a string is markdown text. Content
2. How to convert markdown content in batches without changing the view template
In view of the above, I hope to share with you the solution for markdown display.
ps:
Chanzhi markdown editor uses editmd as markdown input and output.
The extension source code can be obtained through http://git.oschina.net/hainuo...
As per the title, I now have two ideas:
The first one is to use js for front-end processing. The disadvantage is that it is not friendly to search engines. I personally feel that search engines may not have high affinity for markdown text.
The second method is to convert the markdown text into HTML when outputting, so as to ensure the consistency of the code. The code output from the backend to the frontend is all HTML, but there is a bug in this method. If it is your own framework, you can change it wildly. Make it support markdown conversion, but if you develop plug-ins for others, or the development framework is already ready, it will be difficult to convert large areas in the view. How to deal with it.
I have already implemented the first one in the Chanzhi markdown editor extension. Recently I have been thinking about how to control the content output simply and effectively. I have encountered problems:
1. How to judge that the content of a string is markdown text. Content
2. How to convert markdown content in batches without changing the view template
In view of the above, I hope to share with you the solution for markdown display.
ps:
Chanzhi markdown editor uses editmd as markdown input and output.
The extension source code can be obtained through http://git.oschina.net/hainuo...
Personally, I prefer the first option.
First of all, this is more conducive to the separation of front and rear ends. For example, when the front end adapts to multiple display styles, the back end does not need to change the code.
Secondly, regarding the issue you mentioned about search engine inclusion, I think even Markdown text is very readable. Furthermore, as more and more websites are designed using asynchronous loading and single-page mode, search engines have gradually improved their crawling mechanisms. In addition, we can also directly specify key information through meta.
As for how to determine whether a string is markdown, I think there is no need to judge. If it is not markdown, even if markdown is used to parse, the output will be the most basic text.
Converting the content without changing the View actually avoids the pitfall I mentioned above, that is, back-end conversion is difficult to avoid the situation where the front-end and back-end are not separated. Conversion must involve conversion programs and view module codes. A matter of shared weal and woe.