Compare commits
10 Commits
57c2012cd9
...
bf069d12c3
| Author | SHA1 | Date | |
|---|---|---|---|
| bf069d12c3 | |||
| 1c4f1d8176 | |||
| 037ddffc26 | |||
| 859e51c539 | |||
| 7324d5ca6c | |||
| 8bdb514add | |||
| 4a5a1ff5f6 | |||
| 72ba82b09e | |||
| 70ece88089 | |||
| db22fbfa34 |
@@ -0,0 +1,2 @@
|
||||
markdownserver/resources/html/sample.md.html linguist-documentation
|
||||
markdownserver/resources/css/github.css linguist-vendored
|
||||
+2
-3
@@ -12,9 +12,8 @@ How to use
|
||||
Runtime Environment
|
||||
--------------------
|
||||
|
||||
:Python: 2.7.9
|
||||
:pip: 6.1.1
|
||||
:virtualenv: 12.1.1
|
||||
:Python: 3.7
|
||||
:pip: 19.1.1
|
||||
|
||||
|
||||
--------------------
|
||||
|
||||
@@ -1,23 +1,32 @@
|
||||
from bottle import route,run,template,static_file
|
||||
from markdown_converter import MarkdownConverter
|
||||
from env import *
|
||||
from __future__ import absolute_import
|
||||
from bottle import route, run, static_file
|
||||
from .markdown_converter import MarkdownConverter
|
||||
from .env import root_path, ms_host, ms_port, ms_debug
|
||||
import os
|
||||
|
||||
converter = MarkdownConverter()
|
||||
|
||||
|
||||
@route('/<resource:re:.*\.md>')
|
||||
@route(r'/<resource:re:.*\.md>')
|
||||
def gfmize(resource):
|
||||
if resource == 'favicon.ico':
|
||||
return ''
|
||||
|
||||
html_file_name = os.path.basename(converter.convert(resource))
|
||||
if '/' in resource:
|
||||
html_file_name = '/'.join(resource.split('/')[:-1]) + '/' + html_file_name
|
||||
return static_file(os.path.join('resources/html', html_file_name), root=root_path)
|
||||
html_file_name = '/'.join(resource.split('/')[:-1]) + \
|
||||
'/' + html_file_name
|
||||
return static_file(os.path.join('resources/html',
|
||||
html_file_name),
|
||||
root=root_path)
|
||||
|
||||
|
||||
def main():
|
||||
run(host=ms_host,port=ms_port,debug=ms_debug,reloader=ms_reloader)
|
||||
run(host=ms_host,
|
||||
port=ms_port,
|
||||
debug=ms_debug,
|
||||
reloader=False)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
+14
-14
@@ -1,16 +1,16 @@
|
||||
import os
|
||||
|
||||
ms_encoding = 'utf-8'
|
||||
ms_port = '8009'
|
||||
ms_host = 'localhost'
|
||||
ms_debug = True
|
||||
ms_reloader = True
|
||||
html_extension = '.html'
|
||||
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'
|
||||
css_path = os.path.join(css_dir,css_name)
|
||||
markdown_type = 'gfm'
|
||||
ms_encoding = "utf-8"
|
||||
ms_port = "8009"
|
||||
ms_host = "localhost"
|
||||
ms_debug = True
|
||||
ms_reloader = True
|
||||
html_extension = ".html"
|
||||
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"
|
||||
css_path = os.path.join(css_dir, css_name)
|
||||
markdown_type = "gfm"
|
||||
|
||||
@@ -1,61 +1,75 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import
|
||||
from builtins import object
|
||||
import markdown as md
|
||||
import codecs
|
||||
import sys
|
||||
import os
|
||||
from env import *
|
||||
from .env import css_path, ms_encoding, markdown_type, \
|
||||
html_dir, html_extension
|
||||
|
||||
|
||||
class MarkdownConverter(object):
|
||||
|
||||
def __init__(self):
|
||||
css = codecs.open(css_path,encoding=ms_encoding,mode='r')
|
||||
self.html_header = '''
|
||||
css = codecs.open(css_path, encoding=ms_encoding, mode="r")
|
||||
self.html_header = (
|
||||
"""
|
||||
<html>
|
||||
<head>
|
||||
<style type='text/css'>
|
||||
<!--
|
||||
''' + css.read() + \
|
||||
'''
|
||||
"""
|
||||
+ css.read()
|
||||
+ """
|
||||
//-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class='markdown-body'>
|
||||
'''
|
||||
self.html_footer = '''
|
||||
"""
|
||||
)
|
||||
self.html_footer = """
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
"""
|
||||
|
||||
def convert(self,src,dst=""):
|
||||
def convert(self, src, dst=""):
|
||||
code = md.markdown(self.read_md(src), extensions=[markdown_type])
|
||||
return self.write_html(code,src,dst)
|
||||
return self.write_html(code, src, dst)
|
||||
|
||||
def read_md(self,file_name):
|
||||
md_file = codecs.open(os.path.join(markdown_dir, file_name),encoding=ms_encoding,mode='r')
|
||||
def read_md(self, file_name):
|
||||
workingdir = os.getcwd()
|
||||
md_file = codecs.open(
|
||||
os.path.join(workingdir, file_name),
|
||||
encoding=ms_encoding,
|
||||
mode="r"
|
||||
)
|
||||
return md_file.read()
|
||||
|
||||
def write_html(self,body,file_name,dst):
|
||||
def write_html(self, body, file_name, dst):
|
||||
html_path = os.path.join(html_dir, file_name + html_extension)
|
||||
|
||||
if dst != "":
|
||||
html_path = dst
|
||||
try:
|
||||
os.makedirs('/'.join(html_path.replace('\\', '/').split('/')[:-1]))
|
||||
except OSError as exc:
|
||||
os.makedirs("/".join(html_path.replace("\\", "/").split("/")[:-1]))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
html_file = codecs.open(html_path,encoding=ms_encoding,mode='w')
|
||||
html_file = codecs.open(html_path, encoding=ms_encoding, mode="w")
|
||||
html_file.write(self.html_header + body + self.html_footer)
|
||||
return html_path
|
||||
|
||||
|
||||
def main():
|
||||
args = sys.argv
|
||||
if len(args) != 3:
|
||||
print('usage: convert source_md_file target_html_file')
|
||||
print("usage: convert source_md_file target_html_file")
|
||||
else:
|
||||
converter = MarkdownConverter()
|
||||
converter.convert(args[1],args[2])
|
||||
converter.convert(args[1], args[2])
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
bottle==0.12.8
|
||||
bottle==0.12.19
|
||||
linecache2==1.0.0
|
||||
Markdown==2.6.2
|
||||
-e git+https://github.com/ohbarye/markdown-server@f85a63ba06ca7cb5beb59bd96153d7ba1fa867ae#egg=markdownserver-master
|
||||
py-gfm==0.1.0
|
||||
Pygments==2.0.2
|
||||
Pygments==2.7.4
|
||||
six==1.9.0
|
||||
traceback2==1.4.0
|
||||
unittest2==1.0.1
|
||||
|
||||
@@ -1,44 +1,42 @@
|
||||
import os
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
|
||||
def read_file(filename):
|
||||
basepath = os.path.dirname(os.path.dirname(__file__))
|
||||
filepath = os.path.join(basepath, filename)
|
||||
if os.path.exists(filepath):
|
||||
return open(filepath).read()
|
||||
else:
|
||||
return ''
|
||||
return ""
|
||||
|
||||
|
||||
setup(
|
||||
name = 'markdown-server',
|
||||
version = '0.1.3',
|
||||
description = 'A simple markdown server.',
|
||||
long_description = read_file('README.rst'),
|
||||
author = 'Masato Ohba',
|
||||
author_email = 'over.rye@gmail.com',
|
||||
url = 'https://github.com/ohbarye/markdown-server',
|
||||
classifiers = [
|
||||
'Topic :: Utilities',
|
||||
'Development Status :: 4 - Beta',
|
||||
'Framework :: Bottle',
|
||||
'License :: OSI Approved :: MIT License',
|
||||
'Programming Language :: Python',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
name="markdown-server",
|
||||
version="0.1.4",
|
||||
description="A simple markdown server.",
|
||||
long_description=read_file("README.rst"),
|
||||
author="Masato Ohba",
|
||||
author_email="over.rye@gmail.com",
|
||||
url="https://github.com/ohbarye/markdown-server",
|
||||
classifiers=[
|
||||
"Topic :: Utilities",
|
||||
"Development Status :: 4 - Beta",
|
||||
"Framework :: Bottle",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Programming Language :: Python",
|
||||
"Programming Language :: Python :: 2.7",
|
||||
"Programming Language :: Python :: 3",
|
||||
],
|
||||
packages = find_packages(),
|
||||
include_package_data = True,
|
||||
keywords = ['web', 'markdown'],
|
||||
license = 'MIT License',
|
||||
install_requires = [
|
||||
'bottle',
|
||||
'Markdown',
|
||||
'Pygments',
|
||||
'py-gfm',
|
||||
],
|
||||
entry_points = {
|
||||
'console_scripts': [
|
||||
'markdownserver = markdownserver:main',
|
||||
'convert = markdownserver.markdown_converter:main'
|
||||
packages=find_packages(),
|
||||
include_package_data=True,
|
||||
keywords=["web", "markdown"],
|
||||
license="MIT License",
|
||||
install_requires=["bottle", "Markdown==2.6.11", "Pygments", "py-gfm"],
|
||||
entry_points={
|
||||
"console_scripts": [
|
||||
"markdownserver=markdownserver:main",
|
||||
"convert=markdownserver.markdown_converter:main",
|
||||
]
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user