文件Mine类型
配置文件的Mine类型
指定浏览器怎么打开本地的文件,因为本地文件没有HTTP的头部指定mine类型。
比如浏览器没有插件时是无法显示Markdown文件的,所以给浏览器加上了Markdown插件以后, 指定打开本地markdown文件的mime类型。
Firefox on Linux may not know how to handle markdown files by default (see #2). There are a number of possible workarounds for this (see this SuperUser question for example). Here are the 2 options that work the best:
One workaround is to add a new MIME type for markdown file extensions. Add the following XML to ~/.local/share/mime/packages/text-markdown.xml:
<?xml version="1.0"?> <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> <mime-type type="text/plain"> <glob pattern="*.md"/> <glob pattern="*.mkd"/> <glob pattern="*.mkdn"/> <glob pattern="*.mdwn"/> <glob pattern="*.mdown"/> <glob pattern="*.markdown"/> </mime-type> </mime-info>
Then run
$ update-mime-database ~/.local/share/mime
特定浏览器的mine配置
Another workaround (which might cover other OSs as well), is to edit Firefox’s private mime types.
These mime types are stored in a file indicated by helpers.private_mime_types_file, by default it is ~/.mime.types. Create this file if it does not exist, otherwise edit it, and add the following line:
type=text/plain exts=md,mkd,mkdn,mdwn,mdown,markdown, desc="Markdown document"
Then restart firefox.
Important note: On some systems, e.g. Ubuntu 21.10 or newer, firefox may be installed with a system like snap, which prevents it from reading files from your disk such as ~/.mime.types, see #86. In that case you need to use a path accessible to firefox, and expand the ~ to the full path of your home, e.g. use as filename and config value: /home/me/snap/firefox/common/mime.types − where me is your username. A suitable directory is likely the parent of .mozilla in your profile path, which you can find in about:profiles.