shithub: hugo

Download patch

ref: 7c30e2cbb08fdf0e61f80c7f1aa29909aeca4211
parent: 60bd332c1f68e49e6ac439047e7c660865189380
author: Bjørn Erik Pedersen <[email protected]>
date: Fri Oct 13 05:37:47 EDT 2017

Add table linenos support for Chroma highlighter

Fixes #3915

--- a/helpers/pygments.go
+++ b/helpers/pygments.go
@@ -40,7 +40,6 @@
 
 const pygmentsBin = "pygmentize"
 
-// TODO(bep) document chroma -s perldoc --html --html-styles
 // hasPygments checks to see if Pygments is installed and available
 // on the system.
 func hasPygments() bool {
@@ -309,8 +308,12 @@
 		options = append(options, html.WithClasses())
 	}
 
-	if pygmentsOpts["linenos"] != "" {
+	lineNumbers := pygmentsOpts["linenos"]
+	if lineNumbers != "" {
 		options = append(options, html.WithLineNumbers())
+		if lineNumbers != "inline" {
+			options = append(options, html.LineNumbersInTable())
+		}
 	}
 
 	startLineStr := pygmentsOpts["linenostart"]
--- a/helpers/pygments_test.go
+++ b/helpers/pygments_test.go
@@ -111,6 +111,7 @@
 type chromaInfo struct {
 	classes            bool
 	lineNumbers        bool
+	lineNumbersInTable bool
 	highlightRangesLen int
 	highlightRangesStr string
 	baseLineNumber     int
@@ -120,8 +121,10 @@
 	v := reflect.ValueOf(f).Elem()
 	c := chromaInfo{}
 	// Hack:
-	c.classes = v.FieldByName("classes").Bool()
+
+	c.classes = f.Classes
 	c.lineNumbers = v.FieldByName("lineNumbers").Bool()
+	c.lineNumbersInTable = v.FieldByName("lineNumbersInTable").Bool()
 	c.baseLineNumber = int(v.FieldByName("baseLineNumber").Int())
 	vv := v.FieldByName("highlightRanges")
 	c.highlightRangesLen = vv.Len()
@@ -171,13 +174,18 @@
 			assert.Equal("[[1 1] [2 2] [3 3]]", c.highlightRangesStr)
 			assert.Equal(1, c.baseLineNumber)
 		}},
