MCPcopy
hub / github.com/streetwriters/notesnook / extractHeadline

Function extractHeadline

packages/core/src/utils/html-parser.ts:221–254  ·  view source on GitHub ↗
(html: string, characterLimit: number)

Source from the content-addressed store, hash-verified

219}
220
221export function extractHeadline(html: string, characterLimit: number) {
222 let text = "";
223 let start = false;
224 const parser = new Parser(
225 {
226 onopentag: (name) => {
227 if (name === "p") start = true;
228 },
229 onclosetag: (name) => {
230 if (name === "p") {
231 start = false;
232 parser.pause();
233 parser.end();
234 }
235 },
236 ontext: (data) => {
237 if (start) {
238 text += data;
239 if (text.length > characterLimit) {
240 text = text.slice(0, characterLimit);
241 parser.pause();
242 parser.end();
243 }
244 }
245 }
246 },
247 {
248 lowerCaseTags: false,
249 decodeEntities: true
250 }
251 );
252 parser.end(html);
253 return text;
254}
255
256const TITLE_SOURCE_TAGS = ["p", "h1", "h2", "h3", "h4", "h5", "h6"];
257

Callers 1

toHeadlineMethod · 0.85

Calls 3

pauseMethod · 0.95
endMethod · 0.95
sliceMethod · 0.80

Tested by

no test coverage detected