vadimdemedes / code-tag

noop functions to help formatters and syntax highlighters recognize embedded code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

code-tag npm version

noop functions to help formatters and syntax highlighters recognize embedded code

By marking your embedded code with one of these functions, Prettier and syntax highlighters will recognize a string as a piece of code to format or highlight. You can see that GitHub also correctly highlights HTML within javascript as long as it uses the tag

document.body.innerHTML = html`
	<!-- Uses the tag        πŸ‘† -->
	<p>Highlighted HTML in JS πŸ™‚</p>
	<style>
		.and {
			css: 'too';
		}
	</style>
`;

document.body.innerHTML = `
	<!-- No tag             πŸ‘† -->
	<p>Just HTML in JS πŸ˜•</p>
	<style>.and {raw: 'css'}</style>
`;

Install

npm install code-tag

Usage

import {html, css, gql, md} from 'code-tag';
// Or:
// const {html, css, gql, md} = 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)
`);

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

About

noop functions to help formatters and syntax highlighters recognize embedded code

License:MIT License


Languages

Language:JavaScript 68.8%Language:TypeScript 31.3%