mirror of
https://github.com/vlang/v.git
synced 2025-08-03 09:47:15 -04:00
tools: fix return""
in vdoc html output (fix #24979)
This commit is contained in:
parent
10f737e1df
commit
5a4dbf19d0
@ -384,6 +384,7 @@ fn write_token(tok token.Token, typ HighlightTokenTyp, mut buf strings.Builder)
|
||||
fn html_highlight(code string, tb &ast.Table) string {
|
||||
mut s := scanner.new_scanner(code, .parse_comments, &pref.Preferences{ output_mode: .silent })
|
||||
mut tok := s.scan()
|
||||
mut prev_tok := tok
|
||||
mut next_tok := s.scan()
|
||||
mut buf := strings.new_builder(200)
|
||||
mut i := 0
|
||||
@ -490,6 +491,9 @@ fn html_highlight(code string, tb &ast.Table) string {
|
||||
// html documentation outputs / its style rules will affect the readme.
|
||||
buf.write_string("'${html.escape(tok.lit.str())}'")
|
||||
} else {
|
||||
if final_tok_typ == .string && prev_tok.lit == 'return' {
|
||||
buf.write_string(' ')
|
||||
}
|
||||
write_token(tok, tok_typ, mut buf)
|
||||
}
|
||||
buf.write_string('</span>')
|
||||
@ -506,7 +510,7 @@ fn html_highlight(code string, tb &ast.Table) string {
|
||||
if i - 1 == next_tok.pos {
|
||||
i--
|
||||
}
|
||||
|
||||
prev_tok = tok
|
||||
tok = next_tok
|
||||
next_tok = s.scan()
|
||||
}
|
||||
|
26
cmd/tools/vdoc/testdata/output_formats/README.md
vendored
26
cmd/tools/vdoc/testdata/output_formats/README.md
vendored
@ -11,6 +11,32 @@ This is a script `<script>console.log('hi from README.md');</script>` .
|
||||
|
||||
## Examples
|
||||
|
||||
### Functions that return different literals:
|
||||
|
||||
Example of a function returning boolean:
|
||||
```v
|
||||
fn is_odd(x int) bool {
|
||||
if x % 2 == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
```
|
||||
|
||||
Another example of a function returning a string:
|
||||
```v
|
||||
fn answer() string {
|
||||
return '42'
|
||||
}
|
||||
```
|
||||
|
||||
This example shows a function returning a string with interpolation:
|
||||
```v
|
||||
fn str_with_interplation() string {
|
||||
return 'this string has ${42:6} interpolation in it.'
|
||||
}
|
||||
```
|
||||
|
||||
### Processing command line args
|
||||
|
||||
```v
|
||||
|
45
cmd/tools/vdoc/testdata/output_formats/main.ansi
vendored
45
cmd/tools/vdoc/testdata/output_formats/main.ansi
vendored
@ -5,6 +5,25 @@ This is a link to the main V site.
|
||||
This is a bold text.
|
||||
This is a script <script>console.log('hi from README.md');</script> .
|
||||
Examples
|
||||
Functions that return different literals:
|
||||
Example of a function returning boolean:
|
||||
fn is_odd(x int) bool {
|
||||
if x % 2 == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Another example of a function returning a string:
|
||||
fn answer() string {
|
||||
return '42'
|
||||
}
|
||||
|
||||
This example shows a function returning a string with interpolation:
|
||||
fn str_with_interplation() string {
|
||||
return 'this string has ${42:6} interpolation in it.'
|
||||
}
|
||||
|
||||
Processing command line args
|
||||
import os
|
||||
|
||||
@ -150,6 +169,32 @@ The End.
|
||||
|
||||
## Examples
|
||||
|
||||
### Functions that return different literals:
|
||||
|
||||
Example of a function returning boolean:
|
||||
```v
|
||||
fn is_odd(x int) bool {
|
||||
if x % 2 == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
```
|
||||
|
||||
Another example of a function returning a string:
|
||||
```v
|
||||
fn answer() string {
|
||||
return '42'
|
||||
}
|
||||
```
|
||||
|
||||
This example shows a function returning a string with interpolation:
|
||||
```v
|
||||
fn str_with_interplation() string {
|
||||
return 'this string has ${42:6} interpolation in it.'
|
||||
}
|
||||
```
|
||||
|
||||
### Processing command line args
|
||||
|
||||
```v
|
||||
|
11
cmd/tools/vdoc/testdata/output_formats/main.html
vendored
11
cmd/tools/vdoc/testdata/output_formats/main.html
vendored
@ -1,6 +1,15 @@
|
||||
<section id="readme_main" class="doc-node">
|
||||
<div class="title"><h1> main <a href="#readme_main">#</a></h1></div>
|
||||
<h2>Description</h2><p>This is an example of a an .md file, used for adding more rich text documentation in a project or module.</p><p>This is a <a href="https://vlang.io/">link</a> to the main V site.</p><p>This is a <b>bold text</b>.</p><p>This is a script <code><script>console.log('hi from README.md');</script></code> .</p><h2>Examples</h2><h3>Processing command line args</h3><pre><code class="language-v"><span class="token keyword">import</span> os
|
||||
<h2>Description</h2><p>This is an example of a an .md file, used for adding more rich text documentation in a project or module.</p><p>This is a <a href="https://vlang.io/">link</a> to the main V site.</p><p>This is a <b>bold text</b>.</p><p>This is a script <code><script>console.log('hi from README.md');</script></code> .</p><h2>Examples</h2><h3>Functions that return different literals:</h3><p>Example of a function returning boolean:</p><pre><code class="language-v"><span class="token keyword">fn</span> <span class="token function">is_odd</span><span class="token punctuation">(</span>x <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">if</span> x <span class="token operator">%</span> <span class="token number">2</span> <span class="token operator">==</span> <span class="token number">0</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">return</span> <span class="token boolean">false</span>
|
||||
<span class="token punctuation">}</span>
|
||||
<span class="token keyword">return</span> <span class="token boolean">true</span>
|
||||
<span class="token punctuation">}</span></code></pre><p>Another example of a function returning a string:</p><pre><code class="language-v"><span class="token keyword">fn</span> <span class="token function">answer</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">return</span> <span class="token string">'42'</span>
|
||||
<span class="token punctuation">}</span></code></pre><p>This example shows a function returning a string with interpolation:</p><pre><code class="language-v"><span class="token keyword">fn</span> <span class="token function">str_with_interplation</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">return</span><span class="token string"> 'this string has </span><span class="token string_interp">$</span>{<span class="token number">42</span><span class="token punctuation">:</span><span class="token number">6</span>}<span class="token string"> interpolation in it.'</span>
|
||||
<span class="token punctuation">}</span></code></pre><h3>Processing command line args</h3><pre><code class="language-v"><span class="token keyword">import</span> os
|
||||
|
||||
<span class="token keyword">fn</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
|
||||
<span class="token keyword">dump</span><span class="token punctuation">(</span>os<span class="token punctuation">.</span>args<span class="token punctuation">)</span>
|
||||
|
26
cmd/tools/vdoc/testdata/output_formats/main.text
vendored
26
cmd/tools/vdoc/testdata/output_formats/main.text
vendored
@ -11,6 +11,32 @@ module main
|
||||
|
||||
## Examples
|
||||
|
||||
### Functions that return different literals:
|
||||
|
||||
Example of a function returning boolean:
|
||||
```v
|
||||
fn is_odd(x int) bool {
|
||||
if x % 2 == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
```
|
||||
|
||||
Another example of a function returning a string:
|
||||
```v
|
||||
fn answer() string {
|
||||
return '42'
|
||||
}
|
||||
```
|
||||
|
||||
This example shows a function returning a string with interpolation:
|
||||
```v
|
||||
fn str_with_interplation() string {
|
||||
return 'this string has ${42:6} interpolation in it.'
|
||||
}
|
||||
```
|
||||
|
||||
### Processing command line args
|
||||
|
||||
```v
|
||||
|
@ -1 +1,18 @@
|
||||
hello from readme
|
||||
|
||||
Example:
|
||||
```v
|
||||
fn is_odd(x int) bool {
|
||||
if x % 2 == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
```
|
||||
|
||||
Another example:
|
||||
```v
|
||||
fn answer() string {
|
||||
return '42'
|
||||
}
|
||||
```
|
||||
|
@ -1,4 +1,16 @@
|
||||
hello from readme
|
||||
Example:
|
||||
fn is_odd(x int) bool {
|
||||
if x % 2 == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Another example:
|
||||
fn answer() string {
|
||||
return '42'
|
||||
}
|
||||
module foo
|
||||
|
||||
fn bar()
|
||||
|
@ -531,7 +531,7 @@ pub fn new() RE
|
||||
After an initializer is used, the regex expression must be compiled with:
|
||||
|
||||
```v ignore
|
||||
// compile_opt compile RE pattern string, returning an error if the compilation fails
|
||||
// compile_opt compile RE pattern string, returning an error if the compilation fails
|
||||
pub fn (mut re RE) compile_opt(pattern string) !
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user