Created
January 25, 2012 03:27
-
-
Save ikasamt/1674544 to your computer and use it in GitHub Desktop.
RestructuredTextを構築する関数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import docutils.core | |
def render_restructured_text(src): | |
settings = { | |
"stylesheet": "", | |
"stylesheet_path": None, | |
} | |
html = docutils.core.publish_string(src, writer_name='html', settings_overrides=settings) | |
html = html[html.find('<body>')+6:html.find('</body>')].strip() | |
return html | |
def read_as_restructured_text(filename): | |
text = open("memo/%s" % filename).read() | |
html = render_restructured_text(text) | |
return html | |
if __name__ == '__main__': | |
src = """\ | |
* foo | |
* bar | |
* baz | |
""" | |
print render_restructured_text(src) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment