Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/s0/gatsby-remark-tree-sitter
Gatsby plugin to highlight code in Markdown files using tree-sitter
https://github.com/s0/gatsby-remark-tree-sitter
gatsby gatsby-plugin markdown remark syntax-highlighting tree-sitter
Last synced: 14 days ago
JSON representation
Gatsby plugin to highlight code in Markdown files using tree-sitter
- Host: GitHub
- URL: https://github.com/s0/gatsby-remark-tree-sitter
- Owner: s0
- Created: 2019-06-16T17:20:38.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-06-16T20:17:03.000Z (over 5 years ago)
- Last Synced: 2024-12-17T13:40:20.226Z (16 days ago)
- Topics: gatsby, gatsby-plugin, markdown, remark, syntax-highlighting, tree-sitter
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/gatsby-remark-tree-sitter
- Size: 4.88 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gatsby-remark-tree-sitter
[![](https://img.shields.io/npm/v/gatsby-remark-tree-sitter.svg)](https://www.npmjs.com/package/gatsby-remark-tree-sitter)
Highlight code in Markdown files using
[tree-sitter](https://github.com/tree-sitter/tree-sitter), powered by [remark-tree-sitter](https://github.com/samlanning/remark-tree-sitter).## Install
```
npm install --save gatsby-remark-tree-sitter
```## How it works
This plugin uses the same mechanism and data as Atom for syntax highlighting,
So to highlight a particular language, you need to either:* Install the APM (Atom) package for that language and tell `remark-tree-sitter`
to import it, using the [`grammarPackages` option](https://github.com/samlanning/remark-tree-sitter#optionsgrammarpackages).
* Provide the `tree-sitter` grammar and scopeMappings manually,
using the using the [`grammars` option](https://github.com/samlanning/remark-tree-sitter#optionsgrammars).*For more information on how this mechanism works,
[check out the documentation for `tree-sitter-hast`](https://github.com/samlanning/tree-sitter-hast#scope-mappings).*Any code blocks that are encountered for which there is not a matching language will be ignored.
## How to use
Add `gatsby-remark-tree-sitter` to the list of plugins for `gatsby-transformer-remark`,
and list the grammars you want to use in your `gatsby-config.js` file:**Example:**
```
npm install --save @atom-languages/language-typescript
``````js
plugins: [
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: "gatsby-remark-tree-sitter",
options: {
grammarPackages: ['@atom-languages/language-typescript']
},
},
],
},
},
]
```This would then render the following markdown:
````markdown
```typescript
function foo() {
return 1;
}
```
````As this HTML:
```html
function foo() {
return 1;
}
```*Note that either `grammarPackages` or `grammars` **must** be specified in the options.*
For a list of language packages that you can use in `grammarPackages`, please see [Atom language packages](https://github.com/samlanning/remark-tree-sitter#atom-language-packages).
## Whitelisting classes
Sometimes including the full list of classes applied can be too much,
and you'd like to only include those that you have stylesheets for.To do this, you can pass in a whitelist of classes that you actually care about.
**Example:** The following configuration...
```js
plugins: [
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: "gatsby-remark-tree-sitter",
options: {
grammarPackages: ['@atom-languages/language-typescript'],
classWhitelist: ['storage', 'numeric']
},
},
],
},
},
]
```...will convert this markdown...
````md
```typescript
function foo() {
return 1;
}
```
````...to this:
```html
function foo() {
return 1;
}
```## Full Documentation
For for full documentation on the options you can use, please see [the documentation for `remark-tree-sitter`](https://github.com/samlanning/remark-tree-sitter#api), as options are passed directly to that plugin.