implement syntax_highlighting.enabled
This commit is contained in:
parent
c1e377c94d
commit
0940472410
3 changed files with 9 additions and 15 deletions
|
@ -96,7 +96,9 @@ class ZonaBuilder:
|
||||||
self.item_map = {
|
self.item_map = {
|
||||||
item.source.resolve(): item for item in self.items
|
item.source.resolve(): item for item in self.items
|
||||||
}
|
}
|
||||||
|
|
||||||
# write code highlighting stylesheet
|
# write code highlighting stylesheet
|
||||||
|
if self.config.markdown.syntax_highlighting.enabled:
|
||||||
pygments_style = zmd.get_style_defs(self.config)
|
pygments_style = zmd.get_style_defs(self.config)
|
||||||
(self.layout.content / "static" / "pygments.css").write_text(
|
(self.layout.content / "static" / "pygments.css").write_text(
|
||||||
pygments_style
|
pygments_style
|
||||||
|
|
|
@ -37,11 +37,6 @@ class MarkdownConfig:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class ThemeConfig:
|
|
||||||
name: str = "default"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BuildConfig:
|
class BuildConfig:
|
||||||
clean_output_dir: bool = True
|
clean_output_dir: bool = True
|
||||||
|
@ -53,15 +48,12 @@ IGNORELIST = [".git", ".env", "*/.marksman.toml"]
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ZonaConfig:
|
class ZonaConfig:
|
||||||
title: str = "Zona Blog"
|
base_url: str = "/"
|
||||||
base_url: str = "https://example.com"
|
|
||||||
language: str = "en"
|
|
||||||
# dictionary where key is name, value is url
|
# dictionary where key is name, value is url
|
||||||
sitemap: SitemapConfig = field(default_factory=lambda: {"Home": "/"})
|
sitemap: SitemapConfig = field(default_factory=lambda: {"Home": "/"})
|
||||||
# list of globs relative to content that should be ignored
|
# list of globs relative to content that should be ignored
|
||||||
ignore: list[str] = field(default_factory=lambda: IGNORELIST)
|
ignore: list[str] = field(default_factory=lambda: IGNORELIST)
|
||||||
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
|
markdown: MarkdownConfig = field(default_factory=MarkdownConfig)
|
||||||
theme: ThemeConfig = field(default_factory=ThemeConfig)
|
|
||||||
build: BuildConfig = field(default_factory=BuildConfig)
|
build: BuildConfig = field(default_factory=BuildConfig)
|
||||||
blog: BlogConfig = field(default_factory=BlogConfig)
|
blog: BlogConfig = field(default_factory=BlogConfig)
|
||||||
|
|
||||||
|
|
|
@ -87,10 +87,10 @@ class ZonaRenderer(HTMLRenderer):
|
||||||
def render_fenced_code(self, element: FencedCode):
|
def render_fenced_code(self, element: FencedCode):
|
||||||
assert self.config
|
assert self.config
|
||||||
config = self.config.markdown.syntax_highlighting
|
config = self.config.markdown.syntax_highlighting
|
||||||
|
if not config.enabled:
|
||||||
|
return super().render_fenced_code(element)
|
||||||
code = "".join(child.children for child in element.children) # type: ignore
|
code = "".join(child.children for child in element.children) # type: ignore
|
||||||
lang = element.lang or "text"
|
lang = element.lang or "text"
|
||||||
if not config.enabled:
|
|
||||||
return f"<pre><code>{code}</code></pre>"
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lexer = get_lexer_by_name(lang, stripall=False)
|
lexer = get_lexer_by_name(lang, stripall=False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue