diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index 574e13b52a..3e96338ad4 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -12,9 +12,13 @@ import v.doc import v.pref const ( - css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js'] - default_theme = os.resource_abs_path('theme') - link_svg = '' + css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js'] + default_theme = os.resource_abs_path('theme') + link_svg = '' + + single_quote = "'" + double_quote = '"' + no_quotes_replacement = [single_quote, '', double_quote, ''] ) enum HighlightTokenTyp { @@ -385,8 +389,9 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool, highlighted_code := html_highlight(dn.content, tb) node_class := if dn.kind == .const_group { ' const' } else { '' } sym_name := get_sym_name(dn) - has_deprecated := 'deprecated' in dn.tags - mut tags := dn.tags.filter(it != 'deprecated') + mut deprecated_tags := dn.tags.filter(it.starts_with('deprecated')) + deprecated_tags.sort() + mut tags := dn.tags.filter(!it.starts_with('deprecated')) tags.sort() mut node_id := get_node_id(dn) mut hash_link := if !head { ' #' } else { '' } @@ -406,13 +411,12 @@ fn doc_node_html(dn doc.DocNode, link string, head bool, include_examples bool, } dnw.write_string('') } - if tags.len > 0 || has_deprecated { - mut attributes := if has_deprecated { - '
deprecated
' - } else { - '' - } - attributes += tags.map('
$it
').join('') + if deprecated_tags.len > 0 { + attributes := deprecated_tags.map('
${no_quotes(it)}
').join('') + dnw.writeln('
$attributes
') + } + if tags.len > 0 { + attributes := tags.map('
$it
').join('') dnw.writeln('
$attributes
') } if !head && dn.content.len > 0 { @@ -494,3 +498,7 @@ fn write_toc(dn doc.DocNode, mut toc strings.Builder) { } toc.writeln('') } + +fn no_quotes(s string) string { + return s.replace_each(no_quotes_replacement) +} diff --git a/vlib/v/doc/doc.v b/vlib/v/doc/doc.v index f992bbf21b..d9031e7a4b 100644 --- a/vlib/v/doc/doc.v +++ b/vlib/v/doc/doc.v @@ -260,7 +260,11 @@ pub fn (mut d Doc) stmt(stmt ast.Stmt, filename string) ?DocNode { } ast.FnDecl { if stmt.is_deprecated { - node.tags << 'deprecated' + for sa in stmt.attrs { + if sa.name.starts_with('deprecated') { + node.tags << sa.str() + } + } } if stmt.is_unsafe { node.tags << 'unsafe'