mirror of
https://github.com/KevinMidboe/inline-html.git
synced 2025-10-29 17:40:29 +00:00
Ignore template expression in link href.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const co = require('co');
|
||||
const fs = require('mz/fs');
|
||||
const isLocalPath = require('is-local-path');
|
||||
const isTemplateExpression = require('./is-template-expression');
|
||||
const less = require('less');
|
||||
const path = require('path');
|
||||
const R = require('ramda');
|
||||
@@ -38,7 +39,10 @@ const inlineLess = co.wrap(function * ($, filename, options) {
|
||||
var files = [];
|
||||
try {
|
||||
const links = $('link[rel="stylesheet/less"]')
|
||||
.filter((index, link) => isLocalPath($(link).attr('href')))
|
||||
.filter((index, link) => {
|
||||
const href = $(link).attr('href');
|
||||
return isLocalPath(href) && !isTemplateExpression(href);
|
||||
})
|
||||
.toArray();
|
||||
const getHref = element => path.resolve(basedir, $(element).attr('href'));
|
||||
const hrefs = R.map(getHref, links);
|
||||
|
||||
1
test/fixtures/nested-import.less
vendored
Normal file
1
test/fixtures/nested-import.less
vendored
Normal file
@@ -0,0 +1 @@
|
||||
@import 'import.less';
|
||||
@@ -275,16 +275,16 @@ describe('inline-html', () => {
|
||||
});
|
||||
|
||||
describe('img', () => {
|
||||
it('inline img src', () => {
|
||||
it('inline local source', () => {
|
||||
const filename = path.resolve(__dirname, 'fixtures/file.txt');
|
||||
const html = `<img src="${filename}"/>`;
|
||||
return expect(inline.html(html)).to.eventually.match(/data:.*,.*/);
|
||||
});
|
||||
it('ignore img src remote paths', () => {
|
||||
it('ignore remote source', () => {
|
||||
const html = `<img src="http://test.com/file.txt?query=string#hash"/>`;
|
||||
return expect(inline.html(html)).to.eventually.equal(html);
|
||||
});
|
||||
it('ignore img src template expression paths', () => {
|
||||
it('ignore template expression source', () => {
|
||||
const html = `<img src="{{path}}"/>`;
|
||||
return expect(inline.html(html)).to.eventually.equal(html);
|
||||
});
|
||||
@@ -325,20 +325,28 @@ describe('inline-html', () => {
|
||||
});
|
||||
|
||||
describe('link-less', () => {
|
||||
it('inline link less', () => {
|
||||
it('inline local href', () => {
|
||||
const filename = path.resolve(__dirname, 'fixtures/basic.less');
|
||||
const html = `<link rel="stylesheet/less" href="${filename}"/>`;
|
||||
return expect(inline.html(html)).to.eventually.match(/<style>[^]*<\/style>/);
|
||||
});
|
||||
it('inline link less imports', () => {
|
||||
const filename = path.resolve(__dirname, 'fixtures/import.less');
|
||||
it('ignore remote href', () => {
|
||||
const html = `<link rel="stylesheet/less" href="http://test.com/main.less"/>`;
|
||||
return expect(inline.html(html)).to.eventually.equal(html);
|
||||
});
|
||||
it('ignore template expression href', () => {
|
||||
const html = `<link rel="stylesheet/less" href="{{href}}"/>`;
|
||||
return expect(inline.html(html)).to.eventually.equal(html);
|
||||
});
|
||||
it('inline local nested imports', () => {
|
||||
const filename = path.resolve(__dirname, 'fixtures/nested-import.less');
|
||||
const html = `<link rel="stylesheet/less" href="${filename}"/>`;
|
||||
return expect(inline.html(html)).to.eventually.match(/<style>[^]*<\/style>/)
|
||||
.and.not.match(/@import/);
|
||||
});
|
||||
it('rebase urls relative to html filename', () => {
|
||||
const filename = path.resolve(__dirname, 'index.html');
|
||||
const href = 'fixtures/import.less';
|
||||
const href = 'fixtures/basic.less';
|
||||
const html = `<link rel="stylesheet/less" href="${href}"/>`;
|
||||
return expect(inline.html(html, { filename })).to.eventually.match(/<style>[^]*<\/style>/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user