Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add unsupported language. #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,57 @@ Syntax highlighting for Dart and Flutter, which supports lots of languages and t
- [All available languages](https://github.com/pd4d10/highlight/tree/master/highlight/lib/languages)
- [All available themes](https://github.com/pd4d10/highlight/blob/master/flutter_highlight/lib/themes)

## How to add unsupported language

1. Install nodejs and gulp.
Highlight.dart uses [nodejs](https://nodejs.org/en/) and [gulp](https://gulpjs.com/) from command line to generate language syntax definition files, so please install nodejs and gulp-cli.

2. make sure your language is [supported by highlight.js](https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md).
3. add your supported language repository as git submodule under `vendor` folder
**Note:** if the `main` key's value of `pacakge.json` in your language repository does not exists, please correct it(and then create a PR to the repository) or the syntax definition file won't be generated.
4. edit `tool/highlight.js` function allModes`:
for exmaple, given I'm trying to add support for GDScript:
```javascript
export function allModes(){
...
const items = [
...dirs.map(file => ({
name: path.basename(file, path.extname(file)),
factory: require(path.resolve(dir, file)),
community: false
})),
{
name: "vue",
factory: require("../vendor/highlightjs-vue/vue").definer,
community: true
},
{
name: "graphql",
factory: require("../vendor/highlightjs-graphql").definer,
community: true
},
{
name: "gn",
factory: require("../vendor/highlightjs-GN").definer,
community: true
},
{
name: "solidity",
factory: require("../vendor/highlightjs-solidity").definer,
community: true
}, // <- don't forget the comma!
/* Below are appended lines*/
{
name: "gdscript",
factory: require("../vendor/highlightjs-gdscript").definer,
community: true
}
/* append end */
];
...
```
5. change your working directory to `tool` and run gulp in command line, and then use `dart format [your directory]` command to format generated dart files.

## License

MIT