diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 5d6ec00f2f..5d96bb03c1 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -182,14 +182,14 @@ fn (vd &VDoc) write_content(cn &doc.DocNode, d &doc.Doc, mut hw strings.Builder) src_link := get_src_link(vd.manifest.repo_url, vd.manifest.repo_branch, file_path_name, cn.pos.line_nr + 1) if cn.content.len != 0 || cn.name == 'Constants' { - hw.write_string(doc_node_html(cn, src_link, false, cfg.include_examples, d.table)) + hw.write_string(vd.doc_node_html(cn, src_link, false, cfg.include_examples, d.table)) hw.write_string('\n') } for child in cn.children { child_file_path_name := child.file_path.replace('${base_dir}/', '') child_src_link := get_src_link(vd.manifest.repo_url, vd.manifest.repo_branch, child_file_path_name, child.pos.line_nr + 1) - hw.write_string(doc_node_html(child, child_src_link, false, cfg.include_examples, + hw.write_string(vd.doc_node_html(child, child_src_link, false, cfg.include_examples, d.table)) hw.write_string('\n') } @@ -202,7 +202,7 @@ fn (vd &VDoc) gen_html(d doc.Doc) string { mut contents := strings.new_builder(200) dcs_contents := d.contents.arr() // generate toc first - contents.writeln(doc_node_html(d.head, '', true, cfg.include_examples, d.table)) + contents.writeln(vd.doc_node_html(d.head, '', true, cfg.include_examples, d.table)) if is_module_readme(d.head) { write_toc(d.head, mut symbols_toc) } @@ -519,7 +519,7 @@ fn html_highlight(code string, tb &ast.Table) string { return buf.str() } -fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool, tb &ast.Table) string { +fn (vd &VDoc) doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool, tb &ast.Table) string { mut dnw := strings.new_builder(200) head_tag := if head { 'h1' } else { 'h2' } mut renderer := markdown.HtmlRenderer{ diff --git a/cmd/tools/vdoc/run_examples.v b/cmd/tools/vdoc/run_examples.v index 2d58e9e9be..838ea3aea2 100644 --- a/cmd/tools/vdoc/run_examples.v +++ b/cmd/tools/vdoc/run_examples.v @@ -2,11 +2,19 @@ module main import document as doc import v.vmod -import strings import os import rand import term +fn (mut vd VDoc) process_all_examples(contents []doc.DocNode) { + for cn in contents { + if cn.content.len > 0 { + vd.run_examples(cn) + } + vd.process_all_examples(cn.children) + } +} + const normalised_default_vmodules_path = os.vmodules_dir().replace('\\', '/') fn get_mod_name_by_file_path(file_path string) string { @@ -23,7 +31,7 @@ fn get_mod_name_by_file_path(file_path string) string { return mod_name } -fn (mut vd VDoc) run_examples(dn doc.DocNode, mut pw strings.Builder) { +fn (mut vd VDoc) run_examples(dn doc.DocNode) { if dn.comments.len == 0 || !vd.cfg.run_examples { return } diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index ead5947541..1c41c5095f 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -143,7 +143,6 @@ fn (mut vd VDoc) write_plaintext_content(contents []doc.DocNode, mut pw strings. } } } - vd.run_examples(cn, mut pw) } vd.write_plaintext_content(cn.children, mut pw) } @@ -157,6 +156,8 @@ fn (mut vd VDoc) render_doc(d doc.Doc, out Output) (string, string) { .json { vd.gen_json(d) } else { vd.gen_plaintext(d) } } + contents := d.contents.arr() + vd.process_all_examples(contents) return name, output }