本文整理汇总了Python中markdown.markdownFromFile函数的典型用法代码示例。如果您正苦于以下问题:Python markdownFromFile函数的具体用法?Python markdownFromFile怎么用?Python markdownFromFile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了markdownFromFile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gendoc
def gendoc(fpath, md_extensions = []):
"""generate html doc as string from source markdown file"""
if not path.isfile (fpath):
"""check path is a file"""
bottle.abort(400, 'invalid file: %s' % fpath)
@bottle.view('htdoc_head')
@tpl_data(fpath)
@tpl_utils
def htdoc_head():
"""render htdoc head template"""
return dict()
@bottle.view('htdoc_tail')
@tpl_data(fpath)
@tpl_utils
def htdoc_tail():
"""render htdoc tail template"""
return dict()
# parse markdown file
buf = io.BytesIO()
try:
markdownFromFile(input = fpath, extensions = md_extensions,
output = buf, output_format = 'html5')
except FileNotFoundError as err:
bottle.abort(404, str(err))
else:
buf.seek(0, 0)
# generate response
return htdoc_head() + buf.read().decode() + htdoc_tail()
示例2: read_page
def read_page(filename):
page = dict()
page['id'] = os.path.splitext(os.path.basename(filename))[0]
string_file = StringIO.StringIO()
markdown.markdownFromFile(input=filename, output=string_file)
page['content'] = string_file.getvalue()
return page
示例3: get
def get(self, request, *args, **kwargs):
contest_slug = kwargs['contest']
problem_letter = kwargs['problem']
problem_text = ''
contest = get_object_or_404(Contest, active=True, start__lte=now(), slug=contest_slug)
user = request.user.member
first_name = request.user.first_name
if not entry_exists(user, contest):
HttpRedirect('/contest-gateway')
problem = get_object_or_404(Problem, letter=problem_letter)
if problem not in contest.problems.all():
raise Http404
try:
buff = StringIO()
index_file = 'grader/contests/' + contest_slug + '/' + problem_letter + '.md'
markdownFromFile(input=index_file, output=buff)
problem_text = buff.getvalue()
except IOError:
raise Http404
return render(request, self.template, {'problem':problem,
'problem_text':problem_text,
'first_name':first_name,})
示例4: run
def run():
options, logging_level = parse_options()
if not options:
sys.exit(2)
logger.setLevel(logging_level)
logger.addHandler(logging.StreamHandler())
markdown.markdownFromFile(**options)
示例5: plugin_markdown
def plugin_markdown(parameters=[]):
result = []
for parameter in parameters:
filename = parameter + '.html'
markdown.markdownFromFile(parameter, filename)
result.append(filename)
return result
示例6: MakeSourceDist
def MakeSourceDist( ):
distDir = "imfit-%s/" % VERSION_STRING
final_file_list = example_file_list + misc_required_files_list + documentation_file_list
final_file_list += extras_file_list
final_file_list += funcobj_file_list
final_file_list += solvers_file_list
final_file_list += mcmc_file_list
final_file_list += core_file_list
final_file_list += python_file_list
final_file_list += testing_scripts_list
final_file_list += test_file_imfit_list
final_file_list += test_file_mcmc_list
final_file_list += test_file_makeimage_list
final_file_list += test_file_list
final_file_list.append("SConstruct")
tar = tarfile.open(SOURCE_TARFILE, 'w|gz')
for fname in final_file_list:
tar.add(distDir + fname)
tar.close()
print("Copying gzipped tar file %s to %s..." % (SOURCE_TARFILE, SOURCE_COPY_DEST_DIR))
shutil.copy(SOURCE_TARFILE, SOURCE_COPY_DEST_DIR)
print("Generating HTML version of CHANGELOG.md and copying to %s..." % (MAC_CHANGELOG_DEST))
markdown.markdownFromFile(input=MAC_CHANGELOG_MD, output=MAC_CHANGELOG_DEST)
示例7: render_markdown_from_file
def render_markdown_from_file(f, **markdown_kwargs):
"""Render Markdown text from a file stream to HTML."""
s = StringIO()
markdownFromFile(input=f, output=s, **markdown_kwargs)
html = s.getvalue()
s.close()
return html
示例8: section_to_html
def section_to_html(section):
"""
Convert a markdown file in the markdown folder and convert it
into a template snippet in the templates folder
"""
md_fil_name = 'markdown/{}.md'.format(section)
html_fil_name = 'templates/{}.html'.format(section)
markdown.markdownFromFile(input=md_fil_name, output=html_fil_name)
示例9: process_md
def process_md(md, h_str, f_str, indir, outdir):
outfilename = os.path.join(outdir, md[0:-3] + ".html")
infilename = os.path.join(indir, md)
with open(outfilename, "w") as f:
f.write(h_str)
markdownFromFile(output_format="xhtml1",input=infilename, output=f)
f.write(f_str)
示例10: _render
def _render(self):
buffer = StringIO()
self.obj.file.open()
markdown.markdownFromFile(input=self.obj.file, output=buffer, output_format="xhtml1", safe_mode="escape")
rendered = buffer.getvalue()
buffer.close()
return rendered
示例11: get_post_content
def get_post_content(dir, post_time, post_name):
file_name = os.path.join(dir, post_time + '-' + post_name + '.md')
if not os.path.exists(file_name):
return None
output = StringIO.StringIO()
markdown.markdownFromFile(input = file_name, output = output, extensions = ['markdown.extensions.tables'])
content = output.getvalue()
output.close()
return content
示例12: main
def main():
# Available output formats are:
# - "xhtml1": Outputs XHTML 1.x. Default.
# - "xhtml5": Outputs XHTML style tags of HTML 5
# - "xhtml": Outputs latest supported version of XHTML (currently XHTML 1.1).
# - "html4": Outputs HTML 4
# - "html5": Outputs HTML style tags of HTML 5
# - "html": Outputs latest supported version of HTML (currently HTML 4).
markdown.markdownFromFile(input="test.md", output="test.html", output_format="html5")
示例13: run
def run():
"""Run Markdown from the command line."""
# Parse options and adjust logging level if necessary
options, logging_level = parse_options()
if not options: sys.exit(0)
if logging_level: logging.getLogger('MARKDOWN').setLevel(logging_level)
# Run
markdown.markdownFromFile(**options)
示例14: load_legal_doc
def load_legal_doc(request, doc_name):
"""
Load a static Markdown file and return the document as a BeautifulSoup
object for easier manipulation.
"""
locale = l10n_utils.get_locale(request)
source = path.join(LEGAL_DOCS_PATH, doc_name, locale + '.md')
output = StringIO.StringIO()
if not path.exists(source):
source = path.join(LEGAL_DOCS_PATH, doc_name, 'en-US.md')
# Parse the Markdown file
md.markdownFromFile(input=source, output=output,
extensions=['attr_list', 'outline(wrapper_cls=)'])
content = output.getvalue().decode('utf8')
output.close()
soup = BeautifulSoup(content)
hn_pattern = re.compile(r'^h(\d)$')
href_pattern = re.compile(r'^https?\:\/\/www\.mozilla\.org')
# Manipulate the markup
for section in soup.find_all('section'):
level = 0
header = soup.new_tag('header')
div = soup.new_tag('div')
section.insert(0, header)
section.insert(1, div)
# Append elements to <header> or <div>
for tag in section.children:
match = hn_pattern.match(tag.name)
if match:
header.append(tag)
level = int(match.group(1))
if tag.name == 'p':
(header if level == 1 else div).append(tag)
if tag.name in ['ul', 'hr']:
div.append(tag)
if level > 3:
section.parent.div.append(section)
# Remove empty <div>s
if len(div.contents) == 0:
div.extract()
# Convert the site's full URLs to absolute paths
for link in soup.find_all(href=href_pattern):
link['href'] = href_pattern.sub('', link['href'])
# Return the HTML flagment as a BeautifulSoup object
return soup
示例15: main
def main():
base = os.path.abspath(os.path.dirname(__file__))
index = os.path.join(base, "index.html.tmpl")
readme = os.path.join(os.path.dirname(base), "README.md")
templ = open(index).read()
buf = StringIO.StringIO("rw")
markdown.markdownFromFile(input=readme, output=buf)
print templ.format(body=buf.getvalue())