From 77ed2f879a8076e15966a15148d89cbd675b2b09 Mon Sep 17 00:00:00 2001 From: jdx <216188+jdx@users.noreply.github.com> Date: Sat, 14 Dec 2024 10:41:25 -0600 Subject: [PATCH] feat: feature for automatically adding code fences (#197) --- cli/src/cli/generate/markdown.rs | 7 +- cli/usage.usage.kdl | 1 + docs/cli/reference/bash.md | 7 - docs/cli/reference/commands.json | 8 + docs/cli/reference/generate/markdown.md | 2 + examples/docs/MISE_INLINE.md | 4 - examples/docs/MISE_MULTI.md | 4 - ...omplete__bash__tests__complete_bash-3.snap | 5 +- ...omplete__fish__tests__complete_fish-3.snap | 7 +- ..._complete__zsh__tests__complete_zsh-3.snap | 7 +- lib/src/docs/markdown/arg.rs | 18 +- lib/src/docs/markdown/cmd.rs | 30 +- lib/src/docs/markdown/flag.rs | 16 +- lib/src/docs/markdown/renderer.rs | 58 +++- lib/src/docs/markdown/spec.rs | 18 +- .../markdown/templates/arg_template.md.tera | 6 +- .../markdown/templates/cmd_template.md.tera | 20 +- .../markdown/templates/flag_template.md.tera | 5 +- lib/src/docs/mod.rs | 1 + lib/src/docs/models.rs | 313 ++++++++++++++++++ lib/src/lib.rs | 1 + lib/src/test.rs | 23 +- mise.toml | 6 +- 23 files changed, 484 insertions(+), 83 deletions(-) create mode 100644 lib/src/docs/models.rs diff --git a/cli/src/cli/generate/markdown.rs b/cli/src/cli/generate/markdown.rs index 605541d0..2ea07e0a 100644 --- a/cli/src/cli/generate/markdown.rs +++ b/cli/src/cli/generate/markdown.rs @@ -25,6 +25,9 @@ pub struct Markdown { #[clap(long)] html_encode: bool, + #[clap(long)] + replace_pre_with_code_fences: bool, + /// Output markdown files to this directory #[clap(long, value_hint = clap::ValueHint::DirPath)] out_dir: Option, @@ -41,7 +44,9 @@ impl Markdown { Ok(()) }; let (spec, _) = Spec::parse_file(&self.file)?; - let mut ctx = MarkdownRenderer::new(&spec).with_html_encode(self.html_encode); + let mut ctx = MarkdownRenderer::new(spec.clone()) + .with_html_encode(self.html_encode) + .with_replace_pre_with_code_fences(self.replace_pre_with_code_fences); if let Some(url_prefix) = &self.url_prefix { ctx = ctx.with_url_prefix(url_prefix); } diff --git a/cli/usage.usage.kdl b/cli/usage.usage.kdl index 77da4706..98dceec1 100644 --- a/cli/usage.usage.kdl +++ b/cli/usage.usage.kdl @@ -92,6 +92,7 @@ cmd "generate" subcommand_required=true { arg "" } flag "--html-encode" help="Escape HTML in markdown" + flag "--replace-pre-with-code-fences" flag "--out-dir" help="Output markdown files to this directory" { arg "" } diff --git a/docs/cli/reference/bash.md b/docs/cli/reference/bash.md index 183296fb..ce45dced 100644 --- a/docs/cli/reference/bash.md +++ b/docs/cli/reference/bash.md @@ -14,13 +14,6 @@ to properly escape and quote values with spaces in them. ### `