Skip to content

Commit 86019d2

Browse files
Uday HiwaraleUday Hiwarale
Uday Hiwarale
authored and
Uday Hiwarale
committed
init
1 parent 4715e32 commit 86019d2

File tree

404 files changed

+76549
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

404 files changed

+76549
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+62-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
1-
# catage
2-
Node package and CLI tool to convert code into image with syntax highlighting
1+
# catage (**ca**t to im**age**)
2+
Node package and CLI tool to convert code into image with syntax highlighting.
3+
4+
## Install using NPM
5+
```bash
6+
npm install --save catage
7+
```
8+
9+
## API
10+
```js
11+
const path = require( 'path' );
12+
13+
// import convert function and constants
14+
const { convert, IMAGE_FORMATS, LANGUAGES, THEMES } = require( 'catage' );
15+
16+
// output code of `code` in `code.png` file
17+
convert( options );
18+
```
19+
20+
### options
21+
| Name | Use | default Value |
22+
| ---- | --- | ------------- |
23+
| inputFile | Relative or absolue path of a code (text) file | undefined |
24+
| outputFile | Relative or absolue of the output image file | undefined |
25+
| language | Language of the code file | LANGUAGES.DART |
26+
| theme | Theme for the syntax highlighting | LANGUAGES.DART |
27+
| language | Language of the code file | THEMES.FIREWATCH |
28+
| padding | Gap between code and image edges. Value could be string or a number | '20,30' |
29+
| format | Format of the output image file | IMAGE_FORMATS.PNG |
30+
31+
> Supported themes: https://iterm2colorschemes.com/
32+
33+
> Supported languages: https://github.com/highlightjs/highlight.js/tree/master/src/languages
34+
35+
> Supported image formats: jpeg,jpg
36+
37+
## Example
38+
```js
39+
const path = require( 'path' );
40+
41+
// import convert function and constants
42+
const { convert, IMAGE_FORMATS, LANGUAGES, THEMES } = require( '../' );
43+
44+
// output code of `code` in `code.png` file
45+
convert( {
46+
inputFile: path.resolve( __dirname, 'code.dart' ),
47+
outputFile: path.resolve( __dirname, 'code.png' ),
48+
language: LANGUAGES.DART,
49+
theme: THEMES.FIREWATCH,
50+
padding: '20,30',
51+
format: IMAGE_FORMATS.PNG,
52+
} );
53+
```
54+
55+
![example](/test/code.png?raw=true)
56+
57+
58+
## Upcoming changes
59+
- CLI Tool
60+
- Output image corner radius
61+
- Adding MacOS window frame to output image
62+
- Executing code file and compositing output image with the results

