Skip to content
Discussion options

You must be logged in to vote

Hi yes this is available when using posthtml since version 0.16.0

Here is an example that implements what you need through a plugin, referring to the properties of the tree and the node.

const fs = require('fs');
const path = require('path');

const posthtml = require('posthtml');

const files = [
  'files/index.html',
  'files/test.html'
]

const plugin = function (tree) {
  tree.walk(node => {
    Object.assign(node, { 
      attrs: { 
        'data-file-name': tree.options.from,
        'data-location': JSON.stringify(node.location)
      } 
    });
    
    return node;
  })
  return tree;
}


files.forEach(file => {
  const html = fs.readFileSync(path.join(__dirname, file), 'utf-8');

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by vimtor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants