TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Display C sources in chrome

1 点作者 lrizzo大约 13 年前
One of the most annoying features of chromium is that it downloads instead of displaying various types of files (.c, .h and so on).<p>After a bit of investigation i found that at least for local files you can override this by defining your preferred mime types in ~/.local/share/mime/globs2 as follows:<p><pre><code> &#62; cat ~/.local/share/mime/globs2 10:text/plain:*.c 10:text/plain:*.cc 10:text/plain:*.c++ 10:text/plain:*.cpp 10:text/plain:*.h </code></pre> The first field is the priority (smaller number means more important), then follows the mime type, then the pattern that you are matching. The default rules (/usr/local/share/ ...) have a priority of 50 for .c, .h and so on.<p>For remotely-served files, the browser relies on the MIME Type supplied by the server and the trick above does not work.<p>Looking at the Chromium sources<p><pre><code> chromium-courgette-redacted-18.0.1025.162/net/base/mime_util.cc </code></pre> it seems that a partial fix can be achieved by adding the list of types we want to display to the array<p><pre><code> static const char* const supported_non_image_types[] = { ...</code></pre> + "text/x-csrc", + "text/x-chdr", ... }<p>although i'd rather find a way to override the server-supplied mime type in a way that does not require rebuilding Chrome.<p>Anyways, at least for local browsing, this seems a significant improvement.<p><pre><code> cheers luigi</code></pre>

2 条评论

cremno大约 13 年前
There are extensions that open such files. These extensions do mainly syntax highlighting like: <a href="https://chrome.google.com/webstore/detail/cgjalgdhmbpaacnnejmodfinclbdgaci" rel="nofollow">https://chrome.google.com/webstore/detail/cgjalgdhmbpaacnnej...</a> <a href="https://chrome.google.com/webstore/detail/epmaefhielclhlnmjofcdapbeepkmggh" rel="nofollow">https://chrome.google.com/webstore/detail/epmaefhielclhlnmjo...</a> (offers some more features but does not work when AdBlock is enabled)<p>So opening instead of downloading is possible by using an extension. Perhaps an extension already exists which does that without any other features.
wildtype大约 13 年前
I use slackware on a laptop with 512mb RAM. Last time i build chromium package with slackbuilds, it takes a night long..