vdoc: support v doc -check-examples -f none vlib/builtin

This commit is contained in:
Delyan Angelov 2025-08-13 16:43:11 +03:00
parent 5058fd7b79
commit 15f0f8a481
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
4 changed files with 12 additions and 6 deletions

View file

@ -10,7 +10,7 @@ const vexe = os.getenv_opt('VEXE') or { @VEXE }
const vroot = os.dir(vexe)
const allowed_formats = ['md', 'markdown', 'json', 'text', 'ansi', 'html', 'htm']
const allowed_formats = ['md', 'markdown', 'json', 'text', 'ansi', 'html', 'htm', 'none']
enum RunExampleMode {
skip

View file

@ -73,6 +73,7 @@ fn set_output_type_from_str(format string) OutputType {
'md', 'markdown' { .markdown }
'json' { .json }
'text' { .plaintext }
'none' { .none }
else { .ansi }
}
}

View file

@ -19,6 +19,7 @@ struct Readme {
enum OutputType {
unset
none
html
markdown
json
@ -151,6 +152,7 @@ fn (mut vd VDoc) write_plaintext_content(contents []doc.DocNode, mut pw strings.
fn (mut vd VDoc) render_doc(d doc.Doc, out Output) (string, string) {
name := vd.get_file_name(d.head.name, out)
output := match out.typ {
.none { '' }
.html { vd.gen_html(d) }
.markdown { vd.gen_markdown(d, true) }
.json { vd.gen_json(d) }
@ -190,9 +192,11 @@ fn (mut vd VDoc) work_processor(mut work sync.Channel, mut wg sync.WaitGroup) {
}
vd.vprintln('> start processing ${pdoc.d.base_path} ...')
file_name, content := vd.render_doc(pdoc.d, pdoc.out)
output_path := os.join_path(pdoc.out.path, file_name)
println('Generating ${content.len:8} bytes of ${pdoc.out.typ} in `${output_path}` ...')
os.write_file(output_path, content) or { panic(err) }
if vd.cfg.output_type != .none {
output_path := os.join_path(pdoc.out.path, file_name)
println('Generating ${content.len:8} bytes of ${pdoc.out.typ} in `${output_path}` ...')
os.write_file(output_path, content) or { panic(err) }
}
}
wg.done()
}
@ -301,7 +305,7 @@ fn (mut vd VDoc) generate_docs_from_file() {
ext := os.file_ext(out.path)
out.typ = set_output_type_from_str(ext.all_after('.'))
}
if cfg.include_readme && out.typ !in [.html, .ansi, .plaintext] {
if cfg.include_readme && out.typ !in [.html, .ansi, .plaintext, .none] {
eprintln('vdoc: Including README.md for doc generation is supported on HTML output, or when running directly in the terminal.')
exit(1)
}

View file

@ -20,7 +20,8 @@ Options:
-no-color Forces plain text output, without ANSI colors.
Note: -color is on for -f ansi .
-f Specifies the output format to be used.
Available formats are: md/markdown, json, text, ansi and html/htm.
Available formats are: none, md/markdown, json, text, ansi and html/htm.
Note: the format `none` is mostly useful in combination with -check-examples .
-h, -help Prints this help text.
-m Generate docs for modules listed in that folder.
-o The output file/folder path where to store the docs. Use `-o stdout`