How to seamlessly convert Segmentfault's current syntax format to the standard markdown format

Source: Internet
Author: User
The current syntax of the SF community is based on wikis and markdown, and more than one person has told me that this is a weird thing, and I want to get rid of it when the number of questions is not so much. That is, the full standard markdown syntax. Its grammatical parsing is not a problem at all, the Internet has a very mature analytic library.

But how do you convert the current syntax format into a standard markdown? I hope you can give us a complete solution.

Just want to have a PHP implementation class or function , input the current syntax text output markdown Format text

Reply content:

The current syntax of the SF community is based on wikis and markdown, and more than one person has told me that this is a weird thing, and I want to get rid of it when the number of questions is not so much. That is, the full standard markdown syntax. Its grammatical parsing is not a problem at all, the Internet has a very mature analytic library.

But how do you convert the current syntax format into a standard markdown? I hope you can give us a complete solution.

Just want to have a PHP implementation class or function , input the current syntax text output markdown Format text

As for this, I remember that I mentioned an idea before, that is, through meta-tags to identify, similar to the modeline of vim.

Starting from a certain point in time, the old content head is uniformly added like "!! Syntax:sgwiki "to distinguish the old wiki syntax, the new content is written by default using Markdown. Of course, you can also support more lightweight grammar tags, not limited to markdown, as long as the head has a corresponding meta-tag. For example, "!! Syntax:markdown ""!! Syntax:multimarkdown "and so on.

It is not recommended to do automatic syntax conversion, which is like parsing HTML with a RegEx, because you will never be able to consider the whole situation, and it is best to keep the user input intact, only to provide a compatibility mechanism. This is the simplest solution.

Instead of converting, add a grammar attribute to each text entry. The old entries are logged by default to the old syntax, and the new entries are recorded as markdown. It is good to call different parsing libraries based on the syntax attributes when outputting the page. Of course the future can also support more grammar, but the meaning is not big, markdown is enough for the public.

BTW, recommended with GFM https://help.github.com/articles/gith ...

Scenario: The interface is rendered HTML, if the current syntax rendered after the interface of the HTML to turn to markdown it? Then wash the library over.

The final effect is not this: the interface provides a Markdown grammar editor, and then from this new editor on-line, for the previous data, the user clicked ' Edit ' appears is the markdown syntax format, for later additions to the data, but also with markdown syntax editing.

If this is the case:

    • Need to put the previous data Wash library, with the above scenario is the most appropriate, the user can not feel the pain of functional changes.
    • Using the previous syntax rendered HTML on the current interface, converting these tml into markdown format data and then using it to clean the old data in the database ensures that the style does not change much.
    • There is no need to add two sets of editor syntax and conversion programs to the interface.

Wash the work of the library is also very large bar, support cough di small fish, so the simplest, a few steps can be done, functional expansion is better than data reconstruction.

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