1 Star 0 Fork 0

荒野無燈 / markdown-renderer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Markdown Renderer

Markdown Renderer is a very simple HTTP server written in Go. It renders Markdown documents retrieved from another (specified) HTTP server into HTML.

Markdown Renderer uses package github.com/shurcooL/github_flavored_markdown to render Markdown documents.

Package github_flavored_markdown provides a GitHub Flavored Markdown renderer with fenced code block highlighting, clickable heading anchor links.

A Use Case: Render Markdown Documents in SVN

This is a real use case, and the one that motivated me to write Markdown Renderer.

In our company, we have an SVN server, on which our code and documents reside. We would like to be able to browse our documents from the Web browser, in particular, we want those documents in Markdown syntax being renderred to HTML. However, the SVN server is not smart enough to render Markdown documents; more than that, it does not even recognizes file types of documents and returns all documents with Content-Type: text/plain anyway.

This inspires me to set up an Nginx server, which proxy_passes all requests to the SVN server, and set the correct Content-Type by the file extension name of corresponding document. This can be done using the more_set_headers directive provided by Nginx module HttpHeadersMoreModule. Any example Nginx configuration should be like this:

server {
    location ~ \.docx$ {
        more_set_headers application/msword;
    }
    location ~ \.xlsx$ {
        more_set_headers application/vnd.ms-excel;
    }
}

However, this module is not able to render Markdown text into HTML. Indeed, I cannot find an Nginx module that can do this. I tried to write one by my own; however, had I digged into this work could I realise what a pain it is to write an Nginx filter module! This made me to resort to an alternative way, to write a separate HTTP server, instead of an Nginx module. Thus comes Markdown Renderer.

With Markdown Renderer, a new location line can be added to above example configuration:

    location ~ \.md$ {
        proxy_pass http://localhost:8002;
    }

where localhost:8002 is supposed to be the Markdown Renderer server started with proper command line flags set. For example:

 ./markdown-renderer -addr=:8002 -dataserver="http://svn-server:9006

where svn-server:9006 is just a replaceholder; you should change it to your SVN or document server.

you can also use it with local files:

./markdown-renderer -addr=:8002 -mode local -root /home/http/public_html/docs

Play with Markdown Renderer

The nginx.conf attached with this project configures two Nginx virtual servers: the document-type-recognizer server as described in above use case, and one that mimics the SVN/document server.

The recognizer server listens on localhost:8001, the Markdown Renderer server listens on localhost:8002, and the fake SVN server listens on localhost:8003. They work in a chain:

 |browser|----|:8001|----(.md files)----|:8002|----|:8003|
                     \---(other docs)-------------/

If you want to setup this configuration on your computer and play with it, these are the steps:

  1. Checkout and build Markdown Renderer:

    export ~/Projects/markdown-renderer cd ~/Projects go get github.com/ihacklog/markdown-renderer

  2. Download, build and install Nginx.

  3. Make Nginx use the configuration file provided with Markdown Renderer.

    cd /usr/local/nginx/conf # suppose that Nginx was installed here. mv nginx.conf nginx.conf.bak # backup the configuration file.

  4. (Optional) Edit nginx.conf to specify the document root directory to be where Markdown Renderer source code is.

    location / { root /home/hacklog/go/src/github.com/ihacklog/markdown-renderer; }

  5. Start Nginx.

    /usr/local/nginx/sbin/nginx

  6. Build and start Markdown Renderer

    cd ~/Projects/markdown-renderer/src/github.com/wangkuiyi/markdown-renderer go install ~/Projects/markdown-renderer/bin/markdown-renderer

  7. Direct your Web browser to http://localhost:8001 and you should see the README.md file renderred into HTML.

Trouble Shooting

Markdown Renderer requires that the Markdown filename matches the regular expression ^/([_a-zA-Z0-9]+)\\.md$).

空文件

简介

Markdown Renderer is a very simple HTTP server written in Go. It renders Markdown documents retrieved from another (specified) HTTP server into HTML. 展开 收起
Go
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/8ox86/markdown-renderer.git
git@gitee.com:8ox86/markdown-renderer.git
8ox86
markdown-renderer
markdown-renderer
master

搜索帮助