-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(gnoweb): add hyperlinks to import p/*
and r/*
in source code viewer
#3759
Open
mous1985
wants to merge
35
commits into
gnolang:master
Choose a base branch
from
mous1985:linkimport
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+139
−2
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
f03b438
feat: add processing import
mous1985 2f8b529
feat: add hiperlink for source code of gno import
mous1985 27f7ac8
feat: make gno.land imports link to their source code
mous1985 bc14e9c
doc: re-add comments deleted by mistake
mous1985 76be49a
ref: move style to input.css
mous1985 94e4d74
fix: typo
mous1985 207cde4
fix: remove temp file from base32 package
mous1985 efdbef4
Merge branch 'master' into linkimport
mous1985 a32fbf8
fix: ci
mous1985 ae6382b
fix : ci update generated files
mous1985 fffb7f4
ref: use Tailwaind config theme instead to new class
mous1985 cf94c68
Merge branch 'master' into linkimport
mous1985 97e8ae5
fix: CI
mous1985 24991fa
Merge branch 'linkimport' of https://github.com/mous1985/gno into lin…
mous1985 e9130a0
ref: remove logger
mous1985 ede8448
fix: CI
mous1985 d17d363
test: add test cases for FormatSource
mous1985 be86fba
Merge remote-tracking branch 'upstream/master' into linkimport
mous1985 b409a55
Merge branch 'master' into linkimport
2346a61
Update gno.land/pkg/gnoweb/webclient_html.go
mous1985 30f26a5
fix: CI update test
558b00d
Merge branch 'master' into linkimport
c57b3de
Merge branch 'linkimport' of https://github.com/mous1985/gno into lin…
d9f5794
Merge branch 'master' of https://github.com/mous1985/gno into linkimport
4887d09
Merge branch 'master' of https://github.com/mous1985/gno into linkimport
f471bda
Merge branch 'master' of https://github.com/mous1985/gno into linkimport
9fbfd2f
ref: remove contains gno.land
5d43cc6
ref: add const to chroma span formatting
a3ce1be
Merge branch 'master' of https://github.com/mous1985/gno into linkimport
3952b3d
Merge branch 'master' of https://github.com/mous1985/gno into linkimport
3d25c38
ref: use regex
89c0e2b
Merge branch 'master' of https://github.com/mous1985/gno into linkimport
b0e05ba
Merge branch 'master' into linkimport
mous1985 4a18050
Merge branch 'master' of https://github.com/mous1985/gno into linkimport
62e8feb
Merge branch 'master' into linkimport
thehowl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package gnoweb | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log/slog" | ||
"testing" | ||
|
||
chromahtml "github.com/alecthomas/chroma/v2/formatters/html" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFormatSource(t *testing.T) { | ||
// Setup test client with a no-op logger | ||
logger := slog.New(slog.NewTextHandler(bytes.NewBuffer(nil), nil)) | ||
|
||
cfg := &HTMLWebClientConfig{ | ||
Domain: "gno.land", | ||
ChromaStyle: chromaDefaultStyle, | ||
ChromaHTMLOptions: []chromahtml.Option{ | ||
chromahtml.WithClasses(true), | ||
chromahtml.ClassPrefix("chroma-"), | ||
}, | ||
} | ||
client := NewHTMLClient(logger, cfg) | ||
|
||
cases := []struct { | ||
name string | ||
fileName string | ||
input string | ||
expectedPaths []string | ||
linkable bool | ||
}{ | ||
{ | ||
name: "single import", | ||
fileName: "test.gno", | ||
input: `import "gno.land/a/b/abc"`, | ||
expectedPaths: []string{"a/b/abc"}, | ||
linkable: true, | ||
}, | ||
{ | ||
name: "multiple imports", | ||
fileName: "test.gno", | ||
input: `import ( | ||
"gno.land/a/b/abc" | ||
"gno.land/d/e/def" | ||
)`, | ||
expectedPaths: []string{"a/b/abc", "d/e/def"}, | ||
linkable: true, | ||
}, | ||
{ | ||
name: "named import", | ||
fileName: "test.gno", | ||
input: `import name "gno.land/x/y/xyz"`, | ||
expectedPaths: []string{"x/y/xyz"}, | ||
linkable: true, | ||
}, | ||
{ | ||
name: "empty name import", | ||
fileName: "test.gno", | ||
input: `import _ "gno.land/a/b/abc"`, | ||
expectedPaths: []string{"a/b/abc"}, | ||
linkable: true, | ||
}, | ||
{ | ||
name: "multiple imports with name and empty name", | ||
fileName: "test.gno", | ||
input: `import ( | ||
name "gno.land/x/y/xyz" | ||
_ "gno.land/a/b/abc" | ||
)`, | ||
expectedPaths: []string{"x/y/xyz", "a/b/abc"}, | ||
linkable: true, | ||
}, | ||
{ | ||
name: "non gno file", | ||
fileName: "test.go", | ||
input: `import "gno.land/a/b/abc"`, | ||
expectedPaths: []string{}, | ||
linkable: false, | ||
}, | ||
} | ||
|
||
for _, tt := range cases { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var buf bytes.Buffer | ||
err := client.FormatSource(&buf, tt.fileName, []byte(tt.input)) | ||
assert.NoError(t, err) | ||
|
||
result := buf.String() | ||
|
||
if tt.linkable { | ||
// Check each expected path has a corresponding link | ||
for _, path := range tt.expectedPaths { | ||
expectedLink := fmt.Sprintf(`<a href="/%s$source"`, path) | ||
assert.Contains(t, result, expectedLink, | ||
"Should contain link to source for path %s", path) | ||
assert.Contains(t, result, `class="hover:underline"`) | ||
} | ||
} else { | ||
assert.NotContains(t, result, `<a href=`, | ||
"Should not contain any links") | ||
} | ||
|
||
// Check syntax highlighting is present | ||
assert.Contains(t, result, `<span class="chroma-`) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a hack
We have an extensible markdown engine, we should implement this as an extension there, unless you can show it's impossible