https://github.com/itpropro/hexo-tag-ghcode
Hexo plugin to insert code from GitHub
https://github.com/itpropro/hexo-tag-ghcode
Last synced: 3 months ago
JSON representation
Hexo plugin to insert code from GitHub
- Host: GitHub
- URL: https://github.com/itpropro/hexo-tag-ghcode
- Owner: itpropro
- License: mit
- Created: 2019-07-08T10:57:48.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:32:22.000Z (over 1 year ago)
- Last Synced: 2025-04-02T21:18:41.392Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hexo-tag-github-code
**Taken over from [hexo-tag-github-code](https://github.com/itpropro/hexo-tag-ghcode), as the author [nkmk](https://github.com/nkmk) has stopped maintaining the repository.**
Insert code from [GitHub](https://github.com/) when static files are generated.
Not embed.
## Install
```sh
$ npm install hexo-tag-github-code --save
```## Usage
```
{% ghcode URL [start_line stop_line] [options] %}
```## Support URL
### GitHub / Gist
- URL of each file page as below
- https://github.com/itpropro/hexo-tag-ghcode/blob/master/index.js
- https://gist.github.com/nkmk/d60cdbcffdb60d624ac01871543f79a2
- https://gist.github.com/nkmk/d60cdbcffdb60d624ac01871543f79a2#file-sample-py
- URL links to raw file as below
- https://raw.githubusercontent.com/itpropro/hexo-tag-ghcode/master/index.js
- https://gist.githubusercontent.com/nkmk/d60cdbcffdb60d624ac01871543f79a2/raw/e7528c00addcdd0b4d00cb9bbd8d225cc132fbfc/sample.py
- URL of github permalink
- https://github.com/itpropro/hexo-tag-ghcode/blob/master/index.js#L5-L16
- https://github.com/itpropro/hexo-tag-ghcode/blob/master/index.js#L116### Other site
If URL links to raw file, it will work.## Options
Set like as `{cap:false,re:true,lang:javascript}`. Please do __NOT__ insert any spaces.
| option | description | default |
| :--- | :--- | :--- |
| cap| `true`: show caption
`false`: no caption | `true` |
| re| `true`: the first line number restart from 1
`false`: the first line number start from original code number | `false` |
| lang| the language to use for highlighting | the extension of the file |### Config setting
You can change default settings in `_config.yml` as below.
```yml
github_code:
cap: false
re: true
```## Examples
### Full code
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js %}
```### Selected lines
Insert code from line 17 to line 22.
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 %}
```
### Without caption
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 {cap:false} %}
```
### Restart the first line number from 1
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 {re:true} %}
```
### Force the language highlighting to HTML for a JavaScript file
```
{% ghcode https://github.com/nkmk/hexo-list-related-posts/blob/master/lib/index.js 17 22 {lang:html} %}
```