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

code-tag

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code-tag

noop functions to help formatters and syntax highlighters recognize embedded code

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
decreased by-35.02%
Maintainers
1
Weekly downloads
 
Created
Source

code-tag npm version (size)

noop functions to help formatters and syntax highlighters recognize embedded code

When embedding other languages in JavaScript, you can mark those strings with a tag function to help JavaScript tools recognize the string as code:

document.body.innerHTML = html`
	<p>This is inline HTML</p>
	<!-- Including comments -->
	<style>.and {css: 'too'}</style>
`;

You can find such tag functions in:

  • code-tag: this package, it returns the string as is
  • escape-goat: it escapes the any replaced value in the string
  • lit-html: it helps write Web Components
  • Apollo: it parses GraphQL strings
  • Emotion: it defines CSS-in-JS
  • etc…

Here are some tools that support them natively:

  • Prettier: it formats the strings as real non-JavaScript code
  • GitHub: it highlights the syntax in the strings as code (as seen in the example above)

Install

npm install code-tag

Usage

import {html, css, gql, md, sql} from 'code-tag';
// Or:
// const {html, css, gql, md, sql} = require('code-tag');

document.body.innerHTML = html`
	<p>This is HTML in JS</p>
`;

document.querySelector('style').textContent = css`
	.this.is {
		css: 'in JS';
	}
`;

await githubQuery(gql`
	query {
		repository(owner: "fregante", name: "template-tags") {
			nameWithOwner
		}
	}
`);

yourMarkdownConverter(md`
	# Markdown

	Is _highlighted_ [as well](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
`);

await sqlQuery(sql`select * from users`);

There's also an any export that you can rename as you please:

import {any as mdx} from 'code-tag';

mdx`
	Some other <New>Language</New>
`;

License

MIT © Federico Brigante

Keywords

FAQs

Package last updated on 11 Dec 2023

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