本文整理匯總了Python中markdown2.markdown方法的典型用法代碼示例。如果您正苦於以下問題:Python markdown2.markdown方法的具體用法?Python markdown2.markdown怎麽用?Python markdown2.markdown使用的例子?那麽恭喜您, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在模塊markdown2的用法示例。
在下文中一共展示了markdown2.markdown方法的29個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的Python代碼示例。
示例1: rich_edit_static
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def rich_edit_static(context):
files = [
"" % static(
"simplemde/simplemde.min.css"),
"" % static(
"font-awesome/css/font-awesome.min.css"),
"" % static(
"simplemde/marked.min.js"),
"" % static(
"simplemde/simplemde.min.js"),
"" % static(
"simplemde/inline-attachment.min.js"),
"" % static(
"simplemde/codemirror.inline-attachment.js"),
"" % static(
"simplemde/markdown.js")
]
return mark_safe("\n".join(files))
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:21,
示例2: send
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def send(self, event, users, instance, paths):
if not self._ensure_connection():
print("Cannot contact the XMPP server")
return
for user, templates in users.items():
jid = self._get_jid(user)
if not self.enabled(event, user, paths) or jid is None:
continue
template = self._get_template(templates)
if template is None:
continue
params = self.prepare(template, instance)
message = xmpp.protocol.Message(jid, body=params['short_description'].encode('utf-8'),
subject=params['subject'].encode('utf-8'), typ='chat')
html = xmpp.Node('html', {'xmlns': 'http://jabber.org/protocol/xhtml-im'})
text = u"
" + markdown2.markdown(params['short_description'],extras=["link-patterns"],
link_patterns=link_registry.link_patterns(
request),
safe_mode=True) + u""
html.addChild(node=xmpp.simplexml.XML2Node(text.encode('utf-8')))
message.addChild(node=html)
self.client.send(message)
self.client.disconnected()
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:27,
示例3: main
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def main():
"""Covert GitHub mardown to AnkiWeb HTML."""
# permitted tags: img, a, b, i, code, ul, ol, li
translate = [
(r'
(r'
(r'
(r'([^', r'\1'),
(r'([^', r'\1'),
(r'([^', r'\1
'),
(r'
', r'\n'),(r'
', r''),
(r'
', r'\n\n'),(r'(ol|ul)>(?!(li|[ou]l)>)', r'\1>\n'),
]
with open('README.md', encoding='utf-8') as f:
html = ''.join(filter(None, markdown(f.read()).split('\n')))
for a, b in translate:
html = sub(a, b, html)
with open('README.html', 'w', encoding='utf-8') as f:
f.write(html.strip())
開發者ID:luoliyan,項目名稱:chinese-support-redux,代碼行數:27,
示例4: get
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def get(self, request, param):
print('path:%s param:%s' % (request.path, param))
try:
article = JDCommentAnalysis.objects.filter(Q(guid__iexact = param) | Q(product_id__iexact = param)).first()
article.content = markdown2.markdown(text = article.content, extras = {
'tables': True,
'wiki-tables': True,
'fenced-code-blocks': True,
})
context = {
'article': article
}
return render(request, 'full_result.html', context = context)
except:
return render(request, '404.html')
開發者ID:awolfly9,項目名稱:jd_analysis,代碼行數:19,
示例5: record_result
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def record_result(self, result, color = 'default', font_size = 16, strong = False, type = 'word',
br = True, default = False, new_line = False):
self.full_result = ''
if type == 'word' and default == False:
if strong:
result = '%s' % (color, font_size, result)
else:
result = '%s' % (color, font_size, result)
elif type == 'image':
result = markdown2.markdown(result)
self.full_result += result
if br:
self.full_result += '
'
if new_line:
self.full_result += '\n'
utils.push_redis(guid = self.guid, product_id = self.product_id, info = self.full_result, type = type)
# 提取商品的基本信息
開發者ID:awolfly9,項目名稱:jd_analysis,代碼行數:23,
示例6: get_metadata_div
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def get_metadata_div(strategy: bt.Strategy) -> str:
md = ""
md += _get_strategy(strategy)
md += '* * *'
md += _get_datas(strategy)
md += '* * *'
md += _get_observers(strategy)
md += '* * *'
md += _get_analyzers(strategy)
md += '* * *'
css_classes = {'table': 'metaDataTable'}
html = markdown2.markdown(md, extras={
'fenced-code-blocks': None,
'tables': None,
'html-classes': css_classes
})
return html
開發者ID:verybadsoldier,項目名稱:backtrader_plotting,代碼行數:22,
示例7: generate_doc
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def generate_doc(config):
docdir = os.path.join(cwd,'documentation')
if not os.path.exists(docdir):
warn("Couldn't find documentation file at: %s" % docdir)
return None
try:
import markdown2 as markdown
except ImportError:
import markdown
documentation = []
for file in os.listdir(docdir):
if file in ignoreFiles or os.path.isdir(os.path.join(docdir, file)):
continue
md = open(os.path.join(docdir,file)).read()
html = markdown.markdown(md)
documentation.append({file:html});
return documentation
開發者ID:dbankier,項目名稱:TiLogCatcher,代碼行數:20,
示例8: markdown2html
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def markdown2html(markdown):
"""
convert Markdown to HTML via ``markdown2``
Args:
markdown (str):
Markdown text
Returns:
str: HTML
"""
try:
import markdown2
except ImportError:
notinstalled("markdown2", "markdown", "HTML")
sys.exit(4)
return markdown2.markdown(markdown)
開發者ID:Findus23,項目名稱:pyLanguagetool,代碼行數:20,
示例9: ipynb2markdown
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def ipynb2markdown(ipynb):
"""
Extract Markdown cells from iPython Notebook
Args:
ipynb (str):
iPython notebook JSON file
Returns:
str: Markdown
"""
j = json.loads(ipynb)
markdown = ""
for cell in j["cells"]:
if cell["cell_type"] == "markdown":
markdown += "".join(cell["source"]) + "\n"
return markdown
開發者ID:Findus23,項目名稱:pyLanguagetool,代碼行數:19,
示例10: to_pdf
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def to_pdf(title: str, markdown_source: str) -> bytes:
html_style = MarkdownToPDF.css()
html_body = markdown2.markdown(markdown_source)
html = f"""
{title}{html_style}
{html_body}
"""
return pdfkit.from_string(html, False, options={"quiet": ""})
開發者ID:codeforpdx,項目名稱:recordexpungPDX,代碼行數:20,
示例11: get_html_issue_body
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def get_html_issue_body(title, author, body, issue_number, url) -> Any:
"""
Curate a HTML formatted body for the issue mail.
:param title: title of the issue
:type title: str
:param author: author of the issue
:type author: str
:param body: content of the issue
:type body: str
:param issue_number: issue number
:type issue_number: int
:param url: link to the issue
:type url: str
:return: email body in html format
:rtype: str
"""
from run import app
html_issue_body = markdown(body, extras=["target-blank-links", "task_list", "code-friendly"])
template = app.jinja_env.get_or_select_template("email/new_issue.txt")
html_email_body = template.render(title=title, author=author, body=html_issue_body, url=url)
return html_email_body
開發者ID:CCExtractor,項目名稱:sample-platform,代碼行數:25,
示例12: get_blog
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def get_blog(id, request):
blog = yield from Blog.find(id) # 通過id從數據庫中拉去博客信息
# 從數據庫拉取指定blog的全部評論,按時間降序排序,即最新的排在最前
comments = yield from Comment.findAll('blog_id=?', [id], orderBy='created_at desc')
# 將每條評論都轉化成html格式
for c in comments:
c.html_content = text2html(c.content)
# blog也是markdown格式,將其轉化成html格式
blog.html_content = markdown2.markdown(blog.content)
return {
'__template__': 'blog.html',
'blog': blog,
'__user__':request.__user__,
'comments': comments
}
# day10中定義
# 頁麵:注冊頁麵
開發者ID:ReedSun,項目名稱:Preeminent,代碼行數:21,
示例13: to_html
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def to_html(self, md = None, scroll_pos = -1, content_only = False):
md = md or self.markup.text
result = markdown(md, extras=self.extras)
if not content_only:
intro = Template(self.htmlIntro.safe_substitute(css = self.css))
(font_name, font_size) = self.font
result = intro.safe_substitute(
background_color = self.to_css_rgba(self.markup.background_color),
text_color = self.to_css_rgba(self.markup.text_color),
font_family = font_name,
text_align = self.to_css_alignment(),
font_size = str(font_size)+'px',
init_postfix = self.init_postfix,
link_prefix = self.link_prefix,
debug_prefix = self.debug_prefix,
scroll_pos = scroll_pos
) + result + self.htmlOutro
return result
開發者ID:khilnani,項目名稱:pythonista-scripts,代碼行數:20,
示例14: preferred_size
點讚 6
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def preferred_size(self, using='current', min_width=None, max_width=None, min_height=None, max_height=None):
if using=='current':
using = 'markdown' if self.editing else 'html'
if using=='markdown':
self.markup_ghost.text = self.markup.text
view = self.markup_ghost
else:
view = self.web_ghost
view.size_to_fit()
if max_width and view.width > max_width:
view.width = max_width
view.size_to_fit()
if max_width and view.width > max_width:
view.width = max_width
if min_width and view.width < min_width:
view.width = min_width
if max_height and view.height > max_height:
view.height = max_height
if min_height and view.height < min_height:
view.height = min_height
return (view.width, view.height)
開發者ID:khilnani,項目名稱:pythonista-scripts,代碼行數:27,
示例15: get_incidents
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def get_incidents(repo, issues):
# loop over all issues in the past 90 days to get current and past incidents
incidents = []
collaborators = get_collaborators(repo=repo)
for issue in issues:
labels = issue.get_labels()
affected_systems = sorted(iter_systems(labels))
severity = get_severity(labels)
# make sure that non-labeled issues are not displayed
if not affected_systems or (severity is None and issue.state != "closed"):
continue
# make sure that the user that created the issue is a collaborator
if issue.user.login not in collaborators:
continue
# create an incident
incident = {
"created": issue.created_at,
"title": issue.title,
"systems": affected_systems,
"severity": severity,
"closed": issue.state == "closed",
"body": markdown2.markdown(issue.body),
"updates": []
}
for comment in issue.get_comments():
# add comments by collaborators only
if comment.user.login in collaborators:
incident["updates"].append({
"created": comment.created_at,
"body": markdown2.markdown(comment.body)
})
incidents.append(incident)
# sort incidents by date
return sorted(incidents, key=lambda i: i["created"], reverse=True)
開發者ID:jayfk,項目名稱:statuspage,代碼行數:42,
示例16: _view_plaintext
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def _view_plaintext(self, notebook_name, note_name, highlight=None,
dot=False):
notebook_enc = self.encode_name(notebook_name)
note_enc = self.encode_name(note_name)
if dot:
path = join(self.settings.repo, notebook_enc, '.' + note_enc)
else:
path = join(self.settings.repo, notebook_enc, note_enc)
note_contents = open(path).read()
note_contents = markdown(note_contents)
if highlight is not None:
note_contents = self.highlight(note_contents, highlight)
self.render('note.html', notebook_name=notebook_name,
note_name=note_name, note_contents=note_contents,
edit=False, dot=dot, wysiwyg=self.settings['wysiwyg'])
開發者ID:charlesthomas,項目名稱:magpie,代碼行數:17,
示例17: rich_edit
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def rich_edit(context, field):
return field.as_widget(attrs={"class": "form-control markdown"})
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:4,
示例18: render_markdown
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def render_markdown(data):
html = markdown2.markdown(data, extras=["link-patterns", "tables", "code-friendly", "fenced-code-blocks"],
link_patterns=registry.link_patterns(),
safe_mode=settings.MARKDOWN_SAFE_MODE)
if settings.MARKDOWN_SAFE_MODE:
html = bleach.clean(html, tags=settings.MARKDOWN_ALLOWED_TAGS)
return mark_safe(html)
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:9,
示例19: prepare_email_message
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def prepare_email_message(to, subject, body, behalf=None, cc=None, bcc=None, request=None):
reply_to = {}
if hasattr(settings, 'REPLY_TO'):
reply_to = {'Reply-To': settings.REPLY_TO, 'Return-Path': settings.REPLY_TO}
if behalf is None and hasattr(settings, 'EMAIL_FROM'):
behalf = settings.EMAIL_FROM
if not isinstance(to, (tuple, list)):
to = to.split(';')
email_message = EmailMultiAlternatives(
subject=subject,
body=body,
from_email=behalf,
to=to,
cc=cc,
bcc=bcc,
headers=reply_to
)
email_message.attach_alternative(markdown2.markdown(
body,
extras=["link-patterns", "tables", "code-friendly"],
link_patterns=registry.link_patterns(request),
safe_mode=True
),
'text/html')
return email_message
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:32,
示例20: metadata
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def metadata(self):
metadata = super().metadata
if self._meta_with_readme:
return self._meta_with_readme
readme_path = os.path.join(self.path, 'README.md')
if os.path.isfile(readme_path):
with open(readme_path, 'r') as f:
readme_data = f.read()
metadata['readme'] = readme_data
metadata['readme_html'] = markdown2.markdown(readme_data)
self._meta_with_readme = metadata
return self._meta_with_readme
開發者ID:KubeOperator,項目名稱:KubeOperator,代碼行數:15,
示例21: get_context_data
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def get_context_data(self, **kwargs):
content = markdown(self.get_text_file())
return super(AboutView, self).get_context_data(
content=content, **kwargs)
開發者ID:arguman,項目名稱:arguman.org,代碼行數:6,
示例22: formatted_sources
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def formatted_sources(self):
return markdown(escape(self.sources), safe_mode=True)
開發者ID:arguman,項目名稱:arguman.org,代碼行數:4,
示例23: formatted_text
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def formatted_text(self):
return markdown(escape(self.text), safe_mode=True)
開發者ID:arguman,項目名稱:arguman.org,代碼行數:4,
示例24: blog
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def blog(blog_id):
blog = Blog.get(blog_id)
if blog is None:
raise notfound()
blog.html_content = markdown2.markdown(blog.content)
comments = Comment.find_by(
'where blog_id=? order by created_at desc limit 1000', blog_id)
return dict(blog=blog, comments=comments, user=ctx.request.user)
開發者ID:tzshlyt,項目名稱:python-webapp-blog,代碼行數:10,
示例25: api_get_blogs
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def api_get_blogs():
format = ctx.request.get('format', '')
blogs, page = _get_blogs_by_page()
if format == 'html':
for blog in blogs:
blog.content = markdown2.markdown(blog.content)
return dict(blogs=blogs, page=page)
開發者ID:tzshlyt,項目名稱:python-webapp-blog,代碼行數:9,
示例26: markdown2html
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def markdown2html(markdown_data):
extras = ['tables', 'fenced-code-blocks', 'cuddled-lists']
html_output = markdown2.markdown(
markdown_data,
safe_mode=True,
extras=extras,
).replace('
', '').replace('
', '')return html_output
開發者ID:521xueweihan,項目名稱:hellogithub.com,代碼行數:10,
示例27: generate_out_url
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def generate_out_url(image_path):
"""
生成用於輸出 markdown 的 image_url
"""
if image_path:
return GITHUB_IMAGE_PREFIX+image_path
else:
return image_path
開發者ID:521xueweihan,項目名稱:hellogithub.com,代碼行數:10,
示例28: main
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def main(input_paths_str, output_path):
# lee los htmls a convertir en PDF
input_paths = input_paths_str.split(",")
htmls = []
for input_path in input_paths:
with open(input_path) as input_file:
htmls.append(markdown2.markdown(
input_file.read(),
extras=["fenced_code", "codehilite", "admonition"]))
print("Hay {} documentos".format(len(htmls)))
# guarda html
with open(output_path.replace(".pdf", ".html"), "wb") as output_html:
# aplica el estilo al principio
html = "\n".join(htmls)
html_with_style = """
""" + html
# escribe el html
output_html.write(html_with_style.encode("utf-8"))
shutil.copyfile(
"docs/css/pdf.css",
os.path.join(os.path.dirname(output_path), "pdf.css")
)
# guarda pdf
pdfkit.from_string(html, output_path, options={"encoding": "utf8"},
css="docs/css/pdf.css")
開發者ID:datosgobar,項目名稱:portal-andino,代碼行數:33,
示例29: get_readme
點讚 5
# 需要導入模塊: import markdown2 [as 別名]
# 或者: from markdown2 import markdown [as 別名]
def get_readme(self):
readme = self.get_file('README.md')
if readme:
with open(readme, 'r') as f:
readme = markdown(f.read(), extras=["code-friendly"])
return readme
開發者ID:certsocietegenerale,項目名稱:fame,代碼行數:10,
注:本文中的markdown2.markdown方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。