MCPcopy Create free account
hub / github.com/ember-learn/ember-api-docs / createExcerpt

Function createExcerpt

app/utils/create-excerpt.js:3–19  ·  view source on GitHub ↗
(string, maxLength = 300)

Source from the content-addressed store, hash-verified

1import sanitizeHtml from 'sanitize-html';
2
3export default function createExcerpt(string, maxLength = 300) {
4 // Stop at first code example
5 string = string.split('<table')[0];
6
7 let excerpt = sanitizeHtml(string, { allowedTags: [] })
8 // Remove tabs and line breaks
9 .replace(/\t/g, '')
10 .replace(/\n/g, ' ')
11 .trim();
12
13 // Truncate
14 if (excerpt.length > maxLength) {
15 excerpt = excerpt.slice(0, maxLength - 1) + '…';
16 }
17
18 return excerpt;
19}

Callers 3

afterModelMethod · 0.85
afterModelMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected