Skip to content

Commit e412a37

Browse files
committed
Allow to set default title in metadata
Allow to set the default title for each metadata block. This allows to omit the title when creating divs.
1 parent e5ab6d1 commit e412a37

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

docs/usage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pandoc-beamer-block:
1919
- classes: [info]
2020
- classes: [alert]
2121
type: alert
22+
title: Danger
2223
~~~
2324

2425
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:
3132
transformation will be applied. This parameter is mandatory.
3233
* `type`: the block type (either `alert`, `example`, `info`, `theorem`,
3334
`proof`, `corollary`, `definition`, `lemma` and `fact`)
35+
* `title`: an optional default title to use
3436

3537
## Example
3638

src/pandoc_beamer_block/_main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def prepare(doc: Doc):
3333
):
3434
definition["classes"] = frozenset(definition["classes"])
3535
definition["type"] = definition.get("type", "info")
36+
definition["title"] = definition.get("title", "")
3637
doc.defined.append(definition)
3738

3839

@@ -110,7 +111,7 @@ def block(elem: Element, doc: Doc) -> list[Element] | None:
110111
output_format="latex",
111112
)
112113
else:
113-
title = ""
114+
title = definition["title"]
114115

115116
if definition["type"] == "alert":
116117
return latex(elem, "alertblock", title)

tests/test_block.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ def test_title_complex(self):
127127
---
128128
pandoc-beamer-block:
129129
- classes: ['class1', 'class2']
130+
title: Ignored
130131
---
131132
::: {.class1 .class2 title="**My Title**"}
132133
:::
@@ -141,3 +142,25 @@ def test_title_complex(self):
141142
)
142143
self.assertIn("\\begin{block}{\\textbf{My Title}}", text)
143144
self.assertIn("\\end{block}", text)
145+
146+
def test_title_default(self):
147+
doc = BlockTest.conversion(
148+
"""
149+
---
150+
pandoc-beamer-block:
151+
- classes: ['class1']
152+
title: My Title
153+
---
154+
::: class1 :::
155+
:::
156+
""",
157+
"beamer",
158+
)
159+
text = convert_text(
160+
doc,
161+
input_format="panflute",
162+
output_format="latex",
163+
extra_args=["--wrap=none"],
164+
)
165+
self.assertIn("\\begin{block}{My Title}", text)
166+
self.assertIn("\\end{block}", text)

0 commit comments

Comments
 (0)