1.1 --- a/moinformat/themes/default/html.py Mon Nov 26 16:05:50 2018 +0100
1.2 +++ b/moinformat/themes/default/html.py Mon Nov 26 16:10:17 2018 +0100
1.3 @@ -20,6 +20,8 @@
1.4 """
1.5
1.6 from moinformat.themes.common import Theme
1.7 +from os import listdir
1.8 +from os.path import splitext
1.9
1.10 class DefaultHTMLTheme(Theme):
1.11
1.12 @@ -28,6 +30,38 @@
1.13 name = "html"
1.14 origin = __file__
1.15
1.16 + link = '<link rel="stylesheet" type="text/css" charset="utf-8" media="%(media)s" href="%(root)s/_css/%(filename)s" />\n'
1.17 +
1.18 + def get_links(self, subs):
1.19 +
1.20 + "Using 'subs', return a string containing markup linking to resources."
1.21 +
1.22 + d = {}
1.23 + d.update(subs)
1.24 +
1.25 + links = []
1.26 +
1.27 + for filename in listdir(self.get_resource("css")):
1.28 +
1.29 + # Only link to CSS files.
1.30 +
1.31 + if splitext(filename)[-1] != ".css":
1.32 + continue
1.33 +
1.34 + # Filenames can have the form <media>_<name>.css to set the media
1.35 + # type.
1.36 +
1.37 + t = filename.split("_")
1.38 +
1.39 + d["media"] = len(t) > 1 and t[0] or "all"
1.40 + d["filename"] = filename
1.41 +
1.42 + links.append(self.link % d)
1.43 +
1.44 + return "".join(links)
1.45 +
1.46 + # Public methods.
1.47 +
1.48 def apply(self, text):
1.49
1.50 "Apply this theme to the given 'text', returning a themed version."
1.51 @@ -39,6 +73,7 @@
1.52 "text" : text,
1.53 "title" : self.metadata.get("pagename"),
1.54 }
1.55 + subs["links"] = self.get_links(subs)
1.56 return template % subs
1.57
1.58 def install_resources(self):