diff --git a/README.md b/README.md index 601a464..cbe96c9 100644 --- a/README.md +++ b/README.md @@ -15,15 +15,26 @@ lektor plugins add markdown-highlighter The plugin has a config file that is used to configure a few things for Pygments. Just create a file named `markdown-highlighter.ini` into your -`configs/` folder. Currently only `pygments.style` is used: +`configs/` folder. + +You can use `pygments.style` to select any of the built-in Pygments styles: ```ini [pygments] style = tango ``` -You can use this to select any of the built-in Pygments styles. Support for -custom styles will come in the future. +Support for custom styles will come in the future. + +You can also use `pygments.cssclass` to apply a custom CSS class +to the generated html and CSS: + +```ini +[pygments] +cssclass = mycode +``` + +By default the plugin will use `highlight` for the CSS class. The config file is considered the "source" for the Pygments stylesheet, so you must create the configuration file (it can be empty) or Lektor's build will prune `pygments.css`. diff --git a/lektor_markdown_highlighter.py b/lektor_markdown_highlighter.py index 3876b84..3fdeee6 100644 --- a/lektor_markdown_highlighter.py +++ b/lektor_markdown_highlighter.py @@ -12,8 +12,11 @@ class MarkdownHighlighterPlugin(Plugin): name = 'Markdown Highlighter' description = 'Lektor plugin that adds syntax highlighting for markdown blocks with Pygments.' + def get_cssclass(self): + return self.get_config().get('pygments.cssclass', 'highlight') + def get_formatter(self): - return HtmlFormatter(style=self.get_style(), cssclass="hll") + return HtmlFormatter(style=self.get_style(), cssclass=self.get_cssclass()) def get_style(self): return self.get_config().get('pygments.style', 'default') @@ -38,7 +41,7 @@ def get_pygments_stylesheet(artifact_name='/static/pygments.css'): self.config_filename]) def build_stylesheet(artifact): with artifact.open('w') as f: - f.write(self.get_formatter().get_style_defs()) + f.write(self.get_formatter().get_style_defs(f'.{self.get_cssclass()}')) return artifact_name def pygmentize(text, lang):