diff --git a/frontend/doc/CleanRep.2.2.css b/frontend/doc/CleanRep.2.2.css new file mode 120000 index 0000000000000000000000000000000000000000..1043427d2f3224fddaf289374b75073a6a1f3f0a --- /dev/null +++ b/frontend/doc/CleanRep.2.2.css @@ -0,0 +1 @@ +/opt/clean/doc/CleanLangRep/CleanRep.2.2.css \ No newline at end of file diff --git a/frontend/doc/CleanRep.2.2_files b/frontend/doc/CleanRep.2.2_files new file mode 120000 index 0000000000000000000000000000000000000000..6cc51f919f544e449c5dfa3e13f2939edeae9aec --- /dev/null +++ b/frontend/doc/CleanRep.2.2_files @@ -0,0 +1 @@ +/opt/clean/doc/CleanLangRep/CleanRep.2.2_files/ \ No newline at end of file diff --git a/frontend/doc/contents.php b/frontend/doc/contents.php new file mode 100644 index 0000000000000000000000000000000000000000..fcfec4ece07da0c7bc92eaaaa64d42aace9fb5c9 --- /dev/null +++ b/frontend/doc/contents.php @@ -0,0 +1,87 @@ +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 '
'; + foreach ($this->children as $child) { + if ($child->isLeaf()) { + echo '
' . $child->title . '' . + '
'; + } else { + echo '
' . + '' . + '' . + '' . $child->title . ''; + $child->printTree(); + echo '
'; + } + } + echo '
'; + } + + public function isLeaf() { + return count($this->children) == 0; + } +} + +$toc = Toc::factory(1, $toc); +$toc->printTree(); diff --git a/frontend/doc/index.php b/frontend/doc/index.php new file mode 100644 index 0000000000000000000000000000000000000000..9ad188ab6c9b1c9128a68c12c529aa5034efa8ca --- /dev/null +++ b/frontend/doc/index.php @@ -0,0 +1,29 @@ + + + + Documentation browser + + + + + + + + + + + +
+ +
+ + diff --git a/frontend/doc/square_8.png b/frontend/doc/square_8.png new file mode 120000 index 0000000000000000000000000000000000000000..dbe4d019efdb1c0541ef636cc6e64cb80ebc24a1 --- /dev/null +++ b/frontend/doc/square_8.png @@ -0,0 +1 @@ +/opt/clean/doc/CleanLangRep/square_8.png \ No newline at end of file diff --git a/frontend/doc/src.php b/frontend/doc/src.php new file mode 100644 index 0000000000000000000000000000000000000000..972846ba3821e346d066f3d58f6597eee3549c32 --- /dev/null +++ b/frontend/doc/src.php @@ -0,0 +1,28 @@ + 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); diff --git a/frontend/src/view.js b/frontend/src/view.js index 5528b46cbd69463be132ae7508e07760b2800c74..b339d1b0f8d22ed0cca8a188b324c65a449e878d 100644 --- a/frontend/src/view.js +++ b/frontend/src/view.js @@ -20,24 +20,33 @@ function loadModule(elem) { viewer.innerHTML = '

Loading...

'; - 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(); }