Skip to content

Commit

Permalink
Merge pull request #8 from posthtml/milestone-1.2.1
Browse files Browse the repository at this point in the history
Milestone 1.2.1
  • Loading branch information
cossssmin authored May 23, 2020
2 parents 10621af + 0860192 commit d1ba137
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 251 deletions.
29 changes: 16 additions & 13 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@ module.exports = (options = {}) => tree => {
const all = []

tree.match(matcher(options.tags.join()), node => {
const responseAssign = response => {
let [item] = response.tree;

if (typeof item === 'string') {
item = {content: [item]};
}

Object.assign(node, item);
}

if (node.attrs && node.attrs[options.attribute]) {
options.got.url = options.got.url || node.attrs[options.attribute]

all.push(new Promise((resolve, reject) => {
if (options.preserveTag === false) {
node.tag = false
}

Promise.resolve((() => {
let plugins = []
let content = tree.render(node);
Expand All @@ -33,10 +39,7 @@ module.exports = (options = {}) => tree => {

return posthtml(plugins).process(content)
})())
.then(response => {
const [item] = response.tree;
Object.assign(node, item);
})
.then(responseAssign)
.then(got.bind(null, options.got))
.then(({body}) => {
let plugins = []
Expand All @@ -62,13 +65,13 @@ module.exports = (options = {}) => tree => {

return posthtml(plugins).process(content)
})
.then(response => {
const [item] = response.tree;
Object.assign(node, item);
})
.then(responseAssign)
.then(() => {
resolve(node)
if (options.preserveTag === false) {
node.tag = false
}
})
.then(resolve.bind(null, node))
.catch(reject)
})
)
Expand Down
Loading

0 comments on commit d1ba137

Please sign in to comment.