本文整理汇总了Python中pypandoc.convert函数的典型用法代码示例。如果您正苦于以下问题:Python convert函数的具体用法?Python convert怎么用?Python convert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convert函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_unicode_input
def test_unicode_input(self):
# make sure that pandoc always returns unicode and does not mishandle it
expected = u'üäöîôû{0}======{0}{0}'.format(os.linesep)
written = pypandoc.convert(u'<h1>üäöîôû</h1>', 'md', format='html')
self.assertTrue(isinstance(written, pypandoc.unicode_type))
self.assertEqualExceptForNewlineEnd(expected, written)
bytes = u'<h1>üäöîôû</h1>'.encode("utf-8")
written = pypandoc.convert(bytes, 'md', format='html')
self.assertEqualExceptForNewlineEnd(expected, written)
self.assertTrue(isinstance(written, pypandoc.unicode_type))
# Only use german umlauts in th next test, as iso-8859-15 covers that
expected = u'üäö€{0}===={0}{0}'.format(os.linesep)
bytes = u'<h1>üäö€</h1>'.encode("iso-8859-15")
# Without encoding, this fails as we expect utf-8 per default
def f():
pypandoc.convert(bytes, 'md', format='html')
self.assertRaises(RuntimeError, f)
def f():
# we have to use something which interprets '\xa4', so latin and -1 does not work :-/
pypandoc.convert(bytes, 'md', format='html', encoding="utf-16")
self.assertRaises(RuntimeError, f)
# with the right encoding it should work...
written = pypandoc.convert(bytes, 'md', format='html', encoding="iso-8859-15")
self.assertEqualExceptForNewlineEnd(expected, written)
self.assertTrue(isinstance(written, pypandoc.unicode_type))
开发者ID:thatcher,项目名称:pypandoc,代码行数:28,代码来源:tests.py
示例2: format_comment
def format_comment(self, comment):
if comment.body == "[deleted]":
return pypandoc.convert("[deleted]", "tex", format="md")
text = ""
text += self.format_comment_header(comment)
text += pypandoc.convert(comment.body, "tex", format="md")
return text
开发者ID:dhiltonp,项目名称:reddit-latex,代码行数:7,代码来源:reddit-latex.py
示例3: save_to_media
def save_to_media(request, rst_template, context, format, filename=None):
DOCUTILS_FOR = getattr(settings, 'GRIFFIN_DOCUTILS_FOR', [])
if (not PANDOC_AVAILABLE) or (format in DOCUTILS_FOR):
return save_to_media_docutils(request, rst_template, context, format, filename=None)
if not filename:
filename = _get_default_filename()
final_filename = '%s.%s'%(filename, format)
destination = os.path.join(settings.MEDIA_ROOT, 'resume_download')
destination_final = os.path.join(destination, final_filename)
destination_rst = write_rst(request, rst_template, context, filename)
# Finally, convert to the desired format.
if format == 'rst':
destination_final = destination_rst
else:
logger.debug("Converting %s to %s (with pandoc)"%(
destination_rst, destination_final))
try:
pypandoc.convert(destination_rst, format, outputfile=destination_final)
except ImportError as ie:
logger.error(ie)
return None
media_link = settings.MEDIA_URL + 'resume_download/' + final_filename
logger.debug("Media link for resume is %s"%media_link)
return media_link
开发者ID:freckles-the-pirate,项目名称:django-resume-griffin,代码行数:32,代码来源:resume_download.py
示例4: test_conversion_with_citeproc_filter
def test_conversion_with_citeproc_filter(self):
if os.environ.get('CI', None):
print("Skipping: there is a bug with citeproc on travis.")
return
# we just want to get a temp file name, where we can write to
filters = ['pandoc-citeproc']
written = pypandoc.convert('./filter_test.md', to='html', format='md',
outputfile=None, filters=filters)
import re as re
# only properly converted file will have this in it
found = re.search(r'Fenner', written)
self.assertTrue(found.group() == 'Fenner')
# only properly converted file will have this in it
found = re.search(r'10.1038', written)
self.assertTrue(found.group() == '10.1038')
# make sure that it splits the filter line
for filters in ['pandoc-citeproc', u'pandoc-citeproc']:
written = pypandoc.convert('./filter_test.md', to='html', format='md',
outputfile=None, filters=filters)
# only properly converted file will have this in it
found = re.search(r'Fenner', written)
self.assertTrue(found.group() == 'Fenner')
# only properly converted file will have this in it
found = re.search(r'10.1038', written)
self.assertTrue(found.group() == '10.1038')
开发者ID:gwgundersen,项目名称:pypandoc,代码行数:27,代码来源:tests.py
示例5: end_novel
def end_novel(css=None):
out_file.close()
if css is None:
pypandoc.convert(md_file_path, 'html', outputfile=html_file_path, extra_args=['-s'])
else:
pypandoc.convert(md_file_path, 'html', outputfile=html_file_path, extra_args=['-s', '-c', css])
print('Total words: ' + str(word_count))
开发者ID:mattfister,项目名称:freezeword,代码行数:7,代码来源:md_writer.py
示例6: ex_edit
def ex_edit(request, pk):
exercice = get_object_or_404(Exercice, pk=pk)
if request.method == "POST":
form = ExoForm(request.POST, instance=exercice)
if form.is_valid():
exercice = form.save(commit=False)
exercice.pub_date = timezone.now()
if exercice.enonce_latex:
exercice.enonce_html = pypandoc.convert(exercice.enonce_latex,'html5',format='latex',extra_args=['--mathjax','--smart'])
if exercice.indication_latex:
exercice.indication_html = pypandoc.convert(exercice.indication_latex,'html5',format='latex',extra_args=['--mathjax','--smart'])
exercice.save()
form.save_m2m()
group_name = 'PUBLIC'
group = Group.objects.get(name=group_name)
perm_codename = 'see_exercice_{0}'.format(pk)
perm = get_object_or_404(Permission,codename=perm_codename)
if exercice.get_visibility_display() == 'Public':
group.permissions.add(perm)
elif perm in group.permissions.all():
group.permissions.remove(perm)
return redirect('detail', exercice_id=pk)
else:
form = ExoForm(instance=exercice)
return render(request, 'exobase/exercice_edit.html', {'form': form, 'exercice': exercice})
开发者ID:automathproject,项目名称:protomath,代码行数:26,代码来源:views.py
示例7: common_setup
def common_setup(src_dir):
readme_file = 'README.md'
changelog_file = 'CHANGES.md'
version_file = 'VERSION'
# Convert Markdown to RST for PyPI
try:
import pypandoc
long_description = pypandoc.convert(readme_file, 'rst')
changelog = pypandoc.convert(changelog_file, 'rst')
except (IOError, ImportError, OSError):
long_description = open(readme_file).read()
changelog = open(changelog_file).read()
# Gather trailing arguments for pytest, this can't be done using setuptools' api
if 'test' in sys.argv:
PyTest.pytest_args = sys.argv[sys.argv.index('test') + 1:]
if PyTest.pytest_args:
sys.argv = sys.argv[:-len(PyTest.pytest_args)]
PyTest.src_dir = src_dir
return dict(
# Version is shared between all the projects in this repo
version=open(version_file).read().strip(),
long_description='\n'.join((long_description, changelog)),
url='https://github.com/manahl/pytest-plugins',
license='MIT license',
platforms=['unix', 'linux'],
cmdclass={'test': PyTest},
setup_requires=['setuptools-git'],
include_package_data=True
)
开发者ID:msarahan,项目名称:pytest-plugins,代码行数:32,代码来源:common_setup.py
示例8: test_conversion_from_markdown_with_extensions
def test_conversion_from_markdown_with_extensions(self):
input = u'~~strike~~'
expected_with_extension = u'<p><del>strike</del></p>'
expected_without_extension = u'<p><sub><sub>strike</sub></sub></p>'
received_with_extension = pypandoc.convert(input, 'html', format=u'markdown+strikeout')
received_without_extension = pypandoc.convert(input, 'html', format=u'markdown-strikeout')
self.assertEqualExceptForNewlineEnd(expected_with_extension, received_with_extension)
self.assertEqualExceptForNewlineEnd(expected_without_extension, received_without_extension)
开发者ID:thatcher,项目名称:pypandoc,代码行数:8,代码来源:tests.py
示例9: render_doc_
def render_doc_(notebook, output_format, output_file, template, extra_args):
""""""
pypandoc.convert(
source=template.render(notebook), to="pdf" if output_format == "pdf" else output_format,
format="markdown-blank_before_header",
outputfile=output_file,
extra_args=extra_args
)
开发者ID:eliasah,项目名称:airship-convert,代码行数:8,代码来源:document.py
示例10: do_one_round
def do_one_round():
# get all posts from starting point to now
now = pytz.utc.localize(datetime.now())
start = get_start(feed_file)
print "Collecting posts since %s" % start
sys.stdout.flush()
posts = get_posts_list(load_feeds(), start)
posts.sort()
print "Downloaded %s posts" % len(posts)
if posts:
print "Compiling newspaper"
sys.stdout.flush()
result = html_head + u"\n".join([html_perpost.format(**nicepost(post)) for post in posts]) + html_tail
# with codecs.open('dailynews.html', 'w', 'utf-8') as f:
# f.write(result)
print "Creating epub"
sys.stdout.flush()
os.environ["PYPANDOC_PANDOC"] = PANDOC
ofile = "dailynews.epub"
oofile = "dailynews.mobi"
pypandoc.convert(
result,
to="epub3",
format="html",
outputfile=ofile,
extra_args=["--standalone", "--epub-cover-image=cover.png"],
)
print "Converting to kindle"
sys.stdout.flush()
os.system("%s %s -o %s >/dev/null 2>&1" % (KINDLE_GEN, ofile, oofile))
print "Sending to kindle email"
sys.stdout.flush()
send_mail(
send_from=EMAIL_FROM,
send_to=[KINDLE_EMAIL],
subject="Daily News",
text="This is your daily news.\n\n--\n\n",
files=[oofile],
)
print "Cleaning up."
sys.stdout.flush()
os.remove(ofile)
os.remove(oofile)
print "Finished."
sys.stdout.flush()
update_start(now)
开发者ID:anteprandium,项目名称:news2kindle,代码行数:58,代码来源:news2kindle.py
示例11: end_novel
def end_novel():
out_file.close()
pypandoc.convert(
md_file_path,
"html",
outputfile=html_file_path,
extra_args=["-s", "-c", "https://mattfister.github.io/nanogenmo2015/samples/base.css"],
)
print "Total words: " + str(word_count)
开发者ID:mattfister,项目名称:wordtools-deprecated,代码行数:9,代码来源:md_writer.py
示例12: _create
def _create(self):
args, kwargs = self.get_pandoc_params()
try:
pypandoc.convert(*args, **kwargs)
except:
self.errors.append(str("PANDOC-ERROR: " + str(sys.exc_info())))
return
self.upload()
开发者ID:theithec,项目名称:bookhelper,代码行数:9,代码来源:export.py
示例13: get_description
def get_description():
if (not os.path.exists("README.txt") or
(os.path.exists("README.md") and os.stat("README.txt").st_mtime < os.stat("README.md").st_mtime)):
try:
import pypandoc
pypandoc.convert("README.md", "rst", outputfile="README.txt")
except (ImportError, OSError, IOError) as exc:
warnings.warn("Markdown to RST conversion failed (%s), using plain markdown for description" % exc)
return open("README.md", "rt").read()
return open("README.txt", "rt").read()
开发者ID:mwilck,项目名称:proxyenv,代码行数:10,代码来源:setup.py
示例14: test_conversion_with_markdown_extensions
def test_conversion_with_markdown_extensions(self):
input = '<s>strike</s>'
expected_with_extension = u'~~strike~~'
expected_without_extension = u'<s>strike</s>'
received_with_extension = pypandoc.convert(input, 'markdown+strikeout',
format='html')
received_without_extension = pypandoc.convert(input,
'markdown-strikeout',
format='html')
self.assertEqualExceptForNewlineEnd(expected_with_extension, received_with_extension)
self.assertEqualExceptForNewlineEnd(expected_without_extension, received_without_extension)
开发者ID:thatcher,项目名称:pypandoc,代码行数:11,代码来源:tests.py
示例15: test_pdf_conversion
def test_pdf_conversion(self):
tf = tempfile.NamedTemporaryFile(suffix='.pdf', delete=False)
name = tf.name
tf.close()
try:
pypandoc.convert('#some title\n', to='pdf', format='md', outputfile=name)
except:
raise
finally:
os.remove(name)
开发者ID:gwgundersen,项目名称:pypandoc,代码行数:11,代码来源:tests.py
示例16: sendMandrillMarkdownMail
def sendMandrillMarkdownMail(template, dict):
variables = {}
for (k, v) in dict["variables"].iteritems():
variables[k+"_html"] = pypandoc.convert(v, "html", format='md')
for (elem, style) in dict["styles"].iteritems():
variables[k+"_html"] = variables[k+"_html"].replace("<"+elem+">", "<"+elem+" style=\""+style+"\">");
variables[k+"_txt"] = pypandoc.convert(v, "plain", format='md')
sendMandrillMail(template, dict["sender"], dict["recipients"], dict["subject"], variables)
开发者ID:gfmio,项目名称:mandrill-markdown-mails,代码行数:11,代码来源:mandrillmarkdownmails.py
示例17: read_to_rst
def read_to_rst(fname):
try:
import pypandoc
rstname = "{}.{}".format(os.path.splitext(fname)[0], 'rst')
pypandoc.convert(read(fname), 'rst', format='md', outputfile=rstname)
with open(rstname, 'r') as f:
rststr = f.read()
return rststr
#return read(rstname)
except ImportError:
return read(fname)
开发者ID:AlexGrig,项目名称:paramz,代码行数:11,代码来源:setup.py
示例18: convert_md_to_rst
def convert_md_to_rst(source, destination=None, backup_dir=None):
"""Try to convert the source, an .md (markdown) file, to an .rst
(reStructuredText) file at the destination. If the destination isn't
provided, it defaults to be the same as the source path except for the
filename extension. If the destination file already exists, it will be
overwritten. In the event of an error, the destination file will be
left untouched."""
# Doing this in the function instead of the module level ensures the
# error occurs when the function is called, rather than when the module
# is evaluated.
try:
import pypandoc
except ImportError:
# Don't give up right away; first try to install the python module.
os.system("pip install pypandoc")
import pypandoc
# Set our destination path to a default, if necessary
destination = destination or (os.path.splitext(source)[0] + '.rst')
# Likewise for the backup directory
backup_dir = backup_dir or os.path.join(os.path.dirname(destination),
'bak')
bak_name = (os.path.basename(destination) +
time.strftime('.%Y%m%d%H%M%S.bak'))
bak_path = os.path.join(backup_dir, bak_name)
# If there's already a file at the destination path, move it out of the
# way, but don't delete it.
if os.path.isfile(destination):
if not os.path.isdir(os.path.dirname(bak_path)):
os.mkdir(os.path.dirname(bak_path))
os.rename(destination, bak_path)
try:
# Try to convert the file.
pypandoc.convert(
source,
'rst',
format='md',
outputfile=destination
)
except:
# If for any reason the conversion fails, try to put things back
# like we found them.
if os.path.isfile(destination):
os.remove(destination)
if os.path.isfile(bak_path):
os.rename(bak_path, destination)
raise
开发者ID:hosford42,项目名称:pyramids_categories,代码行数:52,代码来源:build_readme.py
示例19: convert_report
def convert_report(templsetting, templfullname, reportsrc,
report_fullfilename, pdoc_writer, pdoc_extra_args = []):
u"""Inställningar för generering av rapporter via Pandoc"""
import pypandoc
pdoc_args = (['--smart', '--standalone', '--latex-engine=xelatex',
'--columns=60', '--' + templsetting + '=' + templfullname,
'--latex-engine-opt=-include-directory=' + templdir] +
pdoc_extra_args)
pypandoc.convert(reportsrc, pdoc_writer, format = 'md',
outputfile = report_fullfilename, extra_args = pdoc_args)
if (sys.platform == 'win32' and pdoc_writer == 'docx' and '--toc' in pdoc_args):
import subprocess
tocscript = os.path.join(maindir, 'toc16.vbs')
subprocess.Popen(['wscript', tocscript, report_fullfilename])
开发者ID:klpn,项目名称:arch_description,代码行数:14,代码来源:reports.py
示例20: pandoc_tofile
def pandoc_tofile(self, oformat, addarg=None):
filters, arguments = self.get_pandoc_args()
if addarg:
arguments.append(addarg)
pypandoc.convert(self.text,
to=oformat,
format="md",
extra_args=arguments,
filters=filters,
outputfile=self.exportpath)
self.show_file()
开发者ID:fizzbucket,项目名称:aced,代码行数:15,代码来源:threads.py
注:本文中的pypandoc.convert函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论