From 62a199cfe4ac966fda5630b3be000fc75d8889d3 Mon Sep 17 00:00:00 2001 From: ohbarye Date: Tue, 2 Aug 2016 01:48:08 +0900 Subject: [PATCH 1/3] Consider path more carefully for when markdown-server is downloaded from pip --- markdownserver/__init__.py | 5 +++-- markdownserver/env.py | 14 +++++++++----- markdownserver/markdown_converter.py | 7 ++++--- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/markdownserver/__init__.py b/markdownserver/__init__.py index 660c239..cedd2ca 100644 --- a/markdownserver/__init__.py +++ b/markdownserver/__init__.py @@ -1,14 +1,15 @@ from bottle import route,run,template,static_file from markdown_converter import MarkdownConverter from env import * +import os converter = MarkdownConverter() @route('/') def gfmize(resource): - html_file_name = converter.convert(resource) - return static_file(html_file_name, root=ms_root) + html_file_name = os.path.basename(converter.convert(resource)) + return static_file(os.path.join(html_dir, html_file_name), root=root_path) def main(): run(host=ms_host,port=ms_port,debug=ms_debug,reloader=ms_reloader) diff --git a/markdownserver/env.py b/markdownserver/env.py index 07c6e39..dd9235b 100644 --- a/markdownserver/env.py +++ b/markdownserver/env.py @@ -1,12 +1,16 @@ +import os + ms_encoding = 'utf-8' ms_port = '8009' ms_host = 'localhost' -ms_root = './' ms_debug = True ms_reloader = True html_extension = '.html' -markdown_root = 'markdownserver/resources/markdown/' -html_root = 'markdownserver/resources/html/' -css_root = 'markdownserver/resources/css/' +root_path = os.path.dirname(__file__) +resource_dir = os.path.join(root_path,'resources') +markdown_dir = os.path.join(resource_dir,'markdown') +html_dir = os.path.join(resource_dir,'html') +css_dir = os.path.join(resource_dir,'css') css_name = 'github.css' -markdown_type = 'gfm' +css_path = os.path.join(css_dir,css_name) +markdown_type = 'gfm' \ No newline at end of file diff --git a/markdownserver/markdown_converter.py b/markdownserver/markdown_converter.py index dc75849..45bf2c1 100644 --- a/markdownserver/markdown_converter.py +++ b/markdownserver/markdown_converter.py @@ -1,12 +1,13 @@ import markdown as md import codecs import sys +import os from env import * class MarkdownConverter(object): def __init__(self): - css = codecs.open(css_root + css_name,encoding=ms_encoding,mode='r') + css = codecs.open(css_path,encoding=ms_encoding,mode='r') self.html_header = ''' @@ -31,11 +32,11 @@ class MarkdownConverter(object): return self.write_html(code,src,dst) def read_md(self,file_name): - md_file = codecs.open(markdown_root + file_name,encoding=ms_encoding,mode='r') + md_file = codecs.open(os.path.join(markdown_dir, file_name),encoding=ms_encoding,mode='r') return md_file.read() def write_html(self,body,file_name,dst): - html_path = html_root + file_name + html_extension + html_path = os.path.join(html_root, file_name + html_extension) if dst != "": html_path = dst From 17209acd582bfea2896be357ee1fc2632db16a38 Mon Sep 17 00:00:00 2001 From: ohbarye Date: Tue, 2 Aug 2016 01:49:32 +0900 Subject: [PATCH 2/3] Update sample.md.html --- markdownserver/resources/html/sample.md.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/markdownserver/resources/html/sample.md.html b/markdownserver/resources/html/sample.md.html index 35876bb..7eb9bd9 100644 --- a/markdownserver/resources/html/sample.md.html +++ b/markdownserver/resources/html/sample.md.html @@ -872,7 +872,7 @@ body .markdown-body

Convert Markdown to HTML with Python

-

Markdown-server is a simple web application. It converts markdown file to HTML and response by text/html.

+

Markdown-server is a simple web application. It converts markdown file to HTML and response by text/html.

Library Dependencies

From b727c48db238f4da648326426fc13bea45c2283a Mon Sep 17 00:00:00 2001 From: ohbarye Date: Tue, 2 Aug 2016 01:54:48 +0900 Subject: [PATCH 3/3] Remove confusable command: mdsvr --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 63e424c..292e356 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ setup( ], entry_points = { 'console_scripts': [ - 'mdsvr = markdownserver:main', + 'markdownserver = markdownserver:main', 'convert = markdownserver.markdown_converter:main' ] },