1.0.5 • Published 2 years ago
posthtml-anchor-host v1.0.5
posthtml-anchor-host
Insert host information immediately after <a href>
using PostHTML
Transform sample
Examples of specifying only required parameters
{ class: 'host-anchor' }
Before:
<a href="https://example.com/" class="host-anchor">Link</a>
<a href="https://example.com/" class="foo host-anchor bar">Link</a>
After:
<a href="https://example.com/">Link</a><span>example.com</span>
<a href="https://example.com/" class="foo bar">Link</a><span>example.com</span>
Examples of specifying all parameters
{ class: 'host-anchor', host_element: 'b', host_class: 'host', host_parentheses_before: '[', host_parentheses_after: ']' }
Before:
<a href="https://example.com/" class="host-anchor">Link</a>
After:
<a href="https://example.com/">Link</a><b class="host">[example.com]</b>
Examples of no transform
<a class="host-anchor">Link</a><!-- No `href` attribute -->
<a href="/" class="host-anchor">Link</a><!-- The `href` attribute value must be an absolute URL for this feature to work -->
Install
npm i -D posthtml-anchor-host
Usage
import posthtml from 'posthtml';
import posthtmlAnchorHost from 'posthtml-anchor-host';
const beforeHtml = '<!DOCTYPE html>...';
const result = posthtml([
posthtmlAnchorHost({
class: 'host-anchor',
host_element: 'b',
host_class: 'host',
host_parentheses_before: '[',
host_parentheses_after: ']',
})
]).process(beforeHtml);
const afterHtml = result.html;