README.md is detected as text/x-matlab
This Pandoc-flavoured markdown file
$ cat README.md
% Title
% Author
# This is a markdown file...
...with a title block for [Pandoc-flavoured markdown](https://pandoc.org/MANUAL.html#extension-pandoc_title_block)
is detected as text/x-matlab
, not as text/markdown
(as its suffix implies) or text/x-readme
(as its prefix implies):
$ xdg-mime query filetype README.md
text/x-matlab
I think the reason is the following. Globs don't give a unique result since both README.*
from text/x-readme
and *.md
from text/markdown
match. Then xdg-mime
looks at the file contents. Neither text/markdown
nor text/x-readme
define any magics. However text/x-matlab
has this magic defined:
<magic priority="10">
<match type="string" value="%" offset="0"/>
</magic>
Thus, the %
as the first character makes xdg-mime
thinks it is a text/x-matlab
file.
I think this file should be identified by xdg-mime
as text/markdown
.
The %
magic from text/x-matlab
clashes with pandoc requiring the %
to be the first character for its markdown title block parsing.
I guess this could be worked around by adding a magic for the %
character to text/markdown
similar to that for text/x-matlab
? I would be willing to provide a patch to do this, but I'm not sure if this is the right approach. Maybe xdg-mime
should behave differently in such cases where the mime type from file contents (text/x-matlab
) is not one of those from the globs (text/markdown
and text/x-readme
)? I.e. maybe xdg-mime
should just return the highest-weight glob match (text/markdown
) and ignore the file content matches in such cases?
Fwiw, I think this is a similar issue as #127 (closed).