diff --git a/content/en/docs/contribute/style/hugo-shortcodes/index.md b/content/en/docs/contribute/style/hugo-shortcodes/index.md
index 2a836ffb913..fa3932f17d9 100644
--- a/content/en/docs/contribute/style/hugo-shortcodes/index.md
+++ b/content/en/docs/contribute/style/hugo-shortcodes/index.md
@@ -83,6 +83,33 @@ You can also include a full definition:
which renders as:
{{< glossary_definition term_id="cluster" length="all" >}}
+## Links to API Reference
+
+You can link to a page of the Kubernetes API reference using the `api-reference` shortcode, for example to the {{< api-reference page="workload-resources/pod-v1" >}} reference:
+
+```
+{{* api-reference page="workload-resources/pod-v1" */>}}
+```
+
+The content of the `page` parameter is the suffix of the URL of the API reference page.
+
+
+You can link to a specific place into a page by specifying an `anchor` parameter, for example to the {{< api-reference page="workload-resources/pod-v1" anchor="PodSpec" >}} reference or the {{< api-reference page="workload-resources/pod-v1" anchor="environment-variables" >}} section of the page:
+
+```
+{{* api-reference page="workload-resources/pod-v1" anchor="PodSpec" */>}}
+{{* api-reference page="workload-resources/pod-v1" anchor="environment-variables" */>}}
+```
+
+
+You can change the text of the link by specifying a `text` parameter, for example by linking to the {{< api-reference page="workload-resources/pod-v1" anchor="environment-variables" text="Environment Variables">}} section of the page:
+
+```
+{{* api-reference page="workload-resources/pod-v1" anchor="environment-variables" text="Environment Variable" */>}}
+```
+
+
+
## Table captions
You can make tables more accessible to screen readers by adding a table caption. To add a [caption](https://www.w3schools.com/tags/tag_caption.asp) to a table, enclose the table with a `table` shortcode and specify the caption with the `caption` parameter.
diff --git a/layouts/shortcodes/api-reference.html b/layouts/shortcodes/api-reference.html
new file mode 100644
index 00000000000..6fdceef8385
--- /dev/null
+++ b/layouts/shortcodes/api-reference.html
@@ -0,0 +1,7 @@
+{{ $base := "docs/reference/kubernetes-api" }}
+{{ $pageArg := .Get "page" }}
+{{ $anchorArg := .Get "anchor" }}
+{{ $textArg := .Get "text" }}
+{{ $page := site.GetPage "page" (printf "%s/%s" $base $pageArg) }}
+{{ $metadata := $page.Params.api_metadata }}
+{{if $textArg}}{{ $textArg }}{{else if $anchorArg}}{{ $anchorArg }}{{else}}{{ $metadata.kind }}{{end}}
\ No newline at end of file
diff --git a/scripts/linkchecker.py b/scripts/linkchecker.py
index 6a5ea7d089e..5bc63e1d7fb 100755
--- a/scripts/linkchecker.py
+++ b/scripts/linkchecker.py
@@ -35,6 +35,8 @@
# + /docs/bar : is a redirect entry, or
# + /docs/bar : is something we don't understand
#
+# + {{ < api-reference page="" anchor="" ... > }}
+# + {{ < api-reference page="" > }}
import argparse
import glob
@@ -72,7 +74,8 @@ ARGS = None
RESULT = {}
# Cached redirect entries
REDIRECTS = {}
-
+# Cached anchors in target pages
+ANCHORS = {}
def new_record(level, message, target):
"""Create new checking record.
@@ -330,6 +333,44 @@ def check_target(page, anchor, target):
msg = "Link may be wrong for the anchor [%s]" % anchor
return new_record("WARNING", msg, target)
+def check_anchor(target_page, anchor):
+ """Check if an anchor is defined in the target page
+
+ :param target_page: The target page to check
+ :param anchor: Anchor string to find in the target page
+ """
+ if target_page not in ANCHORS:
+ try:
+ with open(target_page, "r") as f:
+ data = f.readlines()
+ except Exception as ex:
+ print("[Error] failed in reading markdown file: " + str(ex))
+ return
+ content = "\n".join(strip_comments(data))
+ anchor_pattern1 = r"