本文整理匯總了Python中markdown.extensions.codehilite.CodeHiliteExtension方法的典型用法代碼示例。如果您正苦於以下問題:Python codehilite.CodeHiliteExtension方法的具體用法?Python codehilite.CodeHiliteExtension怎麽用?Python codehilite.CodeHiliteExtension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類markdown.extensions.codehilite
的用法示例。
在下文中一共展示了codehilite.CodeHiliteExtension方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_pymdownx_highlight_settings
# 需要導入模塊: from markdown.extensions import codehilite [as 別名]
# 或者: from markdown.extensions.codehilite import CodeHiliteExtension [as 別名]
def get_pymdownx_highlight_settings(self):
"""Get the specified extension."""
target = None
if self.enabled:
target = self.getConfigs()
if target is None and CodeHiliteExtension:
for ext in self.md.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
target = ext.getConfigs()
break
if target is None:
target = {}
config_clone = copy.deepcopy(DEFAULT_CONFIG)
for k, v in config_clone.items():
target[k] = config_clone[k][0]
return target
示例2: get_pymdownx_highlight_settings
# 需要導入模塊: from markdown.extensions import codehilite [as 別名]
# 或者: from markdown.extensions.codehilite import CodeHiliteExtension [as 別名]
def get_pymdownx_highlight_settings(self):
"""Get the specified extension."""
target = None
if self.enabled:
target = self.getConfigs()
if target is None and CodeHiliteExtension:
for ext in self.md.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
target = ext.getConfigs()
break
if target is None:
target = {}
config_clone = copy.deepcopy(DEFAULT_CONFIG)
for k, v in config_clone.items():
target[k] = config_clone[k][0]
return target
示例3: run
# 需要導入模塊: from markdown.extensions import codehilite [as 別名]
# 或者: from markdown.extensions.codehilite import CodeHiliteExtension [as 別名]
def run(self, lines):
""" Match and store Fenced Code Blocks in the HtmlStash. """
# Check for code hilite extension
if not self.checked_for_codehilite:
for ext in self.markdown.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
self.codehilite_conf = ext.config
break
self.checked_for_codehilite = True
text = "\n".join(lines)
while 1:
m = FENCED_BLOCK_RE.search(text)
if m:
lang = ''
if m.group('lang'):
lang = LANG_TAG % m.group('lang')
# If config is not empty, then the codehighlite extension
# is enabled, so we call it to highlite the code
if self.codehilite_conf:
highliter = CodeHilite(m.group('code'),
linenos=self.codehilite_conf['force_linenos'][0],
guess_lang=self.codehilite_conf['guess_lang'][0],
css_class=self.codehilite_conf['css_class'][0],
style=self.codehilite_conf['pygments_style'][0],
lang=(m.group('lang') or None),
noclasses=self.codehilite_conf['noclasses'][0])
code = highliter.hilite()
else:
code = CODE_WRAP % (lang, self._escape(m.group('code')))
placeholder = self.markdown.htmlStash.store(code, safe=True)
text = '%s\n%s\n%s'% (text[:m.start()], placeholder, text[m.end():])
else:
break
return text.split("\n")
示例4: format_code
# 需要導入模塊: from markdown.extensions import codehilite [as 別名]
# 或者: from markdown.extensions.codehilite import CodeHiliteExtension [as 別名]
def format_code(self, lang: str, text: str) -> str:
if lang:
langclass = LANG_TAG % (lang,)
else:
langclass = ''
# Check for code hilite extension
if not self.checked_for_codehilite:
for ext in self.md.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
self.codehilite_conf = ext.config
break
self.checked_for_codehilite = True
# If config is not empty, then the codehighlite extension
# is enabled, so we call it to highlite the code
if self.codehilite_conf:
highliter = CodeHilite(text,
linenums=self.codehilite_conf['linenums'][0],
guess_lang=self.codehilite_conf['guess_lang'][0],
css_class=self.codehilite_conf['css_class'][0],
style=self.codehilite_conf['pygments_style'][0],
use_pygments=self.codehilite_conf['use_pygments'][0],
lang=(lang or None),
noclasses=self.codehilite_conf['noclasses'][0])
code = highliter.hilite()
else:
code = CODE_WRAP % (langclass, self._escape(text))
return code
示例5: test_custom_md_extension
# 需要導入模塊: from markdown.extensions import codehilite [as 別名]
# 或者: from markdown.extensions.codehilite import CodeHiliteExtension [as 別名]
def test_custom_md_extension(self):
extn = CodeHiliteExtension()
engine = BloggingEngine(extensions=[extn])
extns = engine.post_processor.all_extensions()
self.assertEqual(len(extns), 3)
self.assertTrue(isinstance(extns[-1], CodeHiliteExtension))
示例6: html_content
# 需要導入模塊: from markdown.extensions import codehilite [as 別名]
# 或者: from markdown.extensions.codehilite import CodeHiliteExtension [as 別名]
def html_content(self):
"""
Generate HTML representation of the markdown-formatted note,
and also convert any media URLs into rich media objects such as video
players or images.
"""
hilite = CodeHiliteExtension(linenums=False, css_class='highlight')
extras = ExtraExtension()
markdown_content = markdown(self.content, extensions=[hilite, extras])
return Markup(markdown_content)
示例7: _get_codehilite_config
# 需要導入模塊: from markdown.extensions import codehilite [as 別名]
# 或者: from markdown.extensions.codehilite import CodeHiliteExtension [as 別名]
def _get_codehilite_config(self):
for ext in self.markdown.registeredExtensions:
if isinstance(ext, CodeHiliteExtension):
return ext.config
return None