-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the latest version of russross/blackfriday dep (#2070)
This replaces the code copied from kubectl with calls to the original functions as we aren't doing anything different to what kubectl is doing. This has the affect of using the latest version of the `github.com/russross/blackfriday` dependency. Fixes #2069
- Loading branch information
Showing
5 changed files
with
49 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,15 @@ | ||
/* | ||
Copyright 2016 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package templates | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/MakeNowJust/heredoc/v2" | ||
"github.com/russross/blackfriday" | ||
"k8s.io/kubectl/pkg/util/templates" | ||
) | ||
|
||
const Indentation = ` ` | ||
|
||
// LongDesc normalizes a command's long description to follow the conventions. | ||
func LongDesc(s string) string { | ||
if s == "" { | ||
return s | ||
} | ||
return normalizer{s}.heredoc().markdown().trim().string | ||
return templates.LongDesc(s) | ||
} | ||
|
||
// Examples normalizes a command's examples to follow the conventions. | ||
func Examples(s string) string { | ||
if s == "" { | ||
return s | ||
} | ||
return normalizer{s}.trim().indent().string | ||
} | ||
|
||
type normalizer struct { | ||
string | ||
} | ||
|
||
func (s normalizer) markdown() normalizer { | ||
bytes := []byte(s.string) | ||
formatted := blackfriday.Markdown(bytes, &ASCIIRenderer{Indentation: Indentation}, blackfriday.EXTENSION_NO_INTRA_EMPHASIS) | ||
s.string = string(formatted) | ||
return s | ||
} | ||
|
||
func (s normalizer) heredoc() normalizer { | ||
s.string = heredoc.Doc(s.string) | ||
return s | ||
} | ||
|
||
func (s normalizer) trim() normalizer { | ||
s.string = strings.TrimSpace(s.string) | ||
return s | ||
} | ||
|
||
func (s normalizer) indent() normalizer { | ||
var indentedLines []string | ||
for _, line := range strings.Split(s.string, "\n") { | ||
trimmed := strings.TrimSpace(line) | ||
indented := Indentation + trimmed | ||
indentedLines = append(indentedLines, indented) | ||
} | ||
s.string = strings.Join(indentedLines, "\n") | ||
return s | ||
return templates.Examples(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package templates | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLongDesc(t *testing.T) { | ||
actual := LongDesc(` | ||
Create a job from a file or from stdin. | ||
JSON and YAML formats are accepted. | ||
`) | ||
|
||
assert.Equal(t, `Create a job from a file or from stdin. | ||
JSON and YAML formats are accepted.`, actual) | ||
} | ||
|
||
func TestExamples(t *testing.T) { | ||
actual := Examples(` | ||
# Describe a job with the full ID | ||
bacalhau describe e3f8c209-d683-4a41-b840-f09b88d087b9 | ||
# Describe a job with the a shortened ID | ||
bacalhau describe 47805f5c | ||
# Describe a job and include all server and local events | ||
bacalhau describe --include-events b6ad164a | ||
`) | ||
|
||
assert.Equal(t, ` # Describe a job with the full ID | ||
bacalhau describe e3f8c209-d683-4a41-b840-f09b88d087b9 | ||
# Describe a job with the a shortened ID | ||
bacalhau describe 47805f5c | ||
# Describe a job and include all server and local events | ||
bacalhau describe --include-events b6ad164a`, actual) | ||
} |