Initial chekin post-discontinuity.

This commit is contained in:
2023-09-25 12:16:34 -07:00
commit 694acf8599
36 changed files with 2118 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
"""Map Pygments into the Template API for inclusion in outputs."""
from typing import Optional, cast
import pygments
import pygments.formatters
import pygments.lexers
import pygments.styles
import pygments.util
def pygments_markup_contents_html(input_text: str, file_type: str, style: Optional[str] = None) -> str:
"""Format input string with Pygments and return HTML."""
if style is None:
style = "default"
pyst = pygments.styles.get_style_by_name(style)
formatter = pygments.formatters.get_formatter_by_name("html", style=pyst)
try:
lexer = pygments.lexers.get_lexer_for_filename(file_type)
except pygments.util.ClassNotFound:
try:
lexer = pygments.lexers.get_lexer_by_name(file_type)
except pygments.util.ClassNotFound:
lexer = pygments.lexers.get_lexer_by_mimetype(file_type)
return pygments.highlight(input_text, lexer, formatter)
def pygments_get_css(style: Optional[str] = None) -> str:
"""Return the CSS styles associated with a particular style definition."""
if style is None:
style = "default"
pyst = pygments.styles.get_style_by_name(style)
formatter = pygments.formatters.get_formatter_by_name("html", style=pyst)
return formatter.get_style_defs()