assets/getConstants.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const path = require( 'path' );
2+
const glob = require( 'glob-promise' );
3+
const _ = require( 'lodash' );
4+
5+
/******************************************************************************/
6+
7+
// get list of support languages for highlight
8+
const languageFiles = glob.sync( path.resolve( __dirname, 'languages/*.js' ) );
9+
const languages = languageFiles.map( languageFile => {
10+
const fileInfo = path.parse( languageFile );
11+
12+
// return an array of `key:value` pairs for `fromPairs` to use
13+
return [ fileInfo.name.replace(/[_\s\-\.]+/, '_').toUpperCase(), fileInfo.name ];
14+
} );
15+
16+
// print languages
17+
// console.log( 'languages: => ', JSON.stringify( _.fromPairs( languages ), null, 2 ) );
18+
19+
/******************************************************************************/
20+
21+
// get list of support terminal themes (iterm)
22+
const themeFiles = glob.sync( path.resolve( __dirname, 'iterm-themes/*.itermcolors' ) );
23+
const themes = themeFiles.map( themeFile => {
24+
const fileInfo = path.parse( themeFile );
25+
26+
// return an array of `key:value` pairs for `fromPairs` to use
27+
return [ fileInfo.name.replace(/[_\s\-\.]+/, '_').toUpperCase(), fileInfo.name ];
28+
} );
29+
30+
// print themes
31+
console.log( 'themes: => ', JSON.stringify( _.fromPairs( themes ), null, 2 ) );
+222
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Name: 3024 day
5+
Author: Jan T. Sott (http://github.com/idleberg)
6+
7+
3024 color scheme by Jan T. Sott (https://github.com/idleberg)
8+
Built with a modified version of Base16 Builder by Chris Kempson (https://github.com/chriskempson)
9+
10+
-->
11+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
12+
<plist version="1.0">
13+
<dict>
14+
<key>Ansi 0 Color</key>
15+
<dict>
16+
<key>Blue Component</key>
17+
<real>0.0</real>
18+
<key>Green Component</key>
19+
<real>0.011764705882352941</real>
20+
<key>Red Component</key>
21+
<real>0.03529411764705882</real>
22+
</dict>
23+
<key>Ansi 1 Color</key>
24+
<dict>
25+
<key>Blue Component</key>
26+
<real>0.12549019607843137</real>
27+
<key>Green Component</key>
28+
<real>0.17647058823529413</real>
29+
<key>Red Component</key>
30+
<real>0.8588235294117647</real>
31+
</dict>
32+
<key>Ansi 10 Color</key>
33+
<dict>
34+
<key>Blue Component</key>
35+
<real>0.19607843137254902</real>
36+
<key>Green Component</key>
37+
<real>0.20392156862745098</real>
38+
<key>Red Component</key>
39+
<real>0.22745098039215686</real>
40+
</dict>
41+
<key>Ansi 11 Color</key>
42+
<dict>
43+
<key>Blue Component</key>
44+
<real>0.2627450980392157</real>
45+
<key>Green Component</key>
46+
<real>0.27058823529411763</real>
47+
<key>Red Component</key>
48+
<real>0.2901960784313726</real>
49+
</dict>
50+
<key>Ansi 12 Color</key>
51+
<dict>
52+
<key>Blue Component</key>
53+
<real>0.48627450980392156</real>
54+
<key>Green Component</key>
55+
<real>0.49019607843137253</real>
56+
<key>Red Component</key>
57+
<real>0.5019607843137255</real>
58+
</dict>
59+
<key>Ansi 13 Color</key>
60+
<dict>
61+
<key>Blue Component</key>
62+
<real>0.8313725490196079</real>
63+
<key>Green Component</key>
64+
<real>0.8352941176470589</real>
65+
<key>Red Component</key>
66+
<real>0.8392156862745098</real>
67+
</dict>
68+
<key>Ansi 14 Color</key>
69+
<dict>
70+
<key>Blue Component</key>
71+
<real>0.3254901960784314</real>
72+
<key>Green Component</key>
73+
<real>0.6705882352941176</real>
74+
<key>Red Component</key>
75+
<real>0.803921568627451</real>
76+
</dict>
77+
<key>Ansi 15 Color</key>
78+
<dict>
79+
<key>Blue Component</key>
80+
<real>0.9686274509803922</real>
81+
<key>Green Component</key>
82+
<real>0.9686274509803922</real>
83+
<key>Red Component</key>
84+
<real>0.9686274509803922</real>
85+
</dict>
86+
<key>Ansi 2 Color</key>
87+
<dict>
88+
<key>Blue Component</key>
89+
<real>0.3215686274509804</real>
90+
<key>Green Component</key>
91+
<real>0.6352941176470588</real>
92+
<key>Red Component</key>
93+
<real>0.00392156862745098</real>
94+
</dict>
95+
<key>Ansi 3 Color</key>
96+
<dict>
97+
<key>Blue Component</key>
98+
<real>0.00784313725490196</real>
99+
<key>Green Component</key>
100+
<real>0.9294117647058824</real>
101+
<key>Red Component</key>
102+
<real>0.9921568627450981</real>
103+
</dict>
104+
<key>Ansi 4 Color</key>
105+
<dict>
106+
<key>Blue Component</key>
107+
<real>0.8941176470588236</real>
108+
<key>Green Component</key>
109+
<real>0.6274509803921569</real>
110+
<key>Red Component</key>
111+
<real>0.00392156862745098</real>
112+
</dict>
113+
<key>Ansi 5 Color</key>
114+
<dict>
115+
<key>Blue Component</key>
116+
<real>0.5803921568627451</real>
117+
<key>Green Component</key>
118+
<real>0.41568627450980394</real>
119+
<key>Red Component</key>
120+
<real>0.6313725490196078</real>
121+
</dict>
122+
<key>Ansi 6 Color</key>
123+
<dict>
124+
<key>Blue Component</key>
125+
<real>0.9568627450980393</real>
126+
<key>Green Component</key>
127+
<real>0.8941176470588236</real>
128+
<key>Red Component</key>
129+
<real>0.7098039215686275</real>
130+
</dict>
131+
<key>Ansi 7 Color</key>
132+
<dict>
133+
<key>Blue Component</key>
134+
<real>0.6352941176470588</real>
135+
<key>Green Component</key>
136+
<real>0.6352941176470588</real>
137+
<key>Red Component</key>
138+
<real>0.6470588235294118</real>
139+
</dict>
140+
<key>Ansi 8 Color</key>
141+
<dict>
142+
<key>Blue Component</key>
143+
<real>0.3333333333333333</real>
144+
<key>Green Component</key>
145+
<real>0.34509803921568627</real>
146+
<key>Red Component</key>
147+
<real>0.3607843137254902</real>
148+
</dict>
149+
<key>Ansi 9 Color</key>
150+
<dict>
151+
<key>Blue Component</key>
152+
<real>0.8156862745098039</real>
153+
<key>Green Component</key>
154+
<real>0.7333333333333333</real>
155+
<key>Red Component</key>
156+
<real>0.9098039215686274</real>
157+
</dict>
158+
<key>Background Color</key>
159+
<dict>
160+
<key>Blue Component</key>
161+
<real>0.9686274509803922</real>
162+
<key>Green Component</key>
163+
<real>0.9686274509803922</real>
164+
<key>Red Component</key>
165+
<real>0.9686274509803922</real>
166+
</dict>
167+
<key>Bold Color</key>
168+
<dict>
169+
<key>Blue Component</key>
170+
<real>0.2627450980392157</real>
171+
<key>Green Component</key>
172+
<real>0.27058823529411763</real>
173+
<key>Red Component</key>
174+
<real>0.2901960784313726</real>
175+
</dict>
176+
<key>Cursor Color</key>
177+
<dict>
178+
<key>Blue Component</key>
179+
<real>0.2627450980392157</real>
180+
<key>Green Component</key>
181+
<real>0.27058823529411763</real>
182+
<key>Red Component</key>
183+
<real>0.2901960784313726</real>
184+
</dict>
185+
<key>Cursor Text Color</key>
186+
<dict>
187+
<key>Blue Component</key>
188+
<real>0.9686274509803922</real>
189+
<key>Green Component</key>
190+
<real>0.9686274509803922</real>
191+
<key>Red Component</key>
192+
<real>0.9686274509803922</real>
193+
</dict>
194+
<key>Foreground Color</key>
195+
<dict>
196+
<key>Blue Component</key>
197+
<real>0.2627450980392157</real>
198+
<key>Green Component</key>
199+
<real>0.27058823529411763</real>
200+
<key>Red Component</key>
201+
<real>0.2901960784313726</real>
202+
</dict>
203+
<key>Selected Text Color</key>
204+
<dict>
205+
<key>Blue Component</key>
206+
<real>0.2627450980392157</real>
207+
<key>Green Component</key>
208+
<real>0.27058823529411763</real>
209+
<key>Red Component</key>
210+
<real>0.2901960784313726</real>
211+
</dict>
212+
<key>Selection Color</key>
213+
<dict>
214+
<key>Blue Component</key>
215+
<real>0.6352941176470588</real>
216+
<key>Green Component</key>
217+
<real>0.6352941176470588</real>
218+
<key>Red Component</key>
219+
<real>0.6470588235294118</real>
220+
</dict>
221+
</dict>
222+
</plist>

0 commit comments

Comments
 (0)