diff --git a/docs/usage.md b/docs/usage.md index c2a3f9e..649ae33 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -19,6 +19,7 @@ pandoc-beamer-block: - classes: [info] - classes: [alert] type: alert + title: Danger ~~~ The metadata block above is used to add a `block` environment around @@ -31,6 +32,7 @@ Each entry of `pandoc-beamer-block` is a YAML dictionary containing: transformation will be applied. This parameter is mandatory. * `type`: the block type (either `alert`, `example`, `info`, `theorem`, `proof`, `corollary`, `definition`, `lemma` and `fact`) +* `title`: an optional default title to use ## Example diff --git a/src/pandoc_beamer_block/_main.py b/src/pandoc_beamer_block/_main.py index b7d5f06..230d281 100644 --- a/src/pandoc_beamer_block/_main.py +++ b/src/pandoc_beamer_block/_main.py @@ -33,6 +33,7 @@ def prepare(doc: Doc): ): definition["classes"] = frozenset(definition["classes"]) definition["type"] = definition.get("type", "info") + definition["title"] = definition.get("title", "") doc.defined.append(definition) @@ -110,7 +111,7 @@ def block(elem: Element, doc: Doc) -> list[Element] | None: output_format="latex", ) else: - title = "" + title = definition["title"] if definition["type"] == "alert": return latex(elem, "alertblock", title) diff --git a/tests/test_block.py b/tests/test_block.py index 4743083..128b06c 100644 --- a/tests/test_block.py +++ b/tests/test_block.py @@ -127,6 +127,7 @@ def test_title_complex(self): --- pandoc-beamer-block: - classes: ['class1', 'class2'] + title: Ignored --- ::: {.class1 .class2 title="**My Title**"} ::: @@ -141,3 +142,25 @@ def test_title_complex(self): ) self.assertIn("\\begin{block}{\\textbf{My Title}}", text) self.assertIn("\\end{block}", text) + + def test_title_default(self): + doc = BlockTest.conversion( + """ +--- +pandoc-beamer-block: + - classes: ['class1'] + title: My Title +--- +::: class1 ::: +::: + """, + "beamer", + ) + text = convert_text( + doc, + input_format="panflute", + output_format="latex", + extra_args=["--wrap=none"], + ) + self.assertIn("\\begin{block}{My Title}", text) + self.assertIn("\\end{block}", text)