This package has been deprecated

Author message:

This package has been deprecated

posthtml-anchor-icon
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

posthtml-anchor-icon

npm version Build Status Coverage Status

PostHTML logo

Insert icon immediately after <a href> using PostHTML

Transform sample

Examples of specifying only required parameters

{ class: 'icon-anchor', host_info: [ { host: 'example.com', site_name: 'Example', icon_src: '/icon/example.svg' }] }

Before:

<a href="https://example.com/" class="icon-anchor">Link</a>
<a href="https://example.com/" class="foo icon-anchor bar">Link</a>

After:

<a href="https://example.com/">Link</a><img src="/icon/example.svg" alt="Example">
<a href="https://example.com/" class="foo bar">Link</a><img src="/icon/example.svg" alt="Example">

Examples of specifying all parameters

{ class: 'icon-anchor', host_info: [ { host: 'example.com', site_name: 'Example', icon_src: '/icon/example.svg' }], icon_class: 'icon', icon_size: 16, icon_parentheses_before: '[', icon_parentheses_after: ']' }

Before:

<a href="https://example.com/" class="icon-anchor">Link</a>

After:

<a href="https://example.com/">Link</a><img src="/icon/example.svg" alt="[Example]" width="16" height="16" class="icon">

Examples of no transform

<a class="icon-anchor">Link</a><!-- No `href` attribute -->
<a href="/" class="icon-anchor">Link</a><!-- The `href` attribute value must be an absolute URL for this feature to work -->

Install

npm i -D posthtml-anchor-icon

Usage

import posthtml from 'posthtml';
import posthtmlAnchorIcon from 'posthtml-anchor-icon';

const beforeHtml = '<!DOCTYPE html>...';

const result = posthtml([
	posthtmlAnchorIcon({
		class: 'host-anchor',
		host_info: [
			{
				host: 'foo.example.com',
				site_name: 'Example com - foo',
				icon_src: '/icon/com_example_foo.svg',
			},
			{
				host: 'bar.example.com',
				site_name: 'Example com - bar',
				icon_src: '/icon/com_example_bar.svg',
			},
			{
				host: 'example.net',
				site_name: 'Example net',
				icon_src: '/icon/net_example.png',
			},
		],
		icon_class: 'host',
		icon_size: 16,
		icon_parentheses_before: '[',
		icon_parentheses_after: ']',
	})
]).process(beforeHtml);

const afterHtml = result.html;

Options

class [Required]
Class name of the <a> element to process.
host_info [Required]
List of the following objects:
  • host [Required]: Domain name (Exact domain name must be defined, including subdomains)
  • site_name [Required]: Site name (Used in alt attribute values)
  • icon_src [Required]: Address of the icon file (Used in src attribute values)
icon_class [Optional]
Class name of the <img> element displaying icon.
icon_size [Optional]
Icon size. (Used in width and height attribute values)
icon_parentheses_before [Optional]
Opening parentheses at site name. (Used in alt attribute values)
icon_parentheses_after [Optional]
Closing parentheses at site name. (Used in alt attribute values)

Package Sidebar

Install

npm i posthtml-anchor-icon

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

33.3 kB

Total Files

9

Last publish

Collaborators

  • saekitominaga