MCPcopy Create free account
hub / github.com/danmactough/node-feedparser / rewriteHtmlTagUris

Function rewriteHtmlTagUris

lib/utils.js:276–320  ·  view source on GitHub ↗
(tag, baseUrl)

Source from the content-addressed store, hash-verified

274}
275
276function rewriteHtmlTagUris (tag, baseUrl) {
277 var i = 1;
278 var out = '';
279 var last = 0;
280
281 if (tag[i] === '/') return tag;
282 while (i < tag.length && !/[\s/>]/.test(tag[i])) i++;
283
284 while (i < tag.length) {
285 while (i < tag.length && /\s/.test(tag[i])) i++;
286 if (i >= tag.length || tag[i] === '>' || tag[i] === '/') break;
287
288 var nameStart = i;
289 while (i < tag.length && !/[\s=/>]/.test(tag[i])) i++;
290 var name = tag.slice(nameStart, i);
291
292 while (i < tag.length && /\s/.test(tag[i])) i++;
293 if (tag[i] !== '=') continue;
294 i++;
295 while (i < tag.length && /\s/.test(tag[i])) i++;
296
297 var quote = null;
298 if (tag[i] === '"' || tag[i] === '\'') {
299 quote = tag[i];
300 i++;
301 }
302
303 var valueStart = i;
304 if (quote) {
305 while (i < tag.length && tag[i] !== quote) i++;
306 } else {
307 while (i < tag.length && !/[\s/>]/.test(tag[i])) i++;
308 }
309 var valueEnd = i;
310 var value = tag.slice(valueStart, valueEnd);
311 var resolved = resolveHtmlAttributeValue(baseUrl, name, value);
312 if (resolved !== value) {
313 out += tag.slice(last, valueStart) + resolved;
314 last = valueEnd;
315 }
316 if (quote && tag[i] === quote) i++;
317 }
318
319 return out ? out + tag.slice(last) : tag;
320}
321
322function resolveHtmlUris (html, baseUrl) {
323 if (!baseUrl || !html || typeof html !== 'string') return html;

Callers 1

resolveHtmlUrisFunction · 0.85

Calls 1

Tested by

no test coverage detected