Giter Club home page Giter Club logo

ngx_markdown_filter_module's Introduction

ngx_markdown_filter_module

The ngx_markdown_filter_module module is a filter that transforms markdown files to html format.

This module utilizes the cmark library.

Example configuration

location ~ \.md {
    markdown_filter on;
    markdown_template html/template.html;
}

This works on proxy locations as well.

Directives

Syntax:  markdown_filter on;
Context: location
Syntax:  markdown_template html/template.html;
Context: location

Build

  1. Clone this repo

  2. Install cmark lib with development headers

dnf install cmark-devel
  1. Download nginx src archive and unpack it

  2. Run configure script (see nginx src) and build nginx

> ./configure --add-module=/path/to/ngx_markdown_filter_module
> make
  1. Apply markdown directives to nginx conf and run it

Build with cmark-gfm (tables support)

Original cmark library doesn't support tables. But there is cmark-gfm fork with table extension, supported by Github.

  1. Clone this repo

  2. Rename config_gfm to config

  3. Install cmark-gfm lib

  4. Download nginx src archive and unpack it

  5. Run configure script (see nginx src) and build nginx

> ./configure --add-module=/path/to/ngx_markdown_filter_module --with-cc-opt=-DWITH_CMARK_GFM=1
> make
  1. Apply markdown directives to nginx conf and run it

ngx_markdown_filter_module's People

Contributors

dura0ok avatar mjsir911 avatar ukarim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ngx_markdown_filter_module's Issues

This module will not completely trnaform the whole marddown file.

Compiled successfully into nginx, run it and it will stop transform the whole markdown file into html format. my nginx.conf is as follows,

#user nobody;
worker_processes 1;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 2048; # original 1024
}

http {
include mime.types;
default_type application/octet-stream;

charset utf-8;

# try to correct ngx_markdown_filter_module
client_max_body_size 100M;
# Set the buffer size for reading client request body
client_body_buffer_size 10M;
# Set the buffer size for reading from the upstream server
proxy_buffer_size 64k;
# Set the number and size of buffers used for reading from the upstream server
proxy_buffers 8 64k;
# Set the size of the buffer used for reading from the upstream server when the connection is busy
proxy_busy_buffers_size 128k;
# Set the timeout for reading from the upstream server
proxy_read_timeout 300s;

#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                  '$status $body_bytes_sent "$http_referer" '
#                  '"$http_user_agent" "$http_x_forwarded_for"';

#access_log  logs/access.log  main;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;

#gzip  on;

server {
    listen       8888;
    server_name  localhost;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   html;
        index  index.html index.htm;
        autoindex on;
        autoindex_exact_size off;
        autoindex_localtime on;
    }

    # Render Markdown files as HTML pages using ngx_http_markdown_filter_module
    location ~ \.md$ {
        add_header Content-Type 'text/html';
        markdown_filter on;
        markdown_template /usr/local/nginx/html/template.html;
        # markdown_template html/template.html;
        # sub_filter_types *;
        # sub_filter '</body>' '<div style="padding: 20px;">$markdown$</div></body>';
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}


# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
#    listen       8000;
#    listen       somename:8080;
#    server_name  somename  alias  another.alias;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}


# HTTPS server
#
#server {
#    listen       443 ssl;
#    server_name  localhost;

#    ssl_certificate      cert.pem;
#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;
#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers  on;

#    location / {
#        root   html;
#        index  index.html index.htm;
#    }
#}

}

Feature to populate title and other head/meta data from a config file

It currently sets the title via JS looking through {{content}}. That is helpful but its not great for SEO as some indexers would miss the title that way and they can’t do anything unique to the content.

However, if this supported metadata for the content somehow like front matter in foo.md (or external .foo.json but front matter feels more ideal).

Example

Markdown file:

---
title: title here
meta:
  robots:
    - index
    - nofollow
  description: "description here"
---

# My page

Lorum Ipsom …

markdown_template

<meta charset="utf-8">
<meta name="robots" content="{{meta.robots}}">
<meta name="description" content="{{meta.description}}">

<title>{{title}}</title>

rendered as

<meta charset="UTF-8">
<meta name="robots" content="index, nofollow">
<meta name="description" content="description here">

<title>title here</title>

Support for doing 1 or more link/script/etc tags could be a round 2 thing if it too crazy but Ienvision like:

TAG_NAME::
  - attr1: val1
    attr2: val2
  - attr1: val3
    attr2: val4
  - attr3: val5
    attr4: val6
    .content : "I am content"

Rendering as:

<TAG_NAME attr1="val1" attr2="val12"/>
<TAG_NAME attr1="val1" attr3="val14"/>
<TAG_NAME attr3="val4" attr5="val15"/>I am content</TAG_NAME>

Perhaps the loop syntax can be borrowed from a common existing template format.

Tagging release

Hello, nice work on the module. Is it stable? If it is, please tag a release version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.