Importing WordPress Codex as a dictionary into the Dictionary app
I'm an avid WordPress developer, and I'm constantly referring to the Wordpress Codex to look up various functions. I recently got a new 2013 MBP, and I just found the glorious "three finger tap to look up" function. Now, I've read that it's possible to change the dictionary that's used by adding or removing dictionaries from Dictionary.app, but I'm interested in doing something different.
Has anybody found a way to import WordPress Codex into the Dictionary app? Essentially, I want to be able to highlight a WordPress function, three finger tap, and be presented with the Codex article (or at least an abridged version with usage and params).
Finished dictionary
I found a Wiki parser that cleaned much the Codex exported XML, then did some extra clean up using TextMate regex search/replace and managed to build a decent dictionary:
Minor issues will be found as the Codex is a collective effort, and formatting may vary from article to article.
I put the source files and finished .dictionary
file on Dropbox:
- PHP files to build a custom XML from WordPress Codex exported XML
- Project files to build the dictionary
-
Final dictionary file, put on
~/Library/Dictionaries
Mirror on Google Drive (zip contents viewable).
Initial steps
I was able to create a very rough Codex dictionary using this resources:
Following the steps to install and make a dictionary described in How can I create a dictionary for Mac OS X?
-
A sample XML file from the tool SQL to Apple Dictionary
<?xml version="1.0" encoding="UTF-8"?> <!-- This is a sample dictionary source file. It can be built using Dictionary Development Kit. --> <d:dictionary xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng"> <d:entry id="ldap" d:title="LDAP"> <d:index d:value="LDAP"/> <h1>LDAP</h1> <p>Lightweight Directory Access Protocol</p> </d:entry> <d:entry id="midi" d:title="MIDI"> <d:index d:value="MIDI"/> <h1>MIDI</h1> <p>Musical Instrument Digital Interface</p> </d:entry> <d:entry id="xml" d:title="XML"> <d:index d:value="XML"/> <h1>XML</h1> <p>Extensible Markup Language</p> </d:entry> </d:dictionary>
A PHP script to convert the exported Codex XML file to conform with the sample file. Here's a Google Drive file with the resulting XML (70 thousand lines) and a Gist with the conversion script.
This is the result:
As can be seen, the biggest issue is to convert WordPress markup language into HTML.
Apple shows you how to create and add Custom Dictionaries to it's Dictionary Applications in the Dictionary Services Programming Guide
It includes examples and a guide on the dictionary XHTML markup.