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

Specialize a tokenizer for snake_case and camelCase for the lunr index (resolves #9)

parent dc33a728
Pipeline #15075 passed with stage
in 1 minute and 8 seconds
# clean-doc
Generate documentation from Clean libraries
\ No newline at end of file
Generate documentation from Clean libraries
To get an idea of what this tool is capable of, for now see the documentation
on [cleandoc.camilstaps.nl](http://cleandoc.camilstaps.nl).
var lunr_items;
var lunr_index;
var restoreSessionSettings;
// A tokenizer for snake_case and CamelCase
function lunr_programming_tokenizer(obj, metadata) {
if (obj == null || obj == undefined)
return []
if (Array.isArray(obj)) {
return obj.map(function (t) {
return new lunr.Token(
lunr.utils.asString(t).toLowerCase(),
lunr.utils.clone(metadata)
)
})
}
var str = obj
.toString()
.replace(/([a-z])([A-Z])/g, '$1 $2') // camelCase
.replace(/_/g, ' '); // snake_case
return lunr.tokenizer(str);
}
function build_lunr(items) {
lunr_items = items;
lunr_index = lunr(function(){
this.field('name');
this.field('description');
this.tokenizer = lunr_programming_tokenizer;
for (var i in items) {
items[i].id = i;
this.add(items[i]);
......
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