1.1 --- a/moinformat/macros/attachlist.py Mon Apr 15 22:07:03 2019 +0200
1.2 +++ b/moinformat/macros/attachlist.py Mon Apr 15 22:07:26 2019 +0200
1.3 @@ -19,6 +19,7 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 +from mimetypes import guess_type
1.8 from moinformat.macros.common import Macro
1.9 from moinformat.tree.moin import Link, LinkLabel, List, ListItem, Text
1.10 from moinformat.utils.links import LinkTarget
1.11 @@ -43,10 +44,21 @@
1.12 # Access the input context to get the attachment details.
1.13
1.14 input = self.metadata.get_input()
1.15 - filenames = pagename and input.get_attachments(pagename) or []
1.16
1.17 # Select attachments by type.
1.18 - # NOTE: To do.
1.19 +
1.20 + all_filenames = pagename and input.get_attachments(pagename) or []
1.21 +
1.22 + if mimetype:
1.23 + filenames = []
1.24 +
1.25 + for filename in all_filenames:
1.26 + type, encoding = guess_type(filename)
1.27 +
1.28 + if type == mimetype:
1.29 + filenames.append(filename)
1.30 + else:
1.31 + filenames = all_filenames
1.32
1.33 # Prepare a list of links.
1.34