1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

API: Added documentation generator and built documentation

This commit is contained in:
Laurent Cozic
2018-09-28 21:03:28 +01:00
parent 9841488ce4
commit e98575643c
21 changed files with 1227 additions and 46 deletions

View File

@ -1,5 +1,6 @@
const urlUtils = require('lib/urlUtils');
const MarkdownIt = require('markdown-it');
const stringPadding = require('string-padding');
const markdownUtils = {
@ -55,6 +56,36 @@ const markdownUtils = {
return match ? Number(match[1]) : 0;
},
createMarkdownTable(headers, rows) {
let output = [];
const headersMd = [];
const lineMd = [];
for (let i = 0; i < headers.length; i++) {
const mdRow = [];
const h = headers[i];
headersMd.push(stringPadding(h.label, 3, ' ', stringPadding.RIGHT));
lineMd.push('---');
}
output.push(headersMd.join(' | '));
output.push(lineMd.join(' | '));
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
const rowMd = [];
for (let j = 0; j < headers.length; j++) {
const h = headers[j];
const value = h.filter ? h.filter(row[h.name]) : row[h.name];
rowMd.push(stringPadding(value, 3, ' ', stringPadding.RIGHT));
}
output.push(rowMd.join(' | '));
}
return output.join('\n');
},
};
module.exports = markdownUtils;