Skip to content

Commit 0c12956

Browse files
authored
Show documentation paths beside internal links (#108)
Keep documentation references usable in the terminal by displaying copyable paths and retaining web links.
1 parent 31e9c44 commit 0c12956

5 files changed

Lines changed: 51 additions & 6 deletions

File tree

.agents/features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ Every user-observable behavior of the `k6 x docs` CLI.
115115
88. Strips remaining Hugo shortcodes (youtube, card-grid, collapse, hero-simple)
116116
89. Collapse content preserved (only tags stripped)
117117
90. Replaces `<K6_VERSION>` with actual version
118-
91. Strips markdown links to plain text
118+
91. The CLI opts into shared `docs.Transform` link formatting with `WithLinkSlugs()`: current-version Grafana k6 doc slugs appear in parentheses and backticks after the link text; supports absolute and `/docs/k6/` URLs, matches patch versions to their wildcard version, and drops query strings/fragments from slugs; other markdown links retain their URLs; default shared behavior, existing bundles, and `mcp-k6` remain unchanged; custom options can set exported `TransformOptions.FormatLink`
119119
92. Strips markdown images to alt text
120120
93. Strips HTML comments
121121
94. Strips PascalCase component tags (`<Glossary>`, `<DescriptionList>`, etc.)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/charmbracelet/glamour v1.0.0
77
github.com/creack/pty v1.1.24
88
github.com/go-git/go-git/v5 v5.19.2
9-
github.com/grafana/xk6-docs/docs v0.1.0
9+
github.com/grafana/xk6-docs/docs v0.2.0
1010
github.com/klauspost/compress v1.19.2
1111
github.com/muesli/termenv v0.16.0
1212
github.com/rogpeppe/go-internal v1.14.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ github.com/grafana/sobek-webapi-encoding v0.1.0 h1:2qf2pUiI6j33vl2etSE0Id4mfSQ4J
159159
github.com/grafana/sobek-webapi-encoding v0.1.0/go.mod h1:IegnWm83cyZ8qTnfL6Rivmx7dpMVE+w3CblopwfL/go=
160160
github.com/grafana/xk6-dashboard-assets v0.1.2 h1:n2wqytPICn2ZYsKa9HE6GlvFXk+WjByMfT4eM+ms3gE=
161161
github.com/grafana/xk6-dashboard-assets v0.1.2/go.mod h1:SeoRjvmFF8UhLIFDfvjqqwBtE8MtaIPYIDWqVJZEHDo=
162-
github.com/grafana/xk6-docs/docs v0.1.0 h1:2f9S1qF/VeF9kG+tcLGrI6UMkoQRSSSj45GkDeJX80E=
163-
github.com/grafana/xk6-docs/docs v0.1.0/go.mod h1:IBgZ0BW2xy2hhKaI+pGd/n4Gvi4FfUdR0/YQAVmKYUU=
162+
github.com/grafana/xk6-docs/docs v0.2.0 h1:/IIGby8JmG5rVy3emz+BxKH6P50klacZLrU4Rug6oe0=
163+
github.com/grafana/xk6-docs/docs v0.2.0/go.mod h1:6Vi1nQJjNX57ZNWPsFq7TALQyy1aPCeR+Ep2eo0jZow=
164164
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
165165
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
166166
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=

internal/cli/bundle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (env *docsEnv) readAndTransform(ctx context.Context, slug string) string {
2929
if err != nil {
3030
return ""
3131
}
32-
return docs.Transform(string(data), env.version)
32+
return docs.Transform(string(data), env.version, docs.WithLinkSlugs())
3333
}
3434

3535
// setup resolves the version, ensures docs are cached, and loads the index.
@@ -180,7 +180,7 @@ func printBestPractices(ctx context.Context, env *docsEnv, w io.Writer) error {
180180
if err != nil {
181181
return fmt.Errorf("read best practices: %w", err)
182182
}
183-
content := docs.Transform(string(data), env.version)
183+
content := docs.Transform(string(data), env.version, docs.WithLinkSlugs())
184184
_, _ = fmt.Fprint(w, content)
185185
if !strings.HasSuffix(content, "\n") {
186186
_, _ = fmt.Fprintln(w)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Internal links show a copyable slug; external links retain their URL.
2+
exec ./k6 x docs --cache-dir $WORK/links --version v1.6.x get-started write-your-first-test
3+
cmp stdout expected.md
4+
5+
# TTY output, search navigation, and the best-practices page share the transform.
6+
env NO_COLOR=1
7+
ptyexec ./k6 x docs --cache-dir $WORK/links --version v1.6.x get-started write-your-first-test
8+
cp stdout tty.md
9+
containslines expected.md tty.md
10+
exec ./k6 x docs --cache-dir $WORK/links --version v1.6.x search get-started/write-your-first-test
11+
cmp stdout expected.md
12+
cp links/v1.6.x/markdown/first.md links/v1.6.x/best_practices.md
13+
exec ./k6 x docs --cache-dir $WORK/links --version v1.6.x best-practices
14+
cmp stdout expected.md
15+
16+
# Local source previews keep links through bundle preparation too.
17+
mkdir src/docs/sources/k6/v1.6.x/get-started
18+
cp links/v1.6.x/markdown/first.md src/docs/sources/k6/v1.6.x/get-started/write-your-first-test.md
19+
cp links/v1.6.x/markdown/running.md src/docs/sources/k6/v1.6.x/get-started/running-k6.md
20+
cp index.md src/docs/sources/k6/v1.6.x/get-started/_index.md
21+
exec ./k6 x docs --cache-dir $WORK/source-cache --source $WORK/src --version v1.6.x get-started write-your-first-test
22+
cmp stdout expected.md
23+
24+
-- links/v1.6.x/sections.json --
25+
{"version":"v1.6.x","sections":[{"slug":"get-started/write-your-first-test","rel_path":"first.md"},{"slug":"get-started/running-k6","rel_path":"running.md"}]}
26+
-- links/v1.6.x/markdown/first.md --
27+
Refer to [Running k6](https://grafana.com/docs/k6/<K6_VERSION>/get-started/running-k6/) to learn how to execute your script.
28+
Use [Visual Studio Code](https://code.visualstudio.com/) to edit it.
29+
See [details](https://grafana.com/docs/k6/v1.6.1/get-started/running-k6/#results) and [root-relative](/docs/k6/<K6_VERSION>/get-started/running-k6).
30+
Keep [older docs](https://grafana.com/docs/k6/v1.5.x/get-started/running-k6/), [other docs](https://grafana.com/docs/grafana-cloud/testing/k6/), and [another host](https://example.com/docs/k6/v1.6.x/get-started/running-k6/).
31+
Keep [section](#results), [docs home](https://grafana.com/docs/k6/<K6_VERSION>/), and [web parentheses](https://en.wikipedia.org/wiki/HAR_(file_format)).
32+
Image: ![diagram](https://example.com/diagram.png).
33+
-- links/v1.6.x/markdown/running.md --
34+
# Running k6
35+
-- expected.md --
36+
Refer to Running k6 (`get-started/running-k6`) to learn how to execute your script.
37+
Use [Visual Studio Code](https://code.visualstudio.com/) to edit it.
38+
See details (`get-started/running-k6`) and root-relative (`get-started/running-k6`).
39+
Keep [older docs](https://grafana.com/docs/k6/v1.5.x/get-started/running-k6/), [other docs](https://grafana.com/docs/grafana-cloud/testing/k6/), and [another host](https://example.com/docs/k6/v1.6.x/get-started/running-k6/).
40+
Keep [section](#results), [docs home](https://grafana.com/docs/k6/v1.6.x/), and [web parentheses](https://en.wikipedia.org/wiki/HAR_(file_format)).
41+
Image: diagram.
42+
-- index.md --
43+
---
44+
title: Get started
45+
---

0 commit comments

Comments
 (0)