Home >Backend Development >PHP Problem >How to integrate markdown editor into php website

How to integrate markdown editor into php website

王林
王林Original
2019-09-18 17:56:273489browse

How to integrate markdown editor into php website

What is markdown?

Markdown is a markup language that can be written using an ordinary text editor. Through simple markup syntax, it can make ordinary text content have a certain format. It uses concise syntax instead of typesetting, unlike the word processing software we use, such as Word, which has a large number of typesetting and font settings. This allows us to concentrate on coding without the need for additional typesetting modifications, which is simple and convenient. Many webmaster editors like to use markdown to write articles. Platforms such as Jianshu and Open Source China support markdown editing.

You may be using different website building systems to develop websites, but don’t worry. Markdown integration is very simple. Although the systems may be different, the principles are the same. Here I use my own site as an example. , I will not explain too much about the internal integration of the Chanzhi system, but just demonstrate the overall operation process for your reference.

Operation process:

First, we need to download the interpreter showdown.js, portal: https://github.com/showdownjs/showdown

Then introduce showdown.js into the template file of the content editing page.

Introduce the following JS code:

function compile(){
    var text = document.getElementById("content").value;
    var converter = new showdown.Converter();
    var html = converter.makeHtml(text);
    document.getElementById("result").innerHTML = html;
}

In the above code, text is to get the article content of the markdown syntax you input, then instantiate the interpreter object, and then use The interpreter translates the article content you input into the target style interface content, that is, html, and then outputs it.

Note: Depending on the specific operations of different systems, some may involve the creation of database fields, etc. The introduction of code also differs due to different system architectures and expansion principles.

The above content is for reference only!

Recommended tutorial: PHP video tutorial

The above is the detailed content of How to integrate markdown editor into php website. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn