75lb / command-line-usage

A simple, data-driven module for creating a usage guide.
MIT License
210 stars 36 forks source link

Generate Markdown #21

Closed brettz9 closed 5 years ago

brettz9 commented 5 years ago

I think it'd be handy if you could provide an out-of-the-box solution for converting the usage options into Markdown, e.g., for inclusion in a README. I know it should not be too hard to parse it oneself, but it could be handy, e.g,. for italicizing, if this were all done for us... :)

75lb commented 5 years ago

I do agree this would be useful but it's not something I plan to implement as part of this package. I recommend building a separate tool which takes command-line-usage output as input - let me know if you build it, cheers.

brettz9 commented 5 years ago

Thanks to ansi-to-svg, just took a few lines to get an image out of your output (is that what you used?). Result for my simple formatting: https://github.com/brettz9/git-utilities#command-line-usage

Anyways, not sure how well-supported the necessary CSS would be within Markdown.

import fs from 'fs';
import ansiToSVG from 'ansi-to-svg';
import commandLineUsage from 'command-line-usage';
import {cliSections} from '../src/optionDefinitions.mjs'; // My command-line-usage data

const {promises: {writeFile}} = fs;
const ansiText = commandLineUsage(cliSections);

(async () => {
await writeFile(
  new URL('../cli.svg', import.meta.url).pathname,
  ansiToSVG(ansiText)
);
})();
75lb commented 5 years ago

I just use simple html tags, example here.

brettz9 commented 5 years ago

Oh, sorry, I was referring to your image files like: https://raw.githubusercontent.com/75lb/command-line-usage/master/example/screens/synopsis.png . These can be automatically built--(in my example with SVG, but there is also one for PNG/JPEG: https://github.com/F1LT3R/ansi-to-image ). Not as nice as cut-and-pasteable text, but it at least is automatable and preserves the styling.

75lb commented 5 years ago

ah, ok - they are just screenshots.. thanks for sharing the ansi-to-svg example 👍

brettz9 commented 5 years ago

FWIW, I've now published a tool for exporting command-line-usage arrays to HTML or SVG here: https://github.com/brettz9/command-line-publish (CLI or programmatic)

jrson83 commented 2 years ago

FWIW, I've now published a tool for exporting command-line-usage arrays to HTML or SVG here: https://github.com/brettz9/command-line-publish (CLI or programmatic)

This is great, thank you!