Skip to content

Commit

Permalink
Merge pull request #22 from MartenBE/bugfix/allow-plugin-config
Browse files Browse the repository at this point in the history
Fixed bug with plugin conf in revealjs key, and added CSS file option
  • Loading branch information
MartenBE authored Nov 27, 2024
2 parents afcedbf + 858a855 commit 39bedfa
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 20 deletions.
61 changes: 46 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,57 +77,86 @@ Here's an example showcasing all possible options in the config file:
```yml
# Configuration for the generated index page
index:
# Title of the generated index page: string
title: example-title
# Favicon of the generated index page: file path or public url to favicon
# file
favicon: ./example-index-favicon.ico

# Jinja 2 template to generate index HTML: file path to Jinja2 file
template: ./example.jinja

# Theme of the generated index page: file path or public url to CSS file
theme: example-index-theme.css

# Title of the generated index page: string
title: example-title

# Configuration for the slides
slides:
# Charset of the slides: string
# (see https://revealjs.com/markdown/#external-markdown)
charset: utf-8

# Favicon of the slides: file path or public url to favicon file
favicon: ./example-slides-favicon.ico
# Theme of the slides: file path to CSS file, public url to CSS file, or one
# of the reveal.js themes such as `black`, `white`, `league`, `solarized`,
# `dracula`, ... (see https://revealjs.com/themes/)
theme: example-slides-theme.css

# Theme for syntax highlighting of code fragments on the slides: file path
# to CSS file, public url to CSS file, or one of the highlight.js built-in
# themes such as `monokai`, `obsidian`, `tokyo-night-dark`, `vs`, ...
# (see https://highlightjs.org/examples)
highlight_theme: example-slides-highlight-theme.css

# Relative path to a python script containing a function
# Callable[[str], str] named `preprocess`. For each Markdown file, the whole
# file content is given to the function as a str. The returned string is
# then further processed as the markdown to give to Reveal.js
preprocess_script: tests/test_preprocessors/replace_ats.py
# Separator to determine end current/begin new slide: regexp

# Separator to determine notes of the slide: regexp
# (see https://revealjs.com/markdown/#external-markdown)
separator: ^\s*---\s*$
separator_notes: "^Notes?:"

# Separator to determine end current/begin new vertical slide: regexp
# (see https://revealjs.com/markdown/#external-markdown)
separator_vertical: ^\s*-v-\s*$
# Separator to determine notes of the slide: regexp
# (see https://revealjs.com/markdown/#external-markdown)
separator_notes: "^Notes?:"
# Charset of the slides: string

# Separator to determine end current/begin new slide: regexp
# (see https://revealjs.com/markdown/#external-markdown)
separator_charset: utf-8
separator: ^\s*---\s*$

# Jinja 2 template to generate index HTML: file path to Jinja2 file
template: ./example.jinja

# Theme of the slides: file path to CSS file, public url to CSS file, or one
# of the reveal.js themes such as `black`, `white`, `league`, `solarized`,
# `dracula`, ... (see https://revealjs.com/themes/)
theme: example-slides-theme.css

# Options to be passed to reveal.js: options in yaml format, they will be
# translated to JSON automatically (see https://revealjs.com/config/)
revealjs:
height: 1080
width: 1920
transition: fade

example_plugin:
example_plugin_option_A: true
example_plugin_option_B: qwerty

# Plugins or additional CSS/JavaScript files for the slides. These are given as
# a list.
plugins:
# Name of the plugin (optional, see plugin README): plugin id string
# (see https://revealjs.com/creating-plugins/#registering-a-plugin)
- name: RevealExamplePlugin
# List of CSS files of the plugin (optional, see plugin README):
# public url to CSS file per entry
extra_css:
- https://cdn.jsdelivr.net/npm/reveal.js-example-pluting/example.min.css
# List of JavaScript files of the plugin (optional, see plugin README):
# public url to JavaScript file per entry
extra_javascript:
- https://cdn.jsdelivr.net/npm/reveal.js-example-pluting/example.min.js
- name: RevealMermaid
# List of JavaScript files of the plugin: file path or public url to
# JavaScript file per entry
extra_javascript:
- https://cdn.jsdelivr.net/npm/reveal.js-mermaid-plugin/plugin/mermaid/mermaid.min.js
- extra_javascript:
Expand All @@ -139,9 +168,11 @@ Default config (also used if no config file is present):
```yml
index:
title: Index
template: assets/templates/index.html.jinja # Comes with the pip package
slides:
theme: black
highlight_theme: monokai
template: assets/templates/slides.html.jinja # Comes with the pip package
revealjs:
history: true
slideNumber: c/t
Expand Down
16 changes: 13 additions & 3 deletions src/mkslides/assets/templates/slideshow.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
{% if highlight_theme %}
<link rel="stylesheet" href="{{ highlight_theme }}" />
{% endif %}

