(no commit message) master
authorChristian Weiske <cweiske@cweiske.de>
Wed, 3 Jun 2015 21:43:39 +0000 (23:43 +0200)
committerwww-cweiske <www-cweiske@localhost.localdomain>
Wed, 3 Jun 2015 21:43:39 +0000 (23:43 +0200)
build-toc.php
example-output.html [new file with mode: 0644]

index f585731f4efbc813838fad4957910d6071a6165f..73970eda0f7a3b98d3e1cf25e0262d8c180f29ee 100644 (file)
@@ -1,79 +1,79 @@
-#!/usr/bin/env php
-<?php
-/**
- * Creates a TOC (table of contents) from a given HTML file.
- * <h1> is ignored; all other headings are used.
- *
- * @author Christian Weiske <cweiske@cweiske.de>
- *
- * Alternative if you have an XSLT 2 processor: http://xmlplease.com/tocxhtml
- */
-if ($argc < 2) {
-    echo "Please pass a file\n";
-    exit(1);
-}
-$file = $argv[1];
-if (!file_exists($file)) {
-    echo "File does not exist: $file\n";
-    exit(2);
-}
-if (substr($file, -4) != '.htm') {
-    echo "build-toc.php works only on htm files\n";
-    exit(3);
-}
-
-$sx = simplexml_load_file($file);
-if ($sx === false) {
-    echo "Failed to load XML\n";
-    exit(4);    
-}
-
-$body = $sx->body;
-$body->registerXPathNamespace('h', 'http://www.w3.org/1999/xhtml');
-$elems = $body->xpath(
-    '//*['
-    //XHTML
-    . 'self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6'
-    //HTML
-    . ' or self::h2 or self::h3 or self::h4 or self::h5 or self::h6'
-    . ']'
-);
-
-$data = array();
-$n = -1;
-foreach ($elems as $elem) {
-    $name = $elem->getName();
-    $level = (int) $name{1};
-    $data[] = (object) array(
-        'title' => (string) $elem,
-        'id'    => (string) $elem['id'],
-        'level' => $level,
-        'nextLevel' => null
-    );
-    if (++$n >= 1) {
-        $data[$n - 1]->nextLevel = $level;
-    }
-}
-
-$html = "<ul class=\"toc\">\n";
-foreach ($data as $h) {
-    $i = str_repeat(' ', ($h->level -1) * 2 - 1);
-    $html .= $i
-        . '<li><a href="#' . $h->id . '">'
-        . htmlspecialchars($h->title)
-        . '</a>';
-    if ($h->nextLevel > $h->level) {
-        $html .= "\n"
-            . $i . ' <ul>' . "\n";
-    } else {
-        $html .= '</li>' . "\n";
-    }
-    if ($h->nextLevel < $h->level) {
-        $html .= substr($i, 0, -1) . "</ul>\n"
-            . substr($i, 0, -2) . "</li>\n";
-    }
-}
-
-$html .= "</ul>\n";
-echo $html;
-?>
+#!/usr/bin/env php\r
+<?php\r
+/**\r
+ * Creates a TOC (table of contents) from a given HTML file.\r
+ * <h1> is ignored; all other headings are used.\r
+ *\r
+ * @author Christian Weiske <cweiske@cweiske.de>\r
+ *\r
+ * Alternative if you have an XSLT 2 processor: http://xmlplease.com/tocxhtml\r
+ */\r
+if ($argc < 2) {\r
+    echo "Please pass a file\n";\r
+    exit(1);\r
+}\r
+$file = $argv[1];\r
+if (!file_exists($file)) {\r
+    echo "File does not exist: $file\n";\r
+    exit(2);\r
+}\r
+if (substr($file, -4) != '.htm') {\r
+    echo "build-toc.php works only on htm files\n";\r
+    exit(3);\r
+}\r
+\r
+$sx = simplexml_load_file($file);\r
+if ($sx === false) {\r
+    echo "Failed to load XML\n";\r
+    exit(4);    \r
+}\r
+\r
+$body = $sx->body;\r
+$body->registerXPathNamespace('h', 'http://www.w3.org/1999/xhtml');\r
+$elems = $body->xpath(\r
+    '//*['\r
+    //XHTML\r
+    . 'self::h:h2 or self::h:h3 or self::h:h4 or self::h:h5 or self::h:h6'\r
+    //HTML\r
+    . ' or self::h2 or self::h3 or self::h4 or self::h5 or self::h6'\r
+    . ']'\r
+);\r
+\r
+$data = array();\r
+$n = -1;\r
+foreach ($elems as $elem) {\r
+    $name = $elem->getName();\r
+    $level = (int) $name{1};\r
+    $data[] = (object) array(\r
+        'title' => (string) $elem,\r
+        'id'    => (string) $elem['id'],\r
+        'level' => $level,\r
+        'nextLevel' => null\r
+    );\r
+    if (++$n >= 1) {\r
+        $data[$n - 1]->nextLevel = $level;\r
+    }\r
+}\r
+\r
+$html = "<ul class=\"toc\">\n";\r
+foreach ($data as $h) {\r
+    $i = str_repeat(' ', ($h->level -1) * 2 - 1);\r
+    $html .= $i\r
+        . '<li><a href="#' . $h->id . '">'\r
+        . htmlspecialchars($h->title)\r
+        . '</a>';\r
+    if ($h->nextLevel > $h->level) {\r
+        $html .= "\n"\r
+            . $i . ' <ul>' . "\n";\r
+    } else {\r
+        $html .= '</li>' . "\n";\r
+    }\r
+    if ($h->nextLevel < $h->level) {\r
+        $html .= substr($i, 0, -1) . "</ul>\n"\r
+            . substr($i, 0, -2) . "</li>\n";\r
+    }\r
+}\r
+\r
+$html .= "</ul>\n";\r
+echo $html;\r
+?>\r
diff --git a/example-output.html b/example-output.html
new file mode 100644 (file)
index 0000000..ae9388c
--- /dev/null
@@ -0,0 +1,24 @@
+<ul class="toc">\r
+ <li><a href="#detection">USB device detection</a>\r
+  <ul>\r
+   <li><a href="#detection-pc">Linux PC</a></li>\r
+   <li><a href="#detection-ouya">OUYA</a></li>\r
+   <li><a href="#whatnow">What now?</a></li>\r
+  </ul>\r
+ </li>\r
+ <li><a href="#drivers">Linux drivers</a>\r
+  <ul>\r
+   <li><a href="#ouya-config">OUYA kernel configuration</a></li>\r
+  </ul>\r
+ </li>\r
+ <li><a href="#own-kernel">A custom OUYA linux kernel</a>\r
+  <ul>\r
+   <li><a href="#prep">Preparation</a></li>\r
+   <li><a href="#ramdisk">Ramdisk</a></li>\r
+   <li><a href="#ndk">Android NDK</a></li>\r
+   <li><a href="#kernel-git">OUYA kernel + configuration</a></li>\r
+   <li><a href="#install">Installing the kernel</a></li>\r
+   <li><a href="#dmesg">Success!</a></li>\r
+  </ul>\r
+ </li>\r
+</ul>\r