當前位置: 首頁>>代碼示例>>Python>>正文


Python util.AtomicString方法代碼示例

本文整理匯總了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 
開發者ID:pawamoy,項目名稱:mkdocstrings,代碼行數:24,代碼來源:extension.py

示例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
            )
        ) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:26,代碼來源:magiclink.py

示例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]
            )
        ) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:23,代碼來源:magiclink.py

示例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])
        ) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:22,代碼來源:magiclink.py

示例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) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:19,代碼來源:magiclink.py

示例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 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:23,代碼來源:emoji.py

示例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 
開發者ID:jamiemcg,項目名稱:Remarkable,代碼行數:10,代碼來源:superscript.py

示例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 
開發者ID:jamiemcg,項目名稱:Remarkable,代碼行數:10,代碼來源:subscript.py

示例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) 
開發者ID:airbnb,項目名稱:knowledge-repo,代碼行數:37,代碼來源:html.py

示例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 
開發者ID:airbnb,項目名稱:knowledge-repo,代碼行數:6,代碼來源:html.py

示例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) 
開發者ID:pdoc3,項目名稱:pdoc,代碼行數:12,代碼來源:html_helpers.py

示例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
            )
        ) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:38,代碼來源:magiclink.py

示例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
            )
        ) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:28,代碼來源:magiclink.py

示例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 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:11,代碼來源:arithmatex.py

示例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) 
開發者ID:V1EngineeringInc,項目名稱:V1EngineeringInc-Docs,代碼行數:12,代碼來源:arithmatex.py


注:本文中的markdown.util.AtomicString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。