Dash is a tool for viewing APIs on Mac. Most API documents can be downloaded directly, but sometimes we want to integrate existing documents into dash, we need to do it ourselves, in fact, dash official also has a tutorial on how to make docset, address is: http://kapeli.com/docsets (7. any HTML documentation), this article is based on the official tutorial, the process steps are recorded step by step, you can refer.
All documents required by Dash are docset files. In fact, the docset file is a folder, which contains the final HTML document, and the indexes created based on these HTML (the indexes are stored in the SQLite database) are very simple.
The following uses mysql5.1 official Chinese Document (HTML) as an example to describe how to create docset step by step based on the HTML document.
1. from the MySQL official website download 5.1 HTML Chinese documents, for: http://downloads.mysql.com/docs/refman-5.1-zh.html-chapter.zip, download decompressed, will find all are some HTML files, there are 2 rows, index.html, ix01.html, the first is the home page directory, the second is all the index list, these two files basically contain all MySQL indexes. We will create indexes based on the dash format.
2. Create a folder. In this example, the document we created is called mysql51, so create a directory in the following structure:
mkdir -p mysql51.docset/Contents/Resources/Documents/
3. Copy all HTML documents to the Documents folder.
4. Create the info. plist file in mysql51.doc set/contents/. Note the case sensitivity of the file name. The file content is as follows:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>dashIndexFilePath</key><string>index.html</string><key>CFBundleIdentifier</key><string>mysql51</string><key>CFBundleName</key><string>mysql51</string><key>DocSetPlatformFamily</key><string>mysql51</string><key>isDashDocset</key><true/></dict></plist>
You can see that this file is an XML file, which contains a pair of key-string configuration items. The key pair "dashindexfilepath" corresponds to" string.html ", indicating what the default homepage is after you click your document in Dash, other keys indicate the name and keyword of the document you created. I have written them as mysql51.
5. Create an SQLite index. The index file is located at mysql51.docset/contents/resources/docset. dsidx. SQLite is pre-installed on the Mac computer, so you can directly go to the resources folder from the command line and click:
sqlite3 docSet.dsidx
In this way, you enter the SQLite database. Next, create a data table:
CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);
After completion, click :. exit to exit SQLite. At this time, you will see that there is a docset in the resources directory. dsidx file. Our indexes will be placed in the searchindex table just created. (Enter ". Exit" in SQLite to exit. You can enter ". Help" to view other commands)
In the official tutorial, a unique index is created after a table is created. We cannot do this here. As we will talk about later, one key in our document has multiple indexes, so it cannot be unique.
6. insert data to the searchindex table. The SQL template is:
INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (‘name‘, ‘type‘, ‘path‘);
Name is our keyword. For example, if you want to input a SELECT statement in Dash, the SELECT statement is the keyword. type is the type of the keyword, which is officially supported, what class, function, keyword and so on? I stole a lazy here, and all of them use keyword. path is the name of our specific file. It can be in the form of an anchor, for example: client-side-scripts.html # mysqladmin.
7. After all the index data is inserted into searchindex, the docsetfile is created. You can directly double-click mysql51.doc set to import dash.
The following describes how to create an index through an HTML file and insert it to the SQLite database. Many scripts are provided in the dash official tutorial, including python, Ruby, PHP, OC, and nodejs, in fact, you can use any language, as long as you can generate an SQL file, in SQLite through. just import the READ command. Let's use PHP to try it out. For example, mysqlhas two index files, index.html and ix01.html. I wrote two PHP scripts to output a large number of SQL statements:
<?phpheader('Content-type: text/html; charset=utf-8');echo "<meta charset='utf-8'/>";$dom = new DomDocument;@$dom->loadHTMLFile("/Users/xxx/Desktop/docSet/mysql51.docset/Contents/Resources/Documents/index.html");foreach ($dom->getElementsByTagName("a") as $a) {$href = $a->getAttribute("href");if (substr($href, 0, 1) == ".") continue;if (substr($href, 0, 5) == "http:") continue;$name = trim($a->nodeValue);$name = trim(preg_replace("#\s+#", "", preg_replace("#^([A-Z0-9–]+\.)+#", "", $name)));if (empty($name)) continue;$class = "Keyword";$links[$name] = true;echo "INSERT INTO searchIndex(name, type, path) VALUES ('". $name . "','". $class ."','". $href ."');<br/>";}?>
<?phpheader('Content-type: text/html; charset=utf-8');echo "<meta charset='utf-8'/>";$dom = new DomDocument;@$dom->loadHTMLFile("/Users/bokix/Desktop/docSet/mysql51.docset/Contents/Resources/Documents/ix01.html");foreach ($dom->getElementsByTagName("dt") as $a) {$name = $a->nodeValue;//echo "$name";//echo "<br/>";//echo "===================$name <br/>";$children = $a->childNodes; if($children->length == 1){//echo $name . "has no child <br/>";continue;} for($i = 0; $i < $children->length; $i++) { $child = $children->item($i); if($i==0){ $name = trim($child->nodeValue); if(substr($name,-3) == ","){ $name = substr($name,0,$name->length-3); } //$name = mysql_real_escape_string($name); } if($child->nodeName !="a"){ //echo "[".$child->nodeValue . "]not a anchor <br/>"; continue; } $href = $child->getAttribute("href"); $hrefName=trim($child->nodeValue); $class = "Keyword"; //$hrefName = mysql_real_escape_string($hrefName); echo "INSERT INTO searchIndex(name, type, path) VALUES ('". $name . "','". $class ."','". $href ."');<br/>"; echo "INSERT INTO searchIndex(name, type, path) VALUES ('". $hrefName . "','". $class ."','". $href ."');<br/>"; }}?>
After running, a pile of SQL statements are output on the screen and saved to two files, for example, 1. for SQL and 2. SQL, note that the escape of single quotation marks in SQLite is to add a single quotation mark before single quotation marks, which is different from other SQL statements. In our index HTML, some names are '\' (slashes and single quotation marks), so you have to manually modify them. Fortunately, you can search for them in the SQL file :\', add a single quotation mark before a single quotation mark.
After the SQL file is generated, copy the two SQL files to the docset. dsidx directory and start importing SQLite:
sqlite3 docSet.dsidx.read 1.sql.read 2.sql
If the SQL statement is correctly executed, nothing will be output on the screen. If a lot of SQL statements are output, it indicates that there is a problem with the SQL statement. Go to the first one to see what is wrong, and then modify and re-import the SQL statement, if you are afraid of repeated import, you can clear the searchindex table and re-import it.
Here are some SQL examples I have generated:
Insert into searchindex (name, type, PATH) values functions # string-Functions '); insert into searchindex (name, type, PATH) values ('your strings', 'keyword', 'functions.html # string-Functions '); insert into searchindex (name, type, PATH) values functions # string-Functions '); insert into searchindex (name, type, PATH) values ('your strings', 'keyword', 'functions.html # string-Functions '); insert into searchindex (name, type, PATH) values ('odbc', 'keyword', 'connectors.html # ODBC-connector '); insert into searchindex (name, type, PATH) values ('mysql ctor/odbc', 'keyword', 'connectors.html # ODBC-ctor '); insert into searchindex (name, type, PATH) values ('partitioning interval # partitioning-types '); insert into searchindex (name, type, PATH) values ('partition names ', 'keyword', 'partitioning.html # partitioning-types ');
Create docset documents for dash on Mac