aboutsummaryrefslogtreecommitdiff
path: root/textoutpc/builtin/_Title.py
blob: 05d12ff57fe85a941b52b36783e523f833b5ac88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
#******************************************************************************
# Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
# This file is part of the textoutpc project, which is MIT-licensed.
#******************************************************************************

from .. import BlockTag as _BlockTag

__all__ = ["TitleTag"]


class TitleTag(_BlockTag):
	""" The title tag.
		Example uses:

		[title]Some title[/title]
		[subtitle]Some subtitle[/subtitle]
	"""

	aliases = ('[title]', '[subtitle]')
	raw = True

	def prepare(self, name, value):
		level = self.tweak("title_level", "1")
		if level[0] == "h":
			level = level[1:]
		level = int(level)
		assert 1 <= level <= 5

		# Name.

		self._level = name[1:-1]

		# HTML tag.

		level += self._level == "subtitle"
		self._tag = f"h{level}"

	def begin_html(self):
		return f'<{self._tag} class="{self._level}">'

	def end_html(self):
		return f'</{self._tag}>'

	def begin_lightscript(self):
		return '#' * ((self._level == "subtitle") + 1) + ' '

# End of file.