PHP markdown Implementation code for document management tools

Source: Internet
Author: User
Tags html header php compiler

This article is mainly to share with you PHP markdown Document management tool implementation code, hope to help everyone.

Main objectives:

1. Can be edited by multiple people

2. You can view it in the browser

3 A directory that can be collapsed

4. Support multi-level directory

5. Support Markdown

6. Quick and easy

After work has been engaged in PHP development, from the previous embracing to the present back to the service-side write interface, which is exposed to a few interface document management tools or systems, briefly described below:

    1. Showdoc, full-featured and concise, with users, rights management functions, support markdown, support export word, there are a variety of document templates, directory support two-level folding

    2. Confluence, powerful (Rights management, email alerts, full-text search, plug-in management, etc.), heavy, charge of a document management system

    3. Swagger, you need to write a lot of comments in your code to match

    4. Readmine, feature-rich similar to confluence, its documents are saved in TXT, can be traced back to change, can be full-text search, but writing documents a bit painful, suitable for task/bug tracking management, etc.

    5. Gitbook, Nodejs installation, support markdown, support NPM plug-in, the left of the collapsible directory tree will need to install plug-ins, you can also install search plugins, directories are separate markdown files, I use the feeling from MD to HTML compilation too slow (600+ document, To compile more than 25 minutes, if you have incremental compilation or improve the speed of the plug-in also please enlighten

Workaround:

    1. It can be implemented in combination with Git, which can also take advantage of GIT's rights management capabilities

    2. Need to compile markdown into an HTML file to deploy to the intranet

    3. Because to be viewed in the browser, this is the end of the selection of simple access, refreshing interface, no dependency on the dtree.js (not dependent on jquery)

    4. This function uses the tree's post-root sequence traversal algorithm to achieve a multi-level file read (no recursion, worried about writing to go around), just dtree.js also support multi-level directory folding

    5. Here I finally chose the Segmentfault official PHP Compiler tool Class (because they have reference to optimize a lot of similar PHP classes, thanks ~)

    6. Faster, compile more than 600 files, php time is around 2s, acceptable, and support incremental compilation; Convenient, mainly reflected in the directory is automatically generated, do not need to write the directory alone

Among the problems encountered:

Incremental compilation

Just start to determine whether an MD file needs to be compiled into HTML, is to take the MD file creation time and the last modification time to do a comparison to judge,
But later found that some of the copied, renamed files will not work with this method.
Finally, an intermediate file is used to record the time of the compiled file, and then compare with Max (creation time, last modified time) to determine if a compilation is required.

Delete redundant files

During subsequent use, it was found that some MD documents were deleted, but the final compiled files were not deleted automatically.
Therefore, at compile time, the MD file and the final HTML file will sit a difference, delete those extra HTML files

Integrated Dtree.js

First, dtree.js requires a certain amount of JSON data to display the table of contents and to expand and collapse the interaction
Also, dtree.js font is relatively small, his picture, style, script files are relative paths, I have made the corresponding changes to the path, so that it is based on the absolute path of the current domain name, so that the deployment to different domain name is not modified dtree.js code of the hierarchy directory

Assemble, beautify HTML

The assembly is written in advance of the HTML header, bottom, sidebar, and other HTML code, and then to the content of the post-compilation content, and then put it in the corresponding folder
Landscaping, this is mainly because the Segmentfault official compiler tool does not add a style to the HTML elements (for example, table, code), and I find here GitHub's relevant CSS style has been beautified

Multi-level directory support

It also cost me a lot of brain cells to write, when the university wrote dynamic Huffman code when the tree was written over the traversal,
This thought is very familiar, who knows to toss until 3 o'clock in the night to finally write well, this function is also considered one of the core components.

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.