TOC html
Jump to navigation
Jump to search
| Line 56: | Line 56: | ||
| − | + | var wiki_list = [] | |
| − | + | function walk_through_TOC(children,parent,depth) { | |
| − | + | depth++ | |
| − | + | if(!children || !Object.keys(children).length) { | |
| − | + | return | |
| − | + | } | |
| − | + | for(var value of children) { | |
| − | + | if(value.path) { | |
| − | + | var repeat = depth | |
| − | + | // '&&' does not work ! | |
| − | + | if(parent) { | |
| − | + | if(!parent.path) { | |
| − | + | var regExp = new RegExp('\\b' + parent.text + '$') | |
| − | + | if(regExp.test(value.path)) { | |
| − | + | repeat--; | |
| − | |||
} | } | ||
} | } | ||
| − | |||
} | } | ||
| + | wiki_list.push('#'.repeat(repeat) + '[[' + value.path + '|' + value.text + ']]') | ||
| + | } | ||
| − | + | if(value.children) { | |
| − | + | walk_through_TOC(value.children,value,depth); | |
| − | + | } | |
| − | |||
} | } | ||
| + | } | ||
| + | var contents = $ci('#TOC_contents').val(); | ||
| − | + | contents = decodeURIComponent(window.atob(contents)); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
if(contents) { | if(contents) { | ||
| − | + | contents = JSON.parse(contents) | |
| − | contents = JSON.parse(contents) | + | |
| − | |||
Frontend_Index.translate_index_rec(contents,'from'); | Frontend_Index.translate_index_rec(contents,'from'); | ||
| Line 131: | Line 123: | ||
index_obj_saved = tree.toDict(true).children; | index_obj_saved = tree.toDict(true).children; | ||
| − | |||
| − | |||
Frontend_Index.translate_index_rec(index_obj_saved,'to'); | Frontend_Index.translate_index_rec(index_obj_saved,'to'); | ||
| + | walk_through_TOC(index_obj_saved,null,0); | ||
| − | + | index_obj_saved = btoa(encodeURIComponent(JSON.stringify(index_obj_saved))); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | index_obj_saved = btoa | ||
| − | |||
| − | |||
| − | |||
| − | |||
$ci('#TOC_contents').val(index_obj_saved) | $ci('#TOC_contents').val(index_obj_saved) | ||
| − | $ci('#pf_free_text').val(wiki_list.join("\n")) | + | $ci('#pf_free_text').val(` |
| + | <!-- | ||
| + | The content of this page is created automatically. | ||
| + | Don't edit it without the form, since any additional content | ||
| + | will be lost! | ||
| + | --> | ||
| + | ` + wiki_list.join("\n")) | ||
| − | |||
| − | |||
| − | |||
return true; | return true; | ||
| + | |||
}); | }); | ||
Revision as of 17:52, 16 July 2020