Skip to content

Commit

Permalink
add toclinker, fix h1find regex and indexer typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Freedman committed Jan 28, 2011
1 parent 551c84c commit b056483
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions lib/jodoc-lib.js
Expand Up @@ -73,7 +73,7 @@ function index_to_json (h1s) {
function h1finder (processed) {
var h1s = {};
var files_to_h1s = {};
var h1find = /\<h1\>([^\<]+)\</h1\>/g;
var h1find = /\<h1\>([^\<]+)\<\/h1\>/g;
processed.forEach(
function(file_info) {
var accum_h1s = [];
Expand Down Expand Up @@ -110,7 +110,7 @@ function indexer (h1s, outputdir) {
keywords.forEach(
function(keyword) {
// works for RTL languages only I guess
var letter = keyword.toLocaleUpperCase.substr(0);
var letter = keyword.toLocaleUpperCase().substr(0);
if (typeof keyword_letters[letter] === "undefined") {
keyword_letters[letter] = [formatter(keyword)];
} else {
Expand All @@ -127,8 +127,25 @@ function indexer (h1s, outputdir) {
return '<h1>Index</h1>\n<span id="index">' + keywords_marked.join("\n") + '</span>';
}

// Expand {} placeholders in table of contents
// input: {h1s, files_to_h1s}, indent before '{}', interior of toc '{}' line
// output: markdown list of matching h1s
function toclinker(h1bag, indent, pathpart) {
var files_to_h1s = h1bag.files_to_h1s;
var matching_files = Object.keys(files_to_h1s), matching_h1s = [];
matching_files = matching_files.filter(function (file){ return file.match(pathpart) });
matching_files.forEach(function (matching_file){
matching_h1s = matching_h1s.concat(files_to_h1s[matching_file]);
});
matching_h1s = matching_h1s.sort().map(function(matching_h1) {
return indent + '* ' + matching_h1;
});
return matching_h1s.join("\n");
}

exports.docker = docker;
exports.html_header = html_header;
exports.munge_filename = munge_filename;
exports.h1finder = h1finder;
exports.indexer = indexer;
exports.toclinker = toclinker;

0 comments on commit b056483

Please sign in to comment.