We planned to upgrade GitLab and Mattermost to the latest version this Friday morning (early). You may experience some downtime!

Verified Commit 1316f3c7 authored by Camil Staps's avatar Camil Staps 🚀

Documentation browser

parent feb6320a
/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);
......@@ -20,24 +20,33 @@ function loadModule(elem) {
viewer.innerHTML = '<p id="loading">Loading...</p>';
var url = 'src.php';
url += '?lib=' + libselect.value;
var url = 'src.php?';
if (libselect != null)
url += 'lib=' + libselect.value + '&';
if (curmod != '')
url += '&mod=' + curmod;
if (icl.checked)
url += '&icl';
url += 'mod=' + curmod + '&';
if (icl != null && icl.checked)
url += 'icl';
var hashelems = decodeURIComponent(window.location.hash.substring(1)).split(';');
for (var i in hashelems)
var jump = line != null ? 'line-' + line : null;
for (var i in hashelems) {
if (hashelems[i].substring(0,5) == 'line=')
url += '&line=' + hashelems[i].substring(5);
if (hashelems[i].substring(0,5) == 'jump=')
jump = hashelems[i].substring(5);
}
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
viewer.innerHTML = xmlHttp.response;
if (line != null)
document.getElementById('line-' + line).scrollIntoView(true);
console.log(jump);
if (jump != null) {
var elem = document.getElementById(jump) || document.getElementsByName(jump)[0];
elem.scrollIntoView(true);
}
var linenos = document.getElementsByClassName('special');
for (var i = 0; i < linenos.length; i++) {
......@@ -77,7 +86,7 @@ function updateLibraryPanel() {
function updateHash() {
var newhash = curmod;
if (icl.checked)
if (icl != null && icl.checked)
newhash += ';icl';
if (line != null)
newhash += ';line=' + line;
......@@ -111,9 +120,11 @@ function selectLine(elem) {
}
function restoreShareUI() {
share_button.disabled = false;
share_button.type = 'button';
share_button.value = 'Share';
if (share_button != null) {
share_button.disabled = false;
share_button.type = 'button';
share_button.value = 'Share';
}
}
function shareButtonClick() {
......@@ -138,7 +149,7 @@ window.onhashchange = function() {
} else {
var elems = decodeURIComponent(window.location.hash.substring(1)).split(';');
curmod = elems[0];
icl.checked = elems.indexOf('icl') != -1;
if (icl != null) icl.checked = elems.indexOf('icl') != -1;
for (var i in elems)
if (elems[i].substring(0,5) == 'line=')
line = elems[i].substring(5);
......@@ -158,11 +169,11 @@ window.onload = function () {
viewer.style.height = height + 'px';
}
libselect.onchange = function() {
if (libselect != null) libselect.onchange = function() {
window.location.href = '?lib=' + this.value;
}
icl.onchange = function() {
if (icl != null) icl.onchange = function() {
line = null;
loadModule();
}
......
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