vdoc: add a node type prefix (#7563)

pull/7466/head
Daniel Däschle 2020-12-26 07:55:35 +01:00 committed by GitHub
parent d66ed46486
commit 6842c3c1a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 10 deletions

View File

@ -385,7 +385,11 @@ fn doc_node_html(dd doc.DocNode, link string, head bool, tb &table.Table) string
hash_link := if !head { ' <a href="#$node_id">#</a>' } else { '' } hash_link := if !head { ' <a href="#$node_id">#</a>' } else { '' }
dnw.writeln('<section id="$node_id" class="doc-node$node_class">') dnw.writeln('<section id="$node_id" class="doc-node$node_class">')
if dd.name.len > 0 { if dd.name.len > 0 {
if dd.kind == .const_group {
dnw.write('<div class="title"><$head_tag>$sym_name$hash_link</$head_tag>') dnw.write('<div class="title"><$head_tag>$sym_name$hash_link</$head_tag>')
} else {
dnw.write('<div class="title"><$head_tag>$dd.kind $sym_name$hash_link</$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>')
} }
@ -412,19 +416,21 @@ fn (cfg DocConfig) readme_idx() int {
return -1 return -1
} }
fn write_toc(cn doc.DocNode, nodes []doc.DocNode, mut toc strings.Builder) { fn write_toc(dn doc.DocNode, nodes []doc.DocNode, mut toc strings.Builder) {
mut toc_slug := if cn.name.len == 0 || cn.content.len == 0 { '' } else { slug(cn.name) } mut toc_slug := if dn.name.len == 0 || dn.content.len == 0 { '' } else { slug(dn.name) }
if toc_slug == '' && cn.children.len > 0 { if toc_slug == '' && dn.children.len > 0 {
toc_slug = slug(cn.name + '.' + cn.children[0].name) toc_slug = slug(dn.name + '.' + dn.children[0].name)
} }
toc.write('<li class="open"><a href="#$toc_slug">$cn.name</a>') if dn.name != 'Constants' {
if cn.name != 'Constants' { toc.write('<li class="open"><a href="#$toc_slug">$dn.kind $dn.name</a>')
toc.writeln(' <ul>') toc.writeln(' <ul>')
for child in cn.children { for child in dn.children {
cname := cn.name + '.' + child.name cname := dn.name + '.' + child.name
toc.writeln('<li><a href="#${slug(cname)}">$child.name</a></li>') toc.writeln('<li><a href="#${slug(cname)}">$child.kind $child.name</a></li>')
} }
toc.writeln('</ul>') toc.writeln('</ul>')
} else {
toc.write('<li class="open"><a href="#$toc_slug">$dn.name</a>')
} }
toc.writeln('</li>') toc.writeln('</li>')
} }

View File

@ -28,6 +28,18 @@ pub enum SymbolKind {
struct_field struct_field
} }
pub fn (sk SymbolKind) str() string {
return match sk {
.const_group { 'Constants' }
.function, .method { 'fn' }
.interface_ { 'interface' }
.typedef { 'type' }
.enum_ { 'enum' }
.struct_ { 'struct' }
else { '' }
}
}
pub struct Doc { pub struct Doc {
prefs &pref.Preferences = new_vdoc_preferences() prefs &pref.Preferences = new_vdoc_preferences()
pub mut: pub mut: