From 6afa5fe348813434a5781678f586297423157b93 Mon Sep 17 00:00:00 2001 From: Roman Reiss Date: Wed, 19 Apr 2017 19:22:52 +0200 Subject: [PATCH] tools: add table parsing capability to the doctool PR-URL: https://github.com/nodejs/node/pull/9532 Backport-PR-URL: https://github.com/nodejs/node/pull/13073 Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Rich Trott --- tools/doc/html.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tools/doc/html.js b/tools/doc/html.js index f7c7b46c54..7f22769e63 100644 --- a/tools/doc/html.js +++ b/tools/doc/html.js @@ -162,13 +162,35 @@ function analyticsScript(analytics) { `; } +// replace placeholders in text tokens +function replaceInText(text) { + return linkJsTypeDocs(linkManPages(text)); +} + // handle general body-text replacements // for example, link man page references to the actual page function parseText(lexed) { lexed.forEach(function(tok) { - if (tok.text && tok.type !== 'code') { - tok.text = linkManPages(tok.text); - tok.text = linkJsTypeDocs(tok.text); + if (tok.type === 'table') { + if (tok.cells) { + tok.cells.forEach((row, x) => { + row.forEach((_, y) => { + if (tok.cells[x] && tok.cells[x][y]) { + tok.cells[x][y] = replaceInText(tok.cells[x][y]); + } + }); + }); + } + + if (tok.header) { + tok.header.forEach((_, i) => { + if (tok.header[i]) { + tok.header[i] = replaceInText(tok.header[i]); + } + }); + } + } else if (tok.text && tok.type !== 'code') { + tok.text = replaceInText(tok.text); } }); }