aboutsummaryrefslogtreecommitdiff
path: root/devtools/cmd/css
diff options
context:
space:
mode:
authorJamal Carvalho <jamal@golang.org>2020-10-30 09:25:05 -0400
committerJamal Carvalho <jamal@golang.org>2020-11-02 17:12:21 +0000
commite78f3491d2934d87eb12ae54bfafb70ebdac97f4 (patch)
tree1ca2051109989ec179957bc96c66b7a97a6764dd /devtools/cmd/css
parent44ee364c024daaf0233383b125a9628dbec59939 (diff)
downloadgo-x-pkgsite-e78f3491d2934d87eb12ae54bfafb70ebdac97f4.tar.xz
content,devtools: update readme.css for goldmark styles
Updates css generator and creates new readme.css file that preserves github heading styles when using the goldmark parser. Change-Id: Iddd2ea99711ffe11c14f6e9e2087b023b7d73325 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/266580 Trust: Jamal Carvalho <jamal@golang.org> Reviewed-by: Julie Qiu <julie@golang.org>
Diffstat (limited to 'devtools/cmd/css')
-rw-r--r--devtools/cmd/css/main.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/devtools/cmd/css/main.go b/devtools/cmd/css/main.go
index 6324c15b..f2de24c9 100644
--- a/devtools/cmd/css/main.go
+++ b/devtools/cmd/css/main.go
@@ -59,6 +59,9 @@ func main() {
)
for scanner.Scan() {
text := scanner.Text()
+ if headerString := replaceHeaderTag(text); headerString != "" {
+ text = headerString
+ }
if atPropertyStart && shouldIncludeProperty(text) {
includeProperty = true
}
@@ -131,6 +134,21 @@ func main() {
}
}
+// replaceHeaderTag finds any header tags in a line of text and increases
+// the header level by 2. replaceHeader tag returns the replaced string if a
+// header tag is found and returns an empty string if not
+func replaceHeaderTag(property string) string {
+ headerMap := map[string]string{
+ "h1": "h3", "h2": "h4", "h3": "h5", "h4": "h6", "h5": "div[aria-level=7]", "h6": "div[aria-level=8]",
+ }
+ for k, v := range headerMap {
+ if strings.Contains(property, k) {
+ return strings.ReplaceAll(property, k, v)
+ }
+ }
+ return ""
+}
+
// shouldIncludeProperty reports whether this property should be included in
// the CSS file.
func shouldIncludeProperty(property string) bool {