Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async parse({asset, config}) {
// if we don't have a config it is posthtml is not configure, don't parse
if (!config) {
return;
}
return {
type: 'posthtml',
version: '0.4.1',
program: parse(await asset.getCode(), {
lowerCaseAttributeNames: true,
}),
};
},
test('should add nano id for relative path', async t => {
const staticID = nanoid();
const input = ``;
const html = (await processing(input)).html;
const id = queryString.parse(parser(html)[0].attrs.href.split('?')[1]).v;
const rel = parser(html)[0].attrs.rel;
t.truthy(id);
t.truthy(rel);
t.is(rel, 'stylesheet');
t.is(id, staticID);
t.is(id.length, 21);
});
test('should exclude tag links', async t => {
const input = '';
const html = (await processing(input, {tags: ['iframe'], exclude: ['link']})).html;
const [iframe, link] = parser(html);
const iframeID = queryString.parse(iframe.attrs.src.split('?')[1]).v;
const linkID = queryString.parse(link.attrs.href.split('?')[1]).v;
t.truthy(iframeID);
t.falsy(linkID);
t.is(iframeID.length, 21);
});
return false;
}
function addSrcSetDependencies(srcset: string) {
const newSources = [];
srcset.split(',').forEach(source => {
const pair = source.trim().split(' ');
if (pair.length === 0) return;
pair[0] = addDependency(pair[0]);
newSources.push(pair.join(' '));
});
return newSources.join(',');
}
const res = parse(code, { lowerCaseAttributeNames: true });
res.walk = api.walk;
res.match = api.match;
res.walk(node => {
if (node == null) {
return node;
}
if (node.attrs) {
if (node.tag === 'meta') {
if (
!Object.keys(node.attrs).some(attr => {
const values = META[attr];
return values && values.includes(node.attrs[attr]);
})
) {
function convertServer(html: string, options: Object = {}): ConvertedComponent {
if (typeof html !== 'string') {
throw new TypeError('Expected HTML string');
}
const opts = {
transform: options.transform || {},
preserveAttributes: options.preserveAttributes || [],
};
const ast = parse(html.trim());
const components = ast
.map((node, index) => transform(node, index.toString(), opts))
.filter(node => node !== null);
if (components.length > 1) {
return components;
}
return components[0];
}
async parse({asset}) {
return {
type: 'posthtml',
version: '0.4.1',
program: parse(await asset.getCode(), {
lowerCaseAttributeNames: true,
}),
};
},