PlaintextFromMarkdown function converts the description with optional Markdown tags to the plaintext form.
(markdown string)
| 82 | // PlaintextFromMarkdown function converts the description with optional Markdown tags |
| 83 | // to the plaintext form. |
| 84 | func 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 | |
| 103 | func HTMLFromMarkdown(markdown string) string { |
| 104 | p := parser.NewWithExtensions(parser.CommonExtensions | parser.HardLineBreak) // Added HardLineBreak. |