如何制作聚光灯索引 Markdown 文件?

发布于 2024-07-10 10:59:53 字数 380 浏览 9 评论 0原文

我通常对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

芸娘子的小脾气 2024-07-17 10:59:53

您可以通过创建系统 RichText.mdimporter 的副本、修改其 Info.plist 并将其保存在 /Library/Spotlight 中来执行此操作,而无需禁用 SIP。

cp -r /System/Library/Spotlight/RichText.mdimporter .
patch -p2 RichText.mdimporter/Contents/Info.plist < Markdown.patch
mv RichText.mdimporter Markdown.mdimporter
sudo cp -R Markdown.mdimporter /Library/Spotlight
mdimport -r /Library/Spotlight/Markdown.mdimporter

Markdown.patch

diff -ru RichText.mdimporter/Contents/Info.plist Markdown.mdimporter/Contents/Info.plist
--- RichText.mdimporter/Contents/Info.plist 2015-11-23 16:14:12.000000000 +0200
+++ Markdown.mdimporter/Contents/Info.plist 2015-11-23 16:10:03.000000000 +0200
@@ -13,15 +13,7 @@
            <string>MDImporter</string>
            <key>LSItemContentTypes</key>
            <array>
-               <string>public.rtf</string>
-               <string>public.html</string>
-               <string>public.xml</string>
-               <string>public.plain-text</string>
-               <string>com.apple.traditional-mac-plain-text</string>
-               <string>com.apple.rtfd</string>
-               <string>com.apple.webarchive</string>
-               <string>org.oasis-open.opendocument.text</string>
-               <string>org.openxmlformats.wordprocessingml.document</string>
+               <string>net.daringfireball.markdown</string>
            </array>
        </dict>
    </array>
@@ -30,11 +22,11 @@
    <key>CFBundleGetInfoString</key>
    <string>1.0, Copyright (c) 2004-2010 Apple Inc.</string>
    <key>CFBundleIdentifier</key>
-   <string>com.apple.MDImporter.RichText</string>
+   <string>com.apple.MDImporter.Markdown</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
-   <string>Rich Text Sniffer</string>
+   <string>Markdown Sniffer</string>
    <key>CFBundleShortVersionString</key>
    <string>6.9</string>
    <key>CFBundleSupportedPlatforms</key>

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.

cp -r /System/Library/Spotlight/RichText.mdimporter .
patch -p2 RichText.mdimporter/Contents/Info.plist < Markdown.patch
mv RichText.mdimporter Markdown.mdimporter
sudo cp -R Markdown.mdimporter /Library/Spotlight
mdimport -r /Library/Spotlight/Markdown.mdimporter

Markdown.patch

diff -ru RichText.mdimporter/Contents/Info.plist Markdown.mdimporter/Contents/Info.plist
--- RichText.mdimporter/Contents/Info.plist 2015-11-23 16:14:12.000000000 +0200
+++ Markdown.mdimporter/Contents/Info.plist 2015-11-23 16:10:03.000000000 +0200
@@ -13,15 +13,7 @@
            <string>MDImporter</string>
            <key>LSItemContentTypes</key>
            <array>
-               <string>public.rtf</string>
-               <string>public.html</string>
-               <string>public.xml</string>
-               <string>public.plain-text</string>
-               <string>com.apple.traditional-mac-plain-text</string>
-               <string>com.apple.rtfd</string>
-               <string>com.apple.webarchive</string>
-               <string>org.oasis-open.opendocument.text</string>
-               <string>org.openxmlformats.wordprocessingml.document</string>
+               <string>net.daringfireball.markdown</string>
            </array>
        </dict>
    </array>
@@ -30,11 +22,11 @@
    <key>CFBundleGetInfoString</key>
    <string>1.0, Copyright (c) 2004-2010 Apple Inc.</string>
    <key>CFBundleIdentifier</key>
-   <string>com.apple.MDImporter.RichText</string>
+   <string>com.apple.MDImporter.Markdown</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
-   <string>Rich Text Sniffer</string>
+   <string>Markdown Sniffer</string>
    <key>CFBundleShortVersionString</key>
    <string>6.9</string>
    <key>CFBundleSupportedPlatforms</key>
撩起发的微风 2024-07-17 10:59:53

您必须编写一个 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.

偏爱你一生 2024-07-17 10:59:53

以下内容适用于 Mac OS X 10.11 El Capitan:

由于我们无法在 El Capitan 中编辑系统文件,因此我们必须临时禁用 SIP(​​系统完整性保护)(有关完整详细信息,请查看此 Lifehacker 文章)。

  • 重新启动计算机并按住 command + R 直至屏幕上出现 Apple 徽标,将 Mac 重新启动至恢复模式
  • 单击实用程序 > Terminal
  • 在终端窗口中,输入 csrutil disable 并按 Enter
  • 重新启动 Mac

现在我们可以编辑位于 /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).

  • Reboot your Mac into Recovery Mode by restarting your computer and holding down command + R until the Apple logo appears on your screen
  • Click Utilities > Terminal
  • In the Terminal window, type in csrutil disable and press Enter
  • Restart your Mac

Now 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
  • Add <string>net.daringfireball.markdown</string> under LSItemContentTypes (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.

再见回来 2024-07-17 10:59:53

gist 解释了如何修改 RichText.mdimporter 以导入源文件和 Markdown 文件。

This gist explains how to modify the RichText.mdimporter to import source and markdown files.

眼眸里的那抹悲凉 2024-07-17 10:59:53

可以编写一个导入器,但有一种更简单的方法。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文