| 1631 | } |
| 1632 | |
| 1633 | const markdownToPlainText = function (text) { |
| 1634 | // First, replace HTML tags in text with their plain text contents |
| 1635 | let element |
| 1636 | text = text.replace(/<[^>]*>/g, '') |
| 1637 | const plainTextMarkedRenderer = new marked.Renderer() |
| 1638 | for (element of ['code', 'blockquote', 'html', 'heading', 'hr', 'list', 'listitem', 'paragraph', 'table', 'tablerow', 'tablecell', 'strong', 'em', 'codespan', 'br', 'del', 'text']) { |
| 1639 | plainTextMarkedRenderer[element] = text => text |
| 1640 | } |
| 1641 | for (element of ['link', 'image']) { |
| 1642 | plainTextMarkedRenderer[element] = (href, title, text) => text |
| 1643 | } |
| 1644 | const plainText = marked(text, { renderer: plainTextMarkedRenderer }) |
| 1645 | return plainText |
| 1646 | } |
| 1647 | |
| 1648 | const markedInline = function (text) { |
| 1649 | // Like marked, but inline (no wrapper <p></p>); this is an option in newer marked versions |