Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

posthtml-anchor-icon

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

posthtml-anchor-icon

Insert icon immediately after `` using PostHTML

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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)

Keywords

FAQs

Package last updated on 29 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc