Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MarkdownMagic script updates #3815

Merged
merged 3 commits into from
Mar 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 14 additions & 17 deletions scripts/markdown-magic.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
*/

const {execSync} = require('child_process');
const stripAnsi = require('strip-ansi');
const markdownToc = require('markdown-toc');
const path = require('path');
const fs = require('fs');
const path = require('path');
const markdownToc = require('markdown-toc');
const stripAnsi = require('strip-ansi');

exports.transforms = {
/**
Expand All @@ -20,11 +20,11 @@ exports.transforms = {
usage: (content, options) => {
const {executable} = options;
const flag = options.flag || '--help';
const header = options.header || '\n```plain';
const header = options.header || '\n```text';
plroebuck marked this conversation as resolved.
Show resolved Hide resolved
const footer = options.footer || '```\n';
const output = stripAnsi(
String(
execSync(`${process.execPath} ${executable} ${flag}`, {
execSync(`"${process.execPath}" ${executable} ${flag}`, {
cwd: path.join(__dirname, '..')
})
).trim()
Expand All @@ -40,18 +40,15 @@ exports.transforms = {
*/
toc: (content, options, config) => {
const IGNORED_HEADINGS_REGEXP = /Features|Table of Contents/i;
return (
'\n' +
markdownToc(config.outputContent, {
slugify: require('uslug'),
bullets: options.bullets,
firsth1: false,
// if filter is supplied, maxdepth is apparently ignored,
// so we have to do it ourselves.
filter: (str, ele) => ele.lvl < 2 && !IGNORED_HEADINGS_REGEXP.test(str)
}).content +
'\n'
);
const toc = markdownToc(config.outputContent, {
slugify: require('uslug'),
bullets: options.bullets,
firsth1: false,
// if filter is supplied, maxdepth is apparently ignored,
// so we have to do it ourselves.
filter: (str, ele) => ele.lvl < 2 && !IGNORED_HEADINGS_REGEXP.test(str)
}).content;
return '\n' + toc + '\n';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth adding a comment as to the relevance of the \n's. they ensure markdownlint doesn't barf on the rendered output.

when we ensure that the auto-generated content is no longer under VCS (and is only part of the docs build), then we don't need the extra newlines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had just considered it good style -- didn't realize an automated tool agreed with me. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

},
manifest: require('markdown-magic-package-json'),
/**
Expand Down