本文整理汇总了Python中markdown.util.AtomicString方法的典型用法代码示例。如果您正苦于以下问题:Python util.AtomicString方法的具体用法?Python util.AtomicString怎么用?Python util.AtomicString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markdown.util
的用法示例。
在下文中一共展示了util.AtomicString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: atomic_brute_cast
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def atomic_brute_cast(tree: Element) -> Element:
"""
Cast every node's text into an atomic string to prevent further processing on it.
Since we generate the final HTML with Jinja templates, we do not want other inline or tree processors
to keep modifying the data, so this function is used to mark the complete tree as "do not touch".
Reference: issue [Python-Markdown/markdown#920](https://github.com/Python-Markdown/markdown/issues/920).
On a side note: isn't `atomic_brute_cast` such a beautiful function name?
Arguments:
tree: An XML node, used like the root of an XML tree.
Returns:
The same node, recursively modified by side-effect. You can skip re-assigning the return value.
"""
if tree.text:
tree.text = AtomicString(tree.text)
for child in tree:
atomic_brute_cast(child)
return tree
示例2: process_commit
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def process_commit(self, el, provider, user, repo, commit):
"""Process commit."""
hash_ref = commit[0:PROVIDER_INFO[provider]['hash_size']]
if self.my_repo:
text = hash_ref
elif self.my_user:
text = '%s@%s' % (repo, hash_ref)
else:
text = '%s/%s@%s' % (user, repo, hash_ref)
el.set('href', PROVIDER_INFO[provider]['commit'] % (user, repo, commit))
el.text = md_util.AtomicString(text)
el.set('class', 'magiclink magiclink-%s magiclink-commit' % provider)
el.set(
'title',
'%s %s: %s/%s@%s' % (
PROVIDER_INFO[provider]['provider'],
self.labels.get('commit', 'Commit'),
user,
repo,
hash_ref
)
)
示例3: shorten_diff
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def shorten_diff(self, link, class_name, label, user_repo, value, hash_size):
"""Shorten diff/compare links."""
repo_label = self.repo_labels.get('compare', 'Compare')
if self.my_repo:
text = '%s...%s' % (value[0][0:hash_size], value[1][0:hash_size])
elif self.my_user:
text = '%s@%s...%s' % (user_repo.split('/')[1], value[0][0:hash_size], value[1][0:hash_size])
else:
text = '%s@%s...%s' % (user_repo, value[0][0:hash_size], value[1][0:hash_size])
link.text = md_util.AtomicString(text)
if 'magiclink-compare' not in class_name:
class_name.append('magiclink-compare')
link.set(
'title',
'%s %s: %s@%s...%s' % (
label, repo_label, user_repo.rstrip('/'), value[0][0:hash_size], value[1][0:hash_size]
)
)
示例4: shorten_commit
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def shorten_commit(self, link, class_name, label, user_repo, value, hash_size):
"""Shorten commit link."""
# user/repo@hash
repo_label = self.repo_labels.get('commit', 'Commit')
if self.my_repo:
text = value[0:hash_size]
elif self.my_user:
text = '%s@%s' % (user_repo.split('/')[1], value[0:hash_size])
else:
text = '%s@%s' % (user_repo, value[0:hash_size])
link.text = md_util.AtomicString(text)
if 'magiclink-commit' not in class_name:
class_name.append('magiclink-commit')
link.set(
'title',
'%s %s: %s@%s' % (label, repo_label, user_repo.rstrip('/'), value[0:hash_size])
)
示例5: handleMatch
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def handleMatch(self, m, data):
"""Handle URL matches."""
el = md_util.etree.Element("a")
el.text = md_util.AtomicString(m.group('link'))
if m.group("www"):
href = "http://%s" % m.group('link')
else:
href = m.group('link')
if self.config['hide_protocol']:
el.text = md_util.AtomicString(el.text[el.text.find("://") + 3:])
el.set("href", self.unescape(href.strip()))
if self.config.get('repo_url_shortener', False):
el.set('magiclink', md_util.text_type(MAGIC_LINK))
return el, m.start(0), m.end(0)
示例6: to_png_sprite
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def to_png_sprite(index, shortname, alias, uc, alt, title, category, options, md):
"""Return PNG sprite element."""
attributes = {
"class": '%(class)s-%(size)s-%(category)s _%(unicode)s' % {
"class": options.get('classes', index),
"size": options.get('size', '64'),
"category": (category if category else ''),
"unicode": uc
}
}
if title:
attributes['title'] = title
add_attriubtes(options, attributes)
el = md_util.etree.Element("span", attributes)
el.text = md_util.AtomicString(alt)
return el
示例7: handleMatch
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def handleMatch(self, m):
supr = m.group(3)
text = supr
el = etree.Element("sup")
el.text = AtomicString(text)
return el
示例8: handleMatch
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def handleMatch(self, m):
subsc = m.group(3)
text = subsc
el = etree.Element("sub")
el.text = AtomicString(text)
return el
示例9: run
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def run(self, parent, blocks):
sibling = self.lastChild(parent)
block = blocks.pop(0)
block, theRest = self.detab(block)
block = block.rstrip()
block_is_html = False
if "<div " in block or "</" in block or "<span " in block:
block_is_html = True
if (sibling is not None and sibling.tag == "div"):
# The previous block was a code block. As blank lines do not start
# new code blocks, append this block to the previous, adding back
# linebreaks removed from the split into a list.
block_is_html = block_is_html and not isinstance(sibling.text, AtomicString)
block = u'\n'.join([sibling.text, block])
output = sibling
else:
# This is a new codeblock. Create the elements and insert text.
output = markdown.util.etree.SubElement(parent, 'div', {'class': 'code-output'})
# If not HTML, add the `pre` class so that we know to render output as raw text
if not block_is_html and 'pre' not in output.get('class', 'code-output'):
output.set('class', ' '.join([output.get('class', ''), 'pre']))
output.text = "{}\n".format(block) if block_is_html else AtomicString("{}\n".format(block))
if theRest:
# This block contained unindented line(s) after the first indented
# line. Insert these lines as the first block of the master blocks
# list for future processing.
blocks.insert(0, theRest)
示例10: handleMatch
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def handleMatch(self, m):
node = markdown.util.etree.Element('mathjax')
node.text = markdown.util.AtomicString(m.group(2) + m.group(3) + m.group(2))
return node
示例11: handleMatch
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def handleMatch(self, m, data):
for value, is_block in zip(m.groups(), (False, True, True)):
if value:
break
script = etree.Element('script', type='math/tex' + ('; mode=display' if is_block else ''))
preview = etree.Element('span', {'class': 'MathJax_Preview'})
preview.text = script.text = AtomicString(value)
wrapper = etree.Element('span')
wrapper.extend([preview, script])
return wrapper, m.start(0), m.end(0)
示例12: process_issues
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def process_issues(self, el, provider, user, repo, issue):
"""Process issues."""
issue_type = issue[:1]
issue_value = issue[1:]
if issue_type == '#':
issue_link = PROVIDER_INFO[provider]['issue']
issue_label = self.labels.get('issue', 'Issue')
class_name = 'magiclink-issue'
else:
issue_link = PROVIDER_INFO[provider]['pull']
issue_label = self.labels.get('pull', 'Pull Request')
class_name = 'magiclink-pull'
if self.my_repo:
text = '%s%s' % (issue_type, issue_value)
elif self.my_user:
text = '%s%s%s' % (repo, issue_type, issue_value)
else:
text = '%s/%s%s%s' % (user, repo, issue_type, issue_value)
el.set('href', issue_link % (user, repo, issue_value))
el.text = md_util.AtomicString(text)
el.set('class', 'magiclink magiclink-%s %s' % (provider, class_name))
el.set(
'title',
'%s %s: %s/%s%s%s' % (
PROVIDER_INFO[provider]['provider'],
issue_label,
user,
repo,
issue_type,
issue_value
)
)
示例13: process_compare
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def process_compare(self, el, provider, user, repo, commit1, commit2):
"""Process commit."""
hash_ref1 = commit1[0:PROVIDER_INFO[provider]['hash_size']]
hash_ref2 = commit2[0:PROVIDER_INFO[provider]['hash_size']]
if self.my_repo:
text = '%s...%s' % (hash_ref1, hash_ref2)
elif self.my_user:
text = '%s@%s...%s' % (repo, hash_ref1, hash_ref2)
else:
text = '%s/%s@%s...%s' % (user, repo, hash_ref1, hash_ref2)
el.set('href', PROVIDER_INFO[provider]['compare'] % (user, repo, commit1, commit2))
el.text = md_util.AtomicString(text)
el.set('class', 'magiclink magiclink-%s magiclink-compare' % provider)
el.set(
'title',
'%s %s: %s/%s@%s...%s' % (
PROVIDER_INFO[provider]['provider'],
self.labels.get('compare', 'Compare'),
user,
repo,
hash_ref1,
hash_ref2
)
)
示例14: inline_generic_format
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def inline_generic_format(math, language='math', class_name='arithmatex', md=None, wrap='\\(%s\\)'):
"""Inline generic formatter."""
el = md_util.etree.Element('span', {'class': class_name})
el.text = md_util.AtomicString(wrap % math)
return el
# Formatters usable with SuperFences
示例15: mathjax_output
# 需要导入模块: from markdown import util [as 别名]
# 或者: from markdown.util import AtomicString [as 别名]
def mathjax_output(self, parent, math):
"""Default MathJax output."""
if self.preview:
grandparent = parent
parent = md_util.etree.SubElement(grandparent, 'div')
preview = md_util.etree.SubElement(parent, 'div', {'class': 'MathJax_Preview'})
preview.text = md_util.AtomicString(math)
el = md_util.etree.SubElement(parent, 'script', {'type': 'math/tex; mode=display'})
el.text = md_util.AtomicString(math)