{% for plugin in plugins %}
{% if plugin.extra_css %}
{% for css in plugin.extra_css %}
<link rel="stylesheet" href="{{ css }}" />
{% endfor %}
{% endif %}
{% endfor %}
</head>
<body>
<div class="reveal">
Expand Down Expand Up @@ -43,9 +51,11 @@

{% if plugins %}
{% for plugin in plugins %}
{% for javascript in plugin.extra_javascript %}
<script src="{{ javascript }}"></script>
{% endfor %}
{% if plugin.extra_javascript %}
{% for javascript in plugin.extra_javascript %}
<script src="{{ javascript }}"></script>
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}

Expand Down
3 changes: 2 additions & 1 deletion src/mkslides/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class Slides:
@dataclass
class Plugin:
name: Optional[str] = None
extra_javascript: list[str] = MISSING
extra_css: Optional[list[str]] = None
extra_javascript: Optional[list[str]] = None


# For internal use only
Expand Down
2 changes: 1 addition & 1 deletion src/mkslides/markupgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __process_markdown_file(
revealjs_path=relative_revealjs_path,
markdown_data_options=markdown_data_options,
markdown=markdown_content,
revealjs_config=revealjs_config,
revealjs_config=OmegaConf.to_container(revealjs_config),
plugins=plugins,
)
self.__create_file(output_markup_path, markup)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_configs/test_plugins.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
revealjs:
menu:
openButton: true
openOnInit: true
plugins:
- name: RevealMermaid
extra_javascript:
- https://cdn.jsdelivr.net/npm/reveal.js-mermaid-plugin/plugin/mermaid/mermaid.min.js
- extra_javascript:
- https://cdn.jsdelivr.net/npm/reveal-plantuml/dist/reveal-plantuml.min.js
- name: RevealMenu
extra_javascript:
- https://cdn.jsdelivr.net/npm/reveal.js-menu@2.1.0/menu.min.js
extra_css:
- https://cdn.jsdelivr.net/npm/reveal.js-menu@2.1.0/menu.min.css
5 changes: 5 additions & 0 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def test_plugins(setup_paths: Any) -> None:
assert_html_contains(
output_path / "someslides.html",
[
'<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js-menu@2.1.0/menu.min.css" />',
'menu: {"openButton": true, "openOnInit": true}',
'<script src="https://cdn.jsdelivr.net/npm/reveal.js-menu@2.1.0/menu.min.js"></script>',
'<script src="https://cdn.jsdelivr.net/npm/reveal.js-mermaid-plugin/plugin/mermaid/mermaid.min.js"></script>',
'<script src="https://cdn.jsdelivr.net/npm/reveal-plantuml/dist/reveal-plantuml.min.js"></script>',
],
Expand All @@ -29,6 +32,8 @@ def test_plugins(setup_paths: Any) -> None:
.*?
RevealMermaid,
.*?
RevealMenu,
.*?
\]
.*?
}\);
Expand Down

0 comments on commit 39bedfa

Please sign in to comment.