vdoc: multiple fixes

pull/5241/head
Ned Palacios 2020-06-06 20:31:26 +08:00 committed by GitHub
parent 40bd1be85f
commit e5f12ad74a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import net
import net.urllib import net.urllib
import os import os
import os.cmdline import os.cmdline
import time
import strings import strings
import v.doc import v.doc
import v.scanner import v.scanner
@ -168,8 +169,10 @@ fn html_highlight(code string, tb &table.Table) string {
.name { .name {
if tok.lit in builtin { if tok.lit in builtin {
tok_typ = .builtin tok_typ = .builtin
} else if next_tok.kind in [.lcbr, .lpar] { } else if next_tok.kind == .lcbr {
tok_typ = .symbol tok_typ = .symbol
} else if next_tok.kind == .lpar {
tok_typ = .function
} else { } else {
tok_typ = .name 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' } head_tag := if head { 'h1' } else { 'h2' }
md_content := markdown.to_html(dd.comment) md_content := markdown.to_html(dd.comment)
hlighted_code := html_highlight(dd.content, tb) hlighted_code := html_highlight(dd.content, tb)
dnw.writeln('<section id="${slug(dd.name)}" class="doc-node">') 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('<section id="$node_id" class="doc-node">')
if dd.name != 'README' { if dd.name != 'README' {
dnw.write('<div class="title"><$head_tag>${dd.name} <a href="#${slug(dd.name)}">#</a></$head_tag>') dnw.write('<div class="title"><$head_tag>$sym_name <a href="#$node_id">#</a></$head_tag>')
if link.len != 0 { if link.len != 0 {
dnw.write('<a class="link" rel="noreferrer" target="_blank" href="$link">$link_svg</a>') dnw.write('<a class="link" rel="noreferrer" target="_blank" href="$link">$link_svg</a>')
} }
@ -254,7 +262,8 @@ fn (cfg DocConfig) gen_html(idx int) string {
if children.len != 0 { if children.len != 0 {
toc.writeln(' <ul>') toc.writeln(' <ul>')
for child in children { for child in children {
toc.writeln('<li><a href="#${slug(child.name)}">${child.name}</a></li>') cname := cn.name + '.' + child.name
toc.writeln('<li><a href="#${slug(cname)}">${child.name}</a></li>')
} }
toc.writeln('</ul>') toc.writeln('</ul>')
} }
@ -493,16 +502,22 @@ fn (mut cfg DocConfig) generate_docs_from_file() {
name: 'README', name: 'README',
comment: readme_contents comment: readme_contents
} }
time_generated: time.now()
} }
} }
} }
dirs := if cfg.is_multi { get_modules_list(cfg.input_path) } else { [cfg.input_path] } dirs := if cfg.is_multi { get_modules_list(cfg.input_path) } else { [cfg.input_path] }
for dirpath in dirs { for dirpath in dirs {
cfg.vprintln('Generating docs for ${dirpath}...') 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) panic(err)
} }
if dcs.contents.len == 0 { continue } 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 cfg.docs << dcs
} }
if cfg.serve_http { if cfg.serve_http {