diff --git a/claat/parser/gdoc/parse.go b/claat/parser/gdoc/parse.go index ef760a9e4..057b22d44 100644 --- a/claat/parser/gdoc/parse.go +++ b/claat/parser/gdoc/parse.go @@ -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 ( @@ -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, }) diff --git a/claat/parser/gdoc/parse_test.go b/claat/parser/gdoc/parse_test.go index db5d7a19d..87b8a7f42 100644 --- a/claat/parser/gdoc/parse_test.go +++ b/claat/parser/gdoc/parse_test.go @@ -536,7 +536,8 @@ func TestParseFragment(t *testing.T) {

Test Codelab

this should not be ignored

- +

+ Test redirector.

[a]Test comment.

@@ -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...)