MCPcopy Index your code
hub / github.com/coder/coder / PlaintextFromMarkdown

Function PlaintextFromMarkdown

coderd/render/markdown.go:84–101  ·  view source on GitHub ↗

PlaintextFromMarkdown function converts the description with optional Markdown tags to the plaintext form.

(markdown string)

Source from the content-addressed store, hash-verified

82// PlaintextFromMarkdown function converts the description with optional Markdown tags
83// to the plaintext form.
84func PlaintextFromMarkdown(markdown string) (string, error) {
85 renderer, err := glamour.NewTermRenderer(
86 glamour.WithStandardStyle("ascii"),
87 glamour.WithWordWrap(0), // don't need to add spaces in the end of line
88 glamour.WithStyles(plaintextStyle),
89 )
90 if err != nil {
91 return "", xerrors.Errorf("can't initialize the Markdown renderer: %w", err)
92 }
93
94 output, err := renderer.Render(markdown)
95 if err != nil {
96 return "", xerrors.Errorf("can't render description to plaintext: %w", err)
97 }
98 defer renderer.Close()
99
100 return strings.TrimSpace(output), nil
101}
102
103func HTMLFromMarkdown(markdown string) string {
104 p := parser.NewWithExtensions(parser.CommonExtensions | parser.HardLineBreak) // Added HardLineBreak.

Callers 5

TemplateVersionParameterFunction · 0.92
TestPlaintextFunction · 0.92

Calls 3

RenderMethod · 0.65
CloseMethod · 0.65
ErrorfMethod · 0.45

Tested by 2

TestPlaintextFunction · 0.74