Add support for text block links that point to other repos. (#4952)

This commit is contained in:
Martin Taillefer 2019-09-10 11:57:07 -07:00 committed by GitHub
parent c4dd5227f5
commit dfb41ae672
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 3 deletions

View File

@ -401,6 +401,7 @@ The available attributes are:
|`downloadas` | The default file name used when the user [downloads the preformatted block](#download-name).
|`expandlinks` | Whether or not to expand [GitHub file references](#links-to-github-files) in the preformatted block.
|`snippet` | The name of the [snippet](#snippets) of content to extract from the preformatted block.
|`repo` | The repo to use for [GitHub links](#links-to-github-files) embedded in preformatted blocks.
### Inline vs. imported content
@ -467,6 +468,21 @@ Which renders as:
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-reviews-v3.yaml@
{{< /text >}}
Normally, links will point to the current release branch of the `istio/istio` repo. If you'd like a link
that points to a different Istio repo instead, you can use the `repo` attribute:
{{< text markdown >}}
{{</* text syntax="bash" repo="operator" */>}}
$ cat @README.md@
{{</* /text */>}}
{{< /text >}}
which renders as:
{{< text syntax="bash" repo="operator" >}}
$ cat @README.md@
{{< /text >}}
If your preformatted content happens to use @ symbols for something else, you can turn off link expansion using the
`expandlinks` attribute:

View File

@ -25,7 +25,7 @@ archive_date: YYYY-MM-DD
archive_search_refinement: "V1.1"
# GitHub branch names used when the docs have links to GitHub
source_branch_name: master
source_branch_name: release-1.3
doc_branch_name: master
# The list of supported versions described by the docs

View File

@ -5,6 +5,11 @@
{{- $output_is := .Get "outputis" | default (.Get 1) -}}
{{- $download_as := .Get "downloadas" -}}
{{- $snippet := .Get "snippet" -}}
{{- $repo := .Get "repo" -}}
{{- if not $repo }}
{{- $repo = "istio" }}
{{- end -}}
{{- $expand_links := "true" -}}
@ -78,6 +83,9 @@
{{- if $output_is -}}
{{- $attrs = printf "%sdata-outputis='%s' " $attrs $output_is -}}
{{- end -}}
{{- if $expand_links -}}
{{- $attrs = printf "%sdata-repo='%s' " $attrs $repo -}}
{{- end -}}
{{- $anchor := "" }}
{{- if $url -}}
@ -91,7 +99,7 @@
{{- range $link := $links -}}
{{- $target := trim $link "@" -}}
{{- if gt (len $target) 0 -}}
{{- $anchor = printf "<a data-skipendnotes='true' style='display:none' href='https://raw.githubusercontent.com/istio/istio/%s/%s'>Zip</a>%s" $branch $target $anchor -}}
{{- $anchor = printf "<a data-skipendnotes='true' style='display:none' href='https://raw.githubusercontent.com/istio/%s/%s/%s'>Zip</a>%s" $repo $branch $target $anchor -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -259,7 +259,7 @@ function handleCodeBlocks() {
if (cmd !== "") {
if (code.dataset.expandlinks === "true") {
cmd = cmd.replace(/@(.*?)@/g, "<a href='https://raw.githubusercontent.com/istio/istio/" + branchName + "/$1'>$1</a>");
cmd = cmd.replace(/@(.*?)@/g, "<a href='https://raw.githubusercontent.com/istio/" + code.dataset.repo + "/" + branchName + "/$1'>$1</a>");
}
let html = "<div class='command'>" + cmd + "</div>";