From e5f12ad74ad4da8e0702ed081c0fd922c8d72820 Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Sat, 6 Jun 2020 20:31:26 +0800 Subject: [PATCH] vdoc: multiple fixes --- cmd/tools/vdoc.v | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/cmd/tools/vdoc.v b/cmd/tools/vdoc.v index a5e5075e54..ed0cf4a617 100644 --- a/cmd/tools/vdoc.v +++ b/cmd/tools/vdoc.v @@ -5,6 +5,7 @@ import net import net.urllib import os import os.cmdline +import time import strings import v.doc import v.scanner @@ -168,8 +169,10 @@ fn html_highlight(code string, tb &table.Table) string { .name { if tok.lit in builtin { tok_typ = .builtin - } else if next_tok.kind in [.lcbr, .lpar] { + } else if next_tok.kind == .lcbr { tok_typ = .symbol + } else if next_tok.kind == .lpar { + tok_typ = .function } else { tok_typ = .name } @@ -223,9 +226,14 @@ fn doc_node_html(dd doc.DocNode, link string, head bool, tb &table.Table) string head_tag := if head { 'h1' } else { 'h2' } md_content := markdown.to_html(dd.comment) hlighted_code := html_highlight(dd.content, tb) - dnw.writeln('
') + mut sym_name := dd.name + if dd.parent_type !in ['void', ''] { + sym_name = '${dd.parent_type}.' + sym_name + } + node_id := slug(sym_name) + dnw.writeln('
') if dd.name != 'README' { - dnw.write('
<$head_tag>${dd.name} #') + dnw.write('
<$head_tag>$sym_name #') if link.len != 0 { dnw.write('$link_svg') } @@ -254,7 +262,8 @@ fn (cfg DocConfig) gen_html(idx int) string { if children.len != 0 { toc.writeln('
    ') for child in children { - toc.writeln('
  • ${child.name}
  • ') + cname := cn.name + '.' + child.name + toc.writeln('
  • ${child.name}
  • ') } toc.writeln('
') } @@ -493,16 +502,22 @@ fn (mut cfg DocConfig) generate_docs_from_file() { name: 'README', comment: readme_contents } + time_generated: time.now() } } } dirs := if cfg.is_multi { get_modules_list(cfg.input_path) } else { [cfg.input_path] } for dirpath in dirs { cfg.vprintln('Generating docs for ${dirpath}...') - dcs := doc.generate(dirpath, cfg.pub_only, !is_vlib) or { + mut dcs := doc.generate(dirpath, cfg.pub_only, !is_vlib) or { panic(err) } if dcs.contents.len == 0 { continue } + if cfg.pub_only { + for i, c in dcs.contents { + dcs.contents[i].content = c.content.all_after('pub ') + } + } cfg.docs << dcs } if cfg.serve_http {