Verified Commit c797bcd6 authored by Camil Staps's avatar Camil Staps 🚀

Documentation browser

parents 4423136b 1316f3c7
/opt/clean/doc/CleanLangRep/CleanRep.2.2.css
\ No newline at end of file
/opt/clean/doc/CleanLangRep/CleanRep.2.2_files/
\ No newline at end of file
<?php
define('CLEANHOME', '/opt/clean');
$dom = new DOMDocument;
$dom->loadHTMLFile(CLEANHOME . '/doc/CleanLangRep/CleanRep.2.2_1.htm');
function readContentsLevel($dom, $level) {
}
function isToc($class) {
return preg_match('/^MsoToc\d$/', $class) === 1;
}
function cleanToc($name) {
$name = preg_replace(['/[\r\x80-\xff]+/', '/\n/'], ['', ' '], $name);
$matches = [];
if (preg_match_all('/^([\d\.]+)?\s*(.+?)\s+[iv\d]+$/', $name, $matches) === 1)
return [
'index' => $matches[1][0],
'title' => preg_replace('/Chapter \d+\s+/', '', $matches[2][0]),
];
else
return null;
}
$toc = [];
foreach ($dom->getElementsByTagName('p') as $p) {
if (isToc($p->getAttribute('class'))) {
$elem = cleanToc($p->textContent);
if ($elem != null) {
$elem['level'] = (int) str_replace('MsoToc', '', $p->getAttribute('class'));
$elem['link'] = str_replace('#', ';jump=', $p->getElementsByTagName('a')[0]->getAttribute('href'));
$toc[] = $elem;
}
}
}
class Toc {
protected $title = '';
protected $link = '';
protected $ref = null;
protected $children = [];
public static function factory($level, $elems) {
$toc = new Toc;
while (count($elems) > 0) {
$elem = array_shift($elems);
if ($elem['level'] <= $level) {
$deeper = [];
while ($elems[0]['level'] > $level)
$deeper[] = array_shift($elems);
$child = Toc::factory($level + 1, $deeper);
$child->title = $elem['title'];
$child->link = $elem['link'];
$toc->children[] = $child;
}
}
return $toc;
}
public function printTree() {
echo '<div class="browser togglee">';
foreach ($this->children as $child) {
if ($child->isLeaf()) {
echo '<div class="browser-item module" onclick="loadModule(this)" ' .
'data-module="' . $child->link . '">' . $child->title . '</span>' .
'</div>';
} else {
echo '<div class="browser-item directory toggle-container">' .
'<span class="toggler" onclick="toggle(this)">' .
'<span class="toggle-icon">&#x229e</span>' .
'<span class="title">' . $child->title . '</span></span>';
$child->printTree();
echo '</div>';
}
}
echo '</div>';
}
public function isLeaf() {
return count($this->children) == 0;
}
}
$toc = Toc::factory(1, $toc);
$toc->printTree();
<!DOCTYPE html>
<html>
<head>
<title>Documentation browser</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content="Cloogle is the unofficial Clean language search engine"/>
<meta name="keywords" content="Clean,Clean language,Concurrent Clean,search,functions,search engine,programming language,clean platform,iTasks,cloogle,hoogle"/>
<script src="../common.js" type="text/javascript" defer="defer"></script>
<script src="../src/view.js" type="text/javascript" defer="defer"></script>
<link rel="stylesheet" href="../common.css" type="text/css"/>
<link rel="stylesheet" href="../src/view.css" type="text/css"/>
<style type="text/css">
.Heading1Chapter img, .Newchapter img {
display: none;
}
</style>
</head>
<body>
<div id="sidebar">
<a href="/"><img id="logo" src="../logo.png" alt="Cloogle logo"/></a>
<h3>Documentation browser</h3>
<hr/>
<?php include_once('contents.php'); ?>
</div><div id="viewer">
<?php include_once('src.php'); ?>
</div>
</body>
</html>
/opt/clean/doc/CleanLangRep/square_8.png
\ No newline at end of file
<?php
define('CLEANHOME', '/opt/clean');
$loc = isset($_REQUEST['mod']) ? $_REQUEST['mod'] : 'CleanRep.2.2_1.htm;jump=_Toc311797959';
$loc = preg_replace('/\.\.+/', '.', $loc);
$loc = preg_replace('/[^\w\d.;=]+/', '', $loc);
$match = [];
$file = preg_match('/(.+);jump=(.+)/', $loc, $match) > 0 ? $file = $match[1] : $loc;
$doc = new DOMDocument;
$doc->loadHTMLFile(CLEANHOME . '/doc/CleanLangRep/' . $file);
function transformLink($orgfile, $a) {
$href = $a->getAttribute('href');
$match = [];
if (preg_match('/^(.*)#(.*)$/', $href, $match) == 0)
$a->setAttribute('href', '#' . $href);
$file = $match[1] != '' ? $match[1] : $orgfile;
$hash = $match[2];
$a->setAttribute('href', '#' . $file . ';jump=' . $hash);
}
foreach ($doc->getElementsByTagName('a') as $a) {
transformLink($file, $a);
}
echo $doc->saveHtml($doc);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment