如何制作聚光灯索引 Markdown 文件?
我通常对 Markdown 文档使用 .markdown 或 .md 扩展名。 不幸的是,聚光灯拒绝索引它们,除非它们具有 .txt 文件扩展名。
我在 textmate 博客上看到了一个可能的解决方案,涉及编辑 Info.plist 文件。 有没有更好的办法?
更新:我刚刚发现了 Markdown 文件的 QuickLook 生成器,它添加了聚光灯支持和漂亮的 HTML 快速预览预览。 这是一种享受!
I typically use the .markdown or .md extension for markdown documents. Unfortunately spotlight refuses to index them unless they have the .txt file extension.
I've seen a possible solution involving editing Info.plist files on the textmate blog. Is there a better way?
Update: I just discovered QuickLook generator for Markdown files which adds spotlight support and nice HTML quicklook previews. It works a treat!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以通过创建系统 RichText.mdimporter 的副本、修改其 Info.plist 并将其保存在 /Library/Spotlight 中来执行此操作,而无需禁用 SIP。
Markdown.patch
You can do this without disabling SIP by creating a copy of the system RichText.mdimporter, modifying its Info.plist and saving it in /Library/Spotlight.
Markdown.patch
您必须编写一个 Spotlight 导入程序。 有一个 Xcode 项目模板,可以为您设置基本内容并帮助您入门; 我认为还有一个开发人员的例子。
您的导入程序将需要在其 Info.plist 中包含一个
UTExportedTypeDeclarations
部分,该部分描述带有路径扩展名的 markdown 文件的统一类型标识符。 然后,只需让您的导入程序向 Spotlight 传递 Markdown 文件的适当数据即可。You'll have to write a Spotlight importer. There's an Xcode project template that will set the basic stuff up for you and get you started; I think there's also a developer example.
Your importer will need a
UTExportedTypeDeclarations
section in its Info.plist that describes a Uniform Type Identifier for markdown files with you path extension. Then it's just a matter of having your importer pass Spotlight the appropriate data for a markdown file.以下内容适用于 Mac OS X 10.11 El Capitan:
由于我们无法在 El Capitan 中编辑系统文件,因此我们必须临时禁用 SIP(系统完整性保护)(有关完整详细信息,请查看此 Lifehacker 文章)。
command + R
直至屏幕上出现 Apple 徽标,将 Mac 重新启动至恢复模式实用程序
>Terminal
csrutil disable
并按 Enter现在我们可以编辑位于
/System/Library/Spotlight/RichText 的文件。 mdimporter/Contents/Info.plist
:sudo open -a TextEdit /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist
net.
(有关详细信息,请参阅 原始帖子)LSItemContentTypes
下的 daringfireball.markdown完成后,您可能想要重新索引包含 Markdown 文件的文件夹,请查看这篇文章:聚焦:如何重新索引文件夹或卷。
并且不要忘记通过重复第一部分并运行
csrutil enable
来重新打开 SIP。The following works for Mac OS X 10.11 El Capitan:
As we cannot edit system files in El Capitan, we have to temporary disable SIP (System Integrity Protection) (for full details have a look at this Lifehacker article).
command + R
until the Apple logo appears on your screenUtilities
>Terminal
csrutil disable
and press EnterNow we can edit the file located at
/System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist
:sudo open -a TextEdit /System/Library/Spotlight/RichText.mdimporter/Contents/Info.plist
<string>net.daringfireball.markdown</string>
underLSItemContentTypes
(for more infos see original post)When you are finished you may want to reindex the folders containing the Markdown files, have a look at this article for that: Spotlight: How to re-index folders or volumes.
And don’t forget to turn SIP back on by repeating the first part and running
csrutil enable
.此 gist 解释了如何修改 RichText.mdimporter 以导入源文件和 Markdown 文件。
This gist explains how to modify the RichText.mdimporter to import source and markdown files.
您可以编写一个导入器,但有一种更简单的方法。 Markdown 只是文本,由 Spotlight 处理。 如果您为 Markdown 文件指定扩展名“.txt”,Spotlight 将会识别它们。
就我而言,我只是将所有内容命名为以“.mdwn.txt”结尾,并教 emacs 的 markdown 模式激活与此扩展名匹配的文件。
You could write a Importer, but there's an easier way. Markdown is just text, which Spotlight handles. If you give your markdown files the extension ".txt", Spotlight will pick them up.
In my case, I just named mine all to end with ".mdwn.txt" and taught emacs' markdown-mode to activate for files matching this extension.