Skip to content

feat: render Markdown in rich parameter descriptions #6098

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Leave newlines and links
  • Loading branch information
mtojek committed Feb 8, 2023
commit b0ade51e4a0360ba019a1ff62713c8775220b44b
8 changes: 3 additions & 5 deletions coderd/parameter/plaintext.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var plaintextStyle = ansi.StyleConfig{
BlockPrefix: ". ",
}, Task: ansi.StyleTask{},
Link: ansi.StylePrimitive{
Format: " ",
Format: "({{.text}})",
},
LinkText: ansi.StylePrimitive{
Format: "{{.text}}",
Expand All @@ -63,7 +63,7 @@ var plaintextStyle = ansi.StyleConfig{
Format: "{{.text}}",
},
Image: ansi.StylePrimitive{
Format: " ",
Format: "({{.text}})",
},
Code: ansi.StyleBlock{
StylePrimitive: ansi.StylePrimitive{},
Expand Down Expand Up @@ -93,7 +93,5 @@ func Plaintext(markdown string) (string, error) {
}
defer renderer.Close()

output = strings.ReplaceAll(output, "\n", " ")
output = strings.Join(strings.Fields(output), " ")
return output, nil
return strings.TrimSpace(output), nil
}
2 changes: 1 addition & 1 deletion coderd/parameter/plaintext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ __This is bold text.__

` + "`There are also code tags!`"

expected := "Provide the machine image See the registry for options. Minion This is bold text. This is bold text. This is italic text. Blockquotes can also be nested. Strikethrough. 1. Lorem ipsum dolor sit amet. 2. Consectetur adipiscing elit. 3. Integer molestie lorem at massa. There are also code tags!"
expected := "Provide the machine image\nSee the registry (https://container.registry.blah/namespace) for options.\n\nMinion (https://octodex.github.com/images/minion.png)\n\nThis is bold text.\nThis is bold text.\nThis is italic text.\n\nBlockquotes can also be nested.\nStrikethrough.\n\n1. Lorem ipsum dolor sit amet.\n2. Consectetur adipiscing elit.\n3. Integer molestie lorem at massa.\n\nThere are also code tags!"

stripped, err := parameter.Plaintext(mdDescription)
require.NoError(t, err)
Expand Down