Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix background color #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
7 changes: 5 additions & 2 deletions lektor_markdown_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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):
Expand Down