sugar-high 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -56,8 +56,8 @@ behavior.
56
56
  ## Built-in languages
57
57
 
58
58
  `javascript`, `typescript`, `css`, `python`, `c`, `go`, `java`, `rust`, `json`, `diff`, `shell`,
59
- `cpp`, `csharp`, `sql`, `html`, `yaml`, `markdown`, `kotlin`, `swift`, `php`, `toml`, `powershell`,
60
- `dockerfile`, `graphql`, and `hcl`.
59
+ `cpp`, `csharp`, `sql`, `html`, `yaml`, `markdown`, `plaintext`, `ruby`, `kotlin`, `swift`, `php`,
60
+ `toml`, `powershell`, `dockerfile`, `graphql`, and `hcl`.
61
61
 
62
62
  Related dialects share one implementation: JavaScript includes JSX, TypeScript includes TSX, JSON
63
63
  includes JSONC comments, Shell includes sh/Bash/Zsh, and HCL includes Terraform.
package/lib/index.d.ts CHANGED
@@ -25,6 +25,8 @@ export type LanguageName =
25
25
  | 'html'
26
26
  | 'yaml'
27
27
  | 'markdown'
28
+ | 'plaintext'
29
+ | 'ruby'
28
30
  | 'kotlin'
29
31
  | 'swift'
30
32
  | 'php'
@@ -0,0 +1 @@
1
+ export function tokenize(code: string): Array<[number, string]>;
@@ -0,0 +1,5 @@
1
+ // @ts-check
2
+ import { T_IDENTIFIER } from '../shared.js'
3
+
4
+ /** @param {string} code */
5
+ export const tokenize = (code) => [[T_IDENTIFIER, code]]
@@ -0,0 +1,13 @@
1
+ export const keywords: Set<string>;
2
+ export function onCommentStart(
3
+ curr: string,
4
+ next: string,
5
+ index: number,
6
+ code: string,
7
+ ): 0 | 1 | 2;
8
+ export function onCommentEnd(
9
+ prev: string,
10
+ curr: string,
11
+ index: number,
12
+ code: string,
13
+ ): 0 | 1 | 2;
@@ -0,0 +1,41 @@
1
+ // @ts-check
2
+
3
+ export const keywords = new Set([
4
+ 'BEGIN', 'END', '__ENCODING__', '__FILE__', '__LINE__', 'alias', 'and', 'begin', 'break',
5
+ 'case', 'class', 'def', 'defined', 'do', 'else', 'elsif', 'end', 'ensure', 'false', 'for', 'if',
6
+ 'in', 'module', 'next', 'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
7
+ 'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield',
8
+ ])
9
+
10
+ /** @param {number} index @param {string} code */
11
+ function isBlockCommentStart(index, code) {
12
+ if (index > 0 && code[index - 1] !== '\n') return false
13
+ return /^=begin(?:\s|$)/.test(code.slice(index))
14
+ }
15
+
16
+ /**
17
+ * @param {string} curr
18
+ * @param {string} _next
19
+ * @param {number} index
20
+ * @param {string} code
21
+ */
22
+ export function onCommentStart(curr, _next, index, code) {
23
+ if (curr === '#') return 1
24
+ if (curr === '=' && isBlockCommentStart(index, code)) return 2
25
+ return 0
26
+ }
27
+
28
+ /**
29
+ * @param {string} _prev
30
+ * @param {string} curr
31
+ * @param {number} index
32
+ * @param {string} code
33
+ */
34
+ export function onCommentEnd(_prev, curr, index, code) {
35
+ if (curr !== '\n') return 0
36
+
37
+ const lineStart = code.lastIndexOf('\n', index - 1) + 1
38
+ const line = code.slice(lineStart, index)
39
+ if (/^=end(?:\s|$)/.test(line)) return 2
40
+ return 1
41
+ }
package/lib/lang.js CHANGED
@@ -16,8 +16,10 @@ import * as javascript from './lang/javascript.js'
16
16
  import * as kotlin from './lang/kotlin.js'
17
17
  import * as markdown from './lang/markdown.js'
18
18
  import * as php from './lang/php.js'
19
+ import * as plaintext from './lang/plaintext.js'
19
20
  import * as powershell from './lang/powershell.js'
20
21
  import * as python from './lang/python.js'
22
+ import * as ruby from './lang/ruby.js'
21
23
  import * as rust from './lang/rust.js'
22
24
  import * as shell from './lang/shell.js'
23
25
  import * as sql from './lang/sql.js'
@@ -69,6 +71,8 @@ const languages = [
69
71
  { id: 'html', extension: 'html', aliases: ['htm', 'xml'], config: html },
70
72
  { id: 'yaml', extension: 'yaml', aliases: ['yml'], config: nonJavaScript(yaml) },
71
73
  { id: 'markdown', extension: 'md', aliases: ['md', 'mdx'], config: nonJavaScript(markdown) },
74
+ { id: 'plaintext', extension: 'txt', aliases: ['text', 'plain'], config: nonJavaScript(plaintext) },
75
+ { id: 'ruby', extension: 'rb', aliases: [], config: nonJavaScript(ruby) },
72
76
  { id: 'kotlin', extension: 'kt', aliases: ['kts'], config: nonJavaScript(kotlin) },
73
77
  { id: 'swift', extension: 'swift', aliases: [], config: nonJavaScript(swift) },
74
78
  { id: 'php', extension: 'php', aliases: [], config: nonJavaScript(php) },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sugar-high",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/huozhi/sugar-high.git",