remy / inliner

Node utility to inline images, CSS and JavaScript for a web page - useful for mobile sites
MIT License
1.1k stars 165 forks source link

feat: resolve external absolute path by baseURL #79

Closed okamuuu closed 8 years ago

okamuuu commented 8 years ago

I want to do inlining a local html file. but the html has some external absolute links. inliner.get happens error INVALID URL in this situation.

I resoved the problem with overwrite Inliner.prototyep.resolve as follows:

const path = require('path');
const Inliner = require('inliner');

// add
let baseURL;

Inliner.prototype.resolve = (from, to) => {
  if (!to) {
    to = from;
    from = this.url;
  }
  // add
  if (this.baseURL) {
    from = this.baseURL;
  }
  ...
}

// this is my own code
myinline = (html, opts, callback) => {
  baseURL = opts.baseURL;
  new Inliner(url, (err, result) => {
    if (err) {
      return callback(err);
    }
  callback(null, result);
  });
}

this way is working. but actually, I want new argument baseURL.

var Inliner = require('./lib/index');

new Inliner('<html><head><link rel="stylesheet" href="/simple.css" /></head><body></body></html>', {baseURL: 'http://localhost:8000'}, function (err, html) { 
  console.log(html); // <html><head><style>body{ color:#333;}</style></head><body></body></html>
});

So I suggest this PR. Please check it if you think it is worth.

okamuuu commented 8 years ago

I found bug.. so I close this.