released 0.1.1.
enabled to use conversion function alone.
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
# PythonでMarkdownをHTML化
|
||||
# Convert Markdown to HTML with Python
|
||||
|
||||
Github flavored Markdown で HTML化します。
|
||||
**Markdown-server** is a simple web application. It converts markdown file to HTML and response by text/html.
|
||||
|
||||
## 使用したライブラリ
|
||||
## Library Dependencies
|
||||
|
||||
|No.|Name|Description|
|
||||
|:-|:-|:-|
|
||||
|1|markdown|Markdown -> HTML 変換ライブラリ|
|
||||
|2|pygments|シンタックスハイライト用|
|
||||
|3|bottle|Webアプリケーションフレームワーク|
|
||||
|4|codecs|ファイル読み書き用|
|
||||
|1|markdown|Convert Markdown -> HTML|
|
||||
|2|pygments|Syntax highlighter|
|
||||
|3|bottle|Web application framework|
|
||||
|
||||
|
||||
## コードのシンタックスハイライト
|
||||
## Syntax Highlight
|
||||
|
||||
```python
|
||||
import markdown as md
|
||||
@@ -43,25 +42,33 @@ class MarkdownConverter(object):
|
||||
</html>
|
||||
'''
|
||||
|
||||
def convert(self,file_name):
|
||||
code = md.markdown(self.read_md(file_name), extensions=['gfm'])
|
||||
return self.write_html(file_name,code)
|
||||
def convert(self,src,dst=""):
|
||||
code = md.markdown(self.read_md(src), extensions=[markdown_type])
|
||||
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')
|
||||
return md_file.read()
|
||||
|
||||
def write_html(self,file_name,body):
|
||||
def write_html(self,body,file_name,dst):
|
||||
html_path = html_root + file_name + html_extension
|
||||
|
||||
if dst != "":
|
||||
html_path = dst
|
||||
|
||||
html_file = codecs.open(html_path,encoding=ms_encoding,mode='w')
|
||||
html_file.write(self.html_header + body + self.html_footer)
|
||||
return html_path
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
args = sys.argv
|
||||
if len(args) == 1:
|
||||
print('specify *.md file name from command line.')
|
||||
if len(args) != 3:
|
||||
print('usage: convert source_md_file target_html_file')
|
||||
else:
|
||||
converter = MarkdownConverter()
|
||||
converter.convert(args[1])
|
||||
converter.convert(args[1],args[2])
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user