Verified Commit 219003ed authored by Camil Staps's avatar Camil Staps 🚀

Use clean-doc-markup for documentation markup formatting (#1)

parent 8c9f27de
Pipeline #14649 failed with stage
in 56 seconds
......@@ -4,3 +4,6 @@
[submodule "data/cleandoc-default/modules/lunr.js"]
path = data/cleandoc-default/modules/lunr.js
url = https://github.com/olivernn/lunr.js
[submodule "data/cleandoc-default/modules/clean-doc-markup"]
path = data/cleandoc-default/modules/clean-doc-markup
url = https://gitlab.science.ru.nl/cstaps/clean-doc-markup
......@@ -22,13 +22,14 @@ function make_relative_url(url) {
return new_url;
}
(function(){
/* Highlight Clean code */
let codes = document.getElementsByClassName('clean-code');
for (let i = 0; i < codes.length; i++) {
codes[i].innerHTML = highlightClean(codes[i].innerText);
}
function search(query) {
let searchfield = document.getElementById('search-field');
searchfield.value = query;
searchfield.oninput();
searchfield.focus();
}
(function(){
/* Resizable sidebar */
let sidebar = document.getElementById('sidebar');
sidebar.onmouseup = function () { /* not every browser supports onresize on div */
......@@ -60,22 +61,42 @@ function make_relative_url(url) {
};
window.onhashchange();
/* Highlight Clean code */
let codes = document.getElementsByClassName('clean-code');
for (let i = 0; i < codes.length; i++) {
codes[i].innerHTML = highlightClean(codes[i].innerText);
}
/* Markup Clean documentation */
let docs = document.getElementsByClassName('clean-doc');
for (let i = 0; i < docs.length; i++) {
docs[i].innerHTML = docs[i].innerText.markup(undefined, function(link) {
return '<a href="javascript:search(\'' + link + '\');">' + link + '</a>';
});
}
/* search field */
let searchfield = document.getElementById('search-field');
let searchresults = document.getElementById('search-results').querySelector('ul');
let searchcloogle = document.getElementById('search-cloogle');
searchfield.oninput = function () {
searchresults.innerHTML = '';
searchcloogle.innerHTML = '';
if (this.value == '')
return;
var results = lunr_index.search(this.value);
var cloogle = '<a href="https://cloogle.org/#' + this.value + '" target="_blank">search on Cloogle</a>';
if (results.length == 0) {
searchresults.innerHTML = '<em>no results</em>';
searchresults.innerHTML = '<em>no results</em> &mdash; ' + cloogle;
return;
}
searchcloogle.innerHTML = cloogle.replace('search on Cloogle', 'Find more on Cloogle');
for (let i in results) {
let elem = lunr_items[results[i].ref];
let li = document.createElement('li');
......
Subproject commit 16fbc444668f94b7af12cb9c2380064bb6d5f586
......@@ -44,6 +44,7 @@ where
, LinkTag [RelAttr "stylesheet", TypeAttr "text/css", HrefAttr (relativePath "css/style.css")]
, ScriptTag [] [Text ("var this_relative_url = '" +++ fp +++ "'")]
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/clean-highlighter/clean.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/clean-doc-markup/clean-doc-markup.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "js/cleandoc.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "modules/lunr.js/lunr.js")] []
, ScriptTag [DeferAttr "defer", SrcAttr (relativePath "js/lunr-index.js")] []
......@@ -56,6 +57,7 @@ where
, DivTag [IdAttr "search"]
[ InputTag [IdAttr "search-field", TypeAttr "text", PlaceholderAttr "search"]
, DivTag [IdAttr "search-results"] [UlTag [] []]
, PTag [IdAttr "search-cloogle"] []
]
]
]
......@@ -78,7 +80,7 @@ where
where
html = DivTag [] $ catMaybes
[ Just $ H1Tag [IdAttr ("mod-" +++ m.name)] [Text m.name]
, DivTag [IdAttr "mod_description"] <$> pure <$> Text <$> (docDescription =<< m.doc)
, DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< m.doc)
, Just $ DivTag [IdAttr "type_defs"] typedefs
, Just $ DivTag [IdAttr "classes"] classes
, Just $ DivTag [IdAttr "macros"] macros
......@@ -91,7 +93,7 @@ where
]
where
html dtd = collapsable "typedef" ("td-" +++ dtd.name) dtd.name $ catMaybes
[ DivTag [] <$> pure <$> Text <$> (docDescription =<< dtd.doc)
[ DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< dtd.doc)
, Just $ PreTag [ClassAttr "clean-code"] [Html (fromJust dtd.repr)]
]
......@@ -101,7 +103,7 @@ where
]
where
html dc = collapsable "class" ("class-" +++ dc.name) dc.name $ catMaybes
[ DivTag [] <$> pure <$> Text <$> (docDescription =<< dc.doc)
[ DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< dc.doc)
, Just $ PreTag [ClassAttr "clean-code"] [Html (fromJust dc.repr)]
]
......@@ -113,7 +115,7 @@ where
]
where
html df = collapsable "function" ("fun-" +++ df.name) df.name $ catMaybes
[ DivTag [] <$> pure <$> Text <$> (docDescription =<< df.doc)
[ DivTag [ClassAttr "clean-doc"] <$> pure <$> Text <$> (docDescription =<< df.doc)
, Just $ PreTag [ClassAttr "clean-code"] [Html (fromJust df.repr)]
]
......
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