rehype plugin to enhance raw text with notranslate
.
- What is this?
- When should I use this?
- Install
- Use
- API
- Bugs
- Authoring
- HTML
- CSS
- Syntax
- Types
- Compatibility
- Security
- Related
- Contribute
- Notice
- License
This plugin enhances raw text by adding a mark to them that tells tools like
Google Translate to not translate them.
By default it adds class="notranslate"
to pre
and code
.
This behavior is specific to github.com that only work in comments, not in files.
This plugin is part of a monorepo rehype-github
.
See its readme for more info.
You can use this plugin when you want to match how github.com works or when you want to build similar pipelines that have user content.
This package is ESM only. In Node.js (version 16+), install with npm:
npm install rehype-github-notranslate
In Deno with esm.sh
:
import rehypeGithubNoTranslate from 'https://esm.sh/rehype-github-notranslate@1'
In browsers with esm.sh
:
<script type="module">
import rehypeGithubNoTranslate from 'https://esm.sh/rehype-github-notranslate@1?bundle'
</script>
Say our module example.js
looks as follows:
import rehypeGithubNoTranslate from 'rehype-github-notranslate'
import rehypeParse from 'rehype-parse'
import rehypeStringify from 'rehype-stringify'
import {unified} from 'unified'
const file = await unified()
.use(rehypeParse, {fragment: true})
.use(rehypeGithubNoTranslate)
.use(rehypeStringify)
.process('<code>xxx</code>')
console.log(String(file))
…now running node example.js
yields:
<code class="notranslate">xxx</code>
This package exports the identifier defaultInclude
.
The default export is
rehypeGithubNoTranslate
.
List of tag names that github.com enhances (Array<string>
).
Plugin to enhance raw text with notranslate
.
options
(Options
, optional) — configuration
Configuration (TypeScript type).
include
(Array<string>
, default:defaultInclude
) — elements to enhance; the default behavior is to addnotranslate
tocode
andpre
There are no particular bugs with how this work,
other than that they could do this on files too,
and that they should perhaps use ['code', 'kbd', 'pre', 'tt']
instead.
Furthermore,
there are cases where you would want code to be translated,
that automation can’t solve.
There are no additional recommendations on how to author links in markdown.
The markup for that github.com adds is:
class="notranslate"
No CSS is needed.
No syntax is applicable.
This package is fully typed with TypeScript.
It exports the additional type Options
.
Projects maintained by the unified collective are compatible with all maintained versions of Node.js. As of now, that is Node.js 16+. Our projects sometimes work with older versions, but this is not guaranteed.
This plugin works with rehype-parse
version 3+,
rehype-stringify
version 3+,
rehype
version 5+,
and unified
version 6+.
This package is safe.
remark-gfm
— support GFM in remark
See contributing.md
in rehypejs/.github
for ways to get
started.
See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
This project is not affiliated with GitHub.