Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions claat/parser/gdoc/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const (

// google docs comments are links with commentPrefix.
commentPrefix = "#cmnt"

// the google.com redirector service
redirectorPrefix = "https://www.google.com/url?q="
)

var (
Expand Down Expand Up @@ -786,6 +789,11 @@ func link(ds *docState) nodes.Node {
return nil
}

// re-write google.com redirector URLs
if strings.HasPrefix(href, redirectorPrefix) {
href = strings.TrimPrefix(href, redirectorPrefix)
}

t := nodes.NewTextNode(nodes.NewTextNodeOptions{
Value: text,
})
Expand Down
11 changes: 10 additions & 1 deletion claat/parser/gdoc/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,8 @@ func TestParseFragment(t *testing.T) {
<body>
<p class="title"><a name="a1"></a><span>Test Codelab</span></p>
<p>this should not be ignored</p>
<img src="https://host/image.png">
<p><img src="https://host/image.png"></p>
<span class="c17 c7"><a class="c11" href="https://www.google.com/url?q=https://www.example.com">Test redirector.</a></span>
<div class="comment">
<p><a href="#cmnt_ref1" name="cmnt1">[a]</a><span class="c16 c8">Test comment.</span></p>
</div>
Expand Down Expand Up @@ -568,6 +569,14 @@ func TestParseFragment(t *testing.T) {
para.MutateBlock(true)
want = append(want, para)

tn := nodes.NewTextNode(nodes.NewTextNodeOptions{
Value: "Test redirector.",
})
rlink := nodes.NewURLNode("https://www.example.com", tn)
para = nodes.NewListNode(rlink)
para.MutateBlock(true)
want = append(want, para)

var ctx render.Context
html1, _ := render.HTML(ctx, fragmentNodes...)
html2, _ := render.HTML(ctx, want...)
Expand Down