-		{"linenos=sure,hl_lines=1,linenostart=4", nil, nil, "style=monokai,noclasses=false", func(c chromaInfo) {
+		{"linenos=inline,hl_lines=1,linenostart=4", nil, nil, "style=monokai,noclasses=false", func(c chromaInfo) {
 			assert.True(c.classes)
 			assert.True(c.lineNumbers)
+			assert.False(c.lineNumbersInTable)
 			assert.Equal(1, c.highlightRangesLen)
 			// This compansates for https://github.com/alecthomas/chroma/issues/30
 			assert.Equal("[[4 4]]", c.highlightRangesStr)
 			assert.Equal(4, c.baseLineNumber)
+		}},
+		{"linenos=table", nil, nil, "style=monokai", func(c chromaInfo) {
+			assert.True(c.lineNumbers)
+			assert.True(c.lineNumbersInTable)
 		}},
 		{"style=monokai,noclasses=false", nil, nil, "style=manni,noclasses=true", func(c chromaInfo) {
 			assert.True(c.classes)
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -21,34 +21,34 @@
 			"revisionTime": "2017-08-10T14:37:23Z"
 		},
 		{
-			"checksumSHA1": "OZOPnvP9OY1ADgmcDttl3Zvytcs=",
+			"checksumSHA1": "/xPnkXIHTk3EtmQ9NbufTWUG15g=",
 			"path": "github.com/alecthomas/chroma",
-			"revision": "282a86e2a0ed1739095c404758b99402fe4f7045",
-			"revisionTime": "2017-10-03T14:35:07Z"
+			"revision": "02c4adc0664a104c4ea91c6c3a41a91b93bbd9ef",
+			"revisionTime": "2017-10-14T09:02:40Z"
 		},
 		{
 			"checksumSHA1": "pnWyHePZ2ZE/GEg2fBw/vyjYhmY=",
 			"path": "github.com/alecthomas/chroma/formatters",
-			"revision": "282a86e2a0ed1739095c404758b99402fe4f7045",
-			"revisionTime": "2017-10-03T14:35:07Z"
+			"revision": "02c4adc0664a104c4ea91c6c3a41a91b93bbd9ef",
+			"revisionTime": "2017-10-14T09:02:40Z"
 		},
 		{
-			"checksumSHA1": "cFa4bl6NeNIkSqOsKGY6SI5jprk=",
+			"checksumSHA1": "YgboNwoGG2Yc/rWKaIb00/+Ad5Y=",
 			"path": "github.com/alecthomas/chroma/formatters/html",
-			"revision": "282a86e2a0ed1739095c404758b99402fe4f7045",
-			"revisionTime": "2017-10-03T14:35:07Z"
+			"revision": "02c4adc0664a104c4ea91c6c3a41a91b93bbd9ef",
+			"revisionTime": "2017-10-14T09:02:40Z"
 		},
 		{
-			"checksumSHA1": "MwdDmbQQEpscTjcENv5yUFWIBS0=",
+			"checksumSHA1": "lSa/vZVJvB3+HngwkxBkPHw4EKg=",
 			"path": "github.com/alecthomas/chroma/lexers",
-			"revision": "282a86e2a0ed1739095c404758b99402fe4f7045",
-			"revisionTime": "2017-10-03T14:35:07Z"
+			"revision": "02c4adc0664a104c4ea91c6c3a41a91b93bbd9ef",
+			"revisionTime": "2017-10-14T09:02:40Z"
 		},
 		{
 			"checksumSHA1": "Wxv1e1MLoJGrZ33LgJqaoHcaBTs=",
 			"path": "github.com/alecthomas/chroma/styles",
-			"revision": "282a86e2a0ed1739095c404758b99402fe4f7045",
-			"revisionTime": "2017-10-03T14:35:07Z"
+			"revision": "02c4adc0664a104c4ea91c6c3a41a91b93bbd9ef",
+			"revisionTime": "2017-10-14T09:02:40Z"
 		},
 		{
 			"checksumSHA1": "7yrV1Gzr1ajco1xJ1gsyqRDTY2U=",
@@ -90,14 +90,14 @@
 		{
 			"checksumSHA1": "6y/Ht8J58EotTDBEIuE3+s4AnL8=",
 			"path": "github.com/dlclark/regexp2",
-			"revision": "487489b64fb796de2e55f4e8a4ad1e145f80e957",
-			"revisionTime": "2017-07-18T21:59:41Z"
+			"revision": "7632a260cbaf5e7594fc1544a503456ecd0827f1",
+			"revisionTime": "2017-10-09T02:06:23Z"
 		},
 		{
 			"checksumSHA1": "k0JXX65FspyueQ8/1i50DGRiCUk=",
 			"path": "github.com/dlclark/regexp2/syntax",
-			"revision": "487489b64fb796de2e55f4e8a4ad1e145f80e957",
-			"revisionTime": "2017-07-18T21:59:41Z"
+			"revision": "7632a260cbaf5e7594fc1544a503456ecd0827f1",
+			"revisionTime": "2017-10-09T02:06:23Z"
 		},
 		{
 			"checksumSHA1": "lTESeJAGIWm6b7Xytf9sP3Gjhj8=",
@@ -281,10 +281,10 @@
 			"revisionTime": "2017-07-05T02:17:15Z"
 		},
 		{
-			"checksumSHA1": "OZpv1QDSDG23bzSk/7auPQRB2Qg=",
+			"checksumSHA1": "1KVewmQICPa+IH1gYJUKDgNbKpY=",
 			"path": "github.com/russross/blackfriday",
-			"revision": "4048872b16cc0fc2c5fd9eacf0ed2c2fedaa0c8c",
-			"revisionTime": "2017-07-28T17:53:26Z"
+			"revision": "6d1ef893fcb01b4f50cb6e57ed7df3e2e627b6b2",
+			"revisionTime": "2017-10-11T18:22:19Z"
 		},
 		{
 			"checksumSHA1": "HkNUuhYSk5C2fTMa536jBiORq44=",