Repository: maragudk/gomponents
Pull request #242 (2025-02-05 19:22:13)

Add 'download' and 'referrerpolicy' attributes for anchor <a> element
Hello,

A patch to add [`download`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#download) and [`referrerpolicy`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#referrerpolicy) for the anchor `<a>` element.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/maragudk/gomponents/pull/242?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 100.00%. Comparing base [(`033f6ac`)](https://app.codecov.io/gh/maragudk/gomponents/commit/033f6ac3c36da0e95882d2e00b8cdd54468d3050?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk) to head [(`757d10b`)](https://app.codecov.io/gh/maragudk/gomponents/commit/757d10ba151f824b9600dd2e530324db72a73f68?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).
> Report is 33 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff            @@
##              main      #242   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         5    -4     
  Lines          534       548   +14     
=========================================
+ Hits           534       548   +14     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/maragudk/gomponents/pull/242?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=maragudk).

markuswustenberg: I'm learning so much about HTML attributes I didn't know about these days. :D Thanks, @slegrand45!

Patch:
diff --git a/html/attributes.go b/html/attributes.go
index 6da541d..fb2748b 100644
--- a/html/attributes.go
+++ b/html/attributes.go
@@ -40,6 +40,10 @@ func Disabled() g.Node {
 	return g.Attr("disabled")
 }
 
+func Download(v string) g.Node {
+	return g.Attr("download", v)
+}
+
 func Draggable(v string) g.Node {
 	return g.Attr("draggable", v)
 }
@@ -253,6 +257,10 @@ func Preload(v string) g.Node {
 	return g.Attr("preload", v)
 }
 
+func ReferrerPolicy(v string) g.Node {
+	return g.Attr("referrerpolicy", v)
+}
+
 func Rel(v string) g.Node {
 	return g.Attr("rel", v)
 }


Test patch:
diff --git a/html/attributes_test.go b/html/attributes_test.go
index 9b668b2..88185b1 100644
--- a/html/attributes_test.go
+++ b/html/attributes_test.go
@@ -60,6 +60,7 @@ func TestSimpleAttributes(t *testing.T) {
 		{Name: "draggable", Func: Draggable},
 		{Name: "enctype", Func: EncType},
 		{Name: "dir", Func: Dir},
+		{Name: "download", Func: Download},
 		{Name: "for", Func: For},
 		{Name: "form", Func: FormAttr},
 		{Name: "formaction", Func: FormAction},
@@ -87,6 +88,7 @@ func TestSimpleAttributes(t *testing.T) {
 		{Name: "popovertargetaction", Func: PopoverTargetAction},
 		{Name: "poster", Func: Poster},
 		{Name: "preload", Func: Preload},
+		{Name: "referrerpolicy", Func: ReferrerPolicy},
 		{Name: "rel", Func: Rel},
 		{Name: "role", Func: Role},
 		{Name: "rows", Func: Rows},