presently 0.1.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.
- checksums.yaml +7 -0
- data/bin/presently +13 -0
- data/lib/presently/application.rb +104 -0
- data/lib/presently/clock.rb +77 -0
- data/lib/presently/display_view.rb +73 -0
- data/lib/presently/environment/application.rb +62 -0
- data/lib/presently/page.rb +38 -0
- data/lib/presently/page.xrb +31 -0
- data/lib/presently/presentation.rb +72 -0
- data/lib/presently/presentation_controller.rb +181 -0
- data/lib/presently/presenter_view.rb +264 -0
- data/lib/presently/slide.rb +148 -0
- data/lib/presently/slide_view.rb +92 -0
- data/lib/presently/state.rb +66 -0
- data/lib/presently/version.rb +9 -0
- data/lib/presently.rb +9 -0
- data/license.md +21 -0
- data/public/_components/@socketry/syntax/Syntax/CodeElement.js +337 -0
- data/public/_components/@socketry/syntax/Syntax/Errors.js +52 -0
- data/public/_components/@socketry/syntax/Syntax/Language/apache.js +49 -0
- data/public/_components/@socketry/syntax/Syntax/Language/applescript.js +157 -0
- data/public/_components/@socketry/syntax/Syntax/Language/assembly.js +42 -0
- data/public/_components/@socketry/syntax/Syntax/Language/bash-script.js +108 -0
- data/public/_components/@socketry/syntax/Syntax/Language/bash.js +32 -0
- data/public/_components/@socketry/syntax/Syntax/Language/basic.js +232 -0
- data/public/_components/@socketry/syntax/Syntax/Language/c++.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/c.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/clang.js +201 -0
- data/public/_components/@socketry/syntax/Syntax/Language/cpp.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/csharp.js +166 -0
- data/public/_components/@socketry/syntax/Syntax/Language/css.js +244 -0
- data/public/_components/@socketry/syntax/Syntax/Language/diff.js +24 -0
- data/public/_components/@socketry/syntax/Syntax/Language/go.js +135 -0
- data/public/_components/@socketry/syntax/Syntax/Language/haskell.js +110 -0
- data/public/_components/@socketry/syntax/Syntax/Language/html.js +69 -0
- data/public/_components/@socketry/syntax/Syntax/Language/io.js +68 -0
- data/public/_components/@socketry/syntax/Syntax/Language/java.js +134 -0
- data/public/_components/@socketry/syntax/Syntax/Language/javascript.js +89 -0
- data/public/_components/@socketry/syntax/Syntax/Language/json.js +36 -0
- data/public/_components/@socketry/syntax/Syntax/Language/lisp.js +38 -0
- data/public/_components/@socketry/syntax/Syntax/Language/lua.js +87 -0
- data/public/_components/@socketry/syntax/Syntax/Language/markdown.js +112 -0
- data/public/_components/@socketry/syntax/Syntax/Language/nginx.js +37 -0
- data/public/_components/@socketry/syntax/Syntax/Language/objective-c.js +1 -0
- data/public/_components/@socketry/syntax/Syntax/Language/ocaml.js +225 -0
- data/public/_components/@socketry/syntax/Syntax/Language/pascal.js +166 -0
- data/public/_components/@socketry/syntax/Syntax/Language/patch.js +2 -0
- data/public/_components/@socketry/syntax/Syntax/Language/perl5.js +317 -0
- data/public/_components/@socketry/syntax/Syntax/Language/php-script.js +112 -0
- data/public/_components/@socketry/syntax/Syntax/Language/php.js +18 -0
- data/public/_components/@socketry/syntax/Syntax/Language/plain.js +20 -0
- data/public/_components/@socketry/syntax/Syntax/Language/protobuf.js +77 -0
- data/public/_components/@socketry/syntax/Syntax/Language/python.js +208 -0
- data/public/_components/@socketry/syntax/Syntax/Language/ruby.js +124 -0
- data/public/_components/@socketry/syntax/Syntax/Language/scala.js +81 -0
- data/public/_components/@socketry/syntax/Syntax/Language/smalltalk.js +30 -0
- data/public/_components/@socketry/syntax/Syntax/Language/sql.js +865 -0
- data/public/_components/@socketry/syntax/Syntax/Language/super-collider.js +70 -0
- data/public/_components/@socketry/syntax/Syntax/Language/swift.js +176 -0
- data/public/_components/@socketry/syntax/Syntax/Language/xml.js +76 -0
- data/public/_components/@socketry/syntax/Syntax/Language/xrb.js +33 -0
- data/public/_components/@socketry/syntax/Syntax/Language/yaml.js +29 -0
- data/public/_components/@socketry/syntax/Syntax/Language.js +276 -0
- data/public/_components/@socketry/syntax/Syntax/Loader.js +78 -0
- data/public/_components/@socketry/syntax/Syntax/Match.js +546 -0
- data/public/_components/@socketry/syntax/Syntax/Rule.js +306 -0
- data/public/_components/@socketry/syntax/Syntax.js +356 -0
- data/public/_components/@socketry/syntax/bin/syntax-ast.js +42 -0
- data/public/_components/@socketry/syntax/examples/_template.html +53 -0
- data/public/_components/@socketry/syntax/examples/apache.html +72 -0
- data/public/_components/@socketry/syntax/examples/applescript.html +72 -0
- data/public/_components/@socketry/syntax/examples/assembly.html +74 -0
- data/public/_components/@socketry/syntax/examples/bash.html +90 -0
- data/public/_components/@socketry/syntax/examples/basic.html +87 -0
- data/public/_components/@socketry/syntax/examples/c.html +141 -0
- data/public/_components/@socketry/syntax/examples/clang.html +202 -0
- data/public/_components/@socketry/syntax/examples/csharp.html +110 -0
- data/public/_components/@socketry/syntax/examples/css-colors.html +179 -0
- data/public/_components/@socketry/syntax/examples/custom-theme.html +155 -0
- data/public/_components/@socketry/syntax/examples/diff.html +142 -0
- data/public/_components/@socketry/syntax/examples/examples.css +216 -0
- data/public/_components/@socketry/syntax/examples/go.html +413 -0
- data/public/_components/@socketry/syntax/examples/haskell.html +373 -0
- data/public/_components/@socketry/syntax/examples/html.html +316 -0
- data/public/_components/@socketry/syntax/examples/index.html +97 -0
- data/public/_components/@socketry/syntax/examples/io.html +552 -0
- data/public/_components/@socketry/syntax/examples/java.html +786 -0
- data/public/_components/@socketry/syntax/examples/javascript.html +199 -0
- data/public/_components/@socketry/syntax/examples/json.html +150 -0
- data/public/_components/@socketry/syntax/examples/lisp.html +476 -0
- data/public/_components/@socketry/syntax/examples/lua.html +737 -0
- data/public/_components/@socketry/syntax/examples/markdown.html +121 -0
- data/public/_components/@socketry/syntax/examples/mixed.html +306 -0
- data/public/_components/@socketry/syntax/examples/nginx.html +554 -0
- data/public/_components/@socketry/syntax/examples/ocaml.html +596 -0
- data/public/_components/@socketry/syntax/examples/pascal.html +762 -0
- data/public/_components/@socketry/syntax/examples/perl5.html +488 -0
- data/public/_components/@socketry/syntax/examples/php-script.html +142 -0
- data/public/_components/@socketry/syntax/examples/php.html +95 -0
- data/public/_components/@socketry/syntax/examples/plain.html +222 -0
- data/public/_components/@socketry/syntax/examples/protobuf.html +405 -0
- data/public/_components/@socketry/syntax/examples/python.html +82 -0
- data/public/_components/@socketry/syntax/examples/readme.md +79 -0
- data/public/_components/@socketry/syntax/examples/ruby.html +58 -0
- data/public/_components/@socketry/syntax/examples/scala.html +41 -0
- data/public/_components/@socketry/syntax/examples/smalltalk.html +436 -0
- data/public/_components/@socketry/syntax/examples/sql.html +373 -0
- data/public/_components/@socketry/syntax/examples/super-collider.html +55 -0
- data/public/_components/@socketry/syntax/examples/swift.html +176 -0
- data/public/_components/@socketry/syntax/examples/wrap-demo.html +103 -0
- data/public/_components/@socketry/syntax/examples/xml.html +112 -0
- data/public/_components/@socketry/syntax/examples/xrb.html +37 -0
- data/public/_components/@socketry/syntax/examples/yaml.html +72 -0
- data/public/_components/@socketry/syntax/license.md +21 -0
- data/public/_components/@socketry/syntax/package-lock.json +834 -0
- data/public/_components/@socketry/syntax/package.json +43 -0
- data/public/_components/@socketry/syntax/readme.md +162 -0
- data/public/_components/@socketry/syntax/test/Syntax/CodeElement.js +306 -0
- data/public/_components/@socketry/syntax/test/Syntax/ErrorHandling.js +85 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/apache.js +153 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/applescript.js +198 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/assembly.js +209 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/bash-script.js +225 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/bash.js +162 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/basic.js +265 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/clang.js +390 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/csharp.js +436 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/css.js +431 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/diff.js +206 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/go.js +386 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/haskell.js +454 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/html.js +111 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/io.js +229 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/java.js +362 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/javascript.js +101 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/json.js +101 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/lisp.js +224 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/lua.js +307 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/markdown.js +163 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/nginx.js +267 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/ocaml.js +299 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/pascal.js +311 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/perl5.js +333 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/php-script.js +197 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/php.js +92 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/plain.js +327 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/protobuf.js +294 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/python.js +213 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/ruby.js +70 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/scala.js +75 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/smalltalk.js +223 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/sql.js +281 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/super-collider.js +66 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/swift.js +71 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/xml.js +170 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/xrb.js +57 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language/yaml.js +123 -0
- data/public/_components/@socketry/syntax/test/Syntax/Language.js +62 -0
- data/public/_components/@socketry/syntax/test/Syntax/Match.js +40 -0
- data/public/_components/@socketry/syntax/test/Syntax/Rule.js +251 -0
- data/public/_components/@socketry/syntax/test/Syntax.js +38 -0
- data/public/_components/@socketry/syntax/test/helpers/ast-matcher.js +90 -0
- data/public/_components/@socketry/syntax/themes/base/apache.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/applescript.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/assembly.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/bash.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/basic.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/c.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/clang.css +0 -0
- data/public/_components/@socketry/syntax/themes/base/csharp.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/css.css +22 -0
- data/public/_components/@socketry/syntax/themes/base/diff.css +48 -0
- data/public/_components/@socketry/syntax/themes/base/go.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/haskell.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/html.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/io.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/java.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/javascript.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/json.css +41 -0
- data/public/_components/@socketry/syntax/themes/base/lisp.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/lua.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/markdown.css +16 -0
- data/public/_components/@socketry/syntax/themes/base/nginx.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/ocaml.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/pascal.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/perl5.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/php-script.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/php.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/plain.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/protobuf.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/python.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/ruby.css +23 -0
- data/public/_components/@socketry/syntax/themes/base/scala.css +3 -0
- data/public/_components/@socketry/syntax/themes/base/smalltalk.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/sql.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/super-collider.css +33 -0
- data/public/_components/@socketry/syntax/themes/base/swift.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/syntax.css +63 -0
- data/public/_components/@socketry/syntax/themes/base/xml.css +1 -0
- data/public/_components/@socketry/syntax/themes/base/xrb.css +29 -0
- data/public/_components/@socketry/syntax/themes/base/yaml.css +1 -0
- data/public/_components/@socketry/syntax/themes/theming.md +233 -0
- data/public/_components/@socketry/syntax/update-examples.js +135 -0
- data/public/_static/index.css +593 -0
- data/public/application.js +147 -0
- data/readme.md +69 -0
- data/releases.md +3 -0
- data/templates/code.xrb +12 -0
- data/templates/default.xrb +5 -0
- data/templates/image.xrb +8 -0
- data/templates/section.xrb +5 -0
- data/templates/title.xrb +8 -0
- data/templates/translation.xrb +8 -0
- data/templates/two_column.xrb +8 -0
- metadata +280 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Markdown language definition
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {test} from 'node:test';
|
|
6
|
+
import assert from 'node:assert';
|
|
7
|
+
import {JSDOM} from 'jsdom';
|
|
8
|
+
|
|
9
|
+
// Setup DOM environment
|
|
10
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
|
|
11
|
+
global.document = dom.window.document;
|
|
12
|
+
|
|
13
|
+
import Syntax from '../../../Syntax.js';
|
|
14
|
+
import registerMarkdown from '../../../Syntax/Language/markdown.js';
|
|
15
|
+
import {
|
|
16
|
+
assertToken,
|
|
17
|
+
assertTokenType,
|
|
18
|
+
assertTokenCount,
|
|
19
|
+
getMatchText
|
|
20
|
+
} from '../../helpers/ast-matcher.js';
|
|
21
|
+
|
|
22
|
+
test('Markdown language can be registered', async () => {
|
|
23
|
+
const syntax = new Syntax();
|
|
24
|
+
registerMarkdown(syntax);
|
|
25
|
+
const language = await syntax.getLanguage('markdown');
|
|
26
|
+
assert.ok(language);
|
|
27
|
+
assert.strictEqual(language.name, 'markdown');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('Markdown can match headers', async () => {
|
|
31
|
+
const syntax = new Syntax();
|
|
32
|
+
registerMarkdown(syntax);
|
|
33
|
+
const language = await syntax.getLanguage('markdown');
|
|
34
|
+
|
|
35
|
+
const code = '# Heading 1';
|
|
36
|
+
const matches = await language.getMatches(syntax, code);
|
|
37
|
+
|
|
38
|
+
assertToken(code, matches, 'heading', '# Heading 1');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('Markdown can match bold text', async () => {
|
|
42
|
+
const syntax = new Syntax();
|
|
43
|
+
registerMarkdown(syntax);
|
|
44
|
+
const language = await syntax.getLanguage('markdown');
|
|
45
|
+
|
|
46
|
+
const code = '**bold text**';
|
|
47
|
+
const matches = await language.getMatches(syntax, code);
|
|
48
|
+
|
|
49
|
+
assertToken(code, matches, 'strong', '**bold text**');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('Markdown can match italic text', async () => {
|
|
53
|
+
const syntax = new Syntax();
|
|
54
|
+
registerMarkdown(syntax);
|
|
55
|
+
const language = await syntax.getLanguage('markdown');
|
|
56
|
+
|
|
57
|
+
const code = '*italic text*';
|
|
58
|
+
const matches = await language.getMatches(syntax, code);
|
|
59
|
+
|
|
60
|
+
assertToken(code, matches, 'emphasis', '*italic text*');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('Markdown can match inline code', async () => {
|
|
64
|
+
const syntax = new Syntax();
|
|
65
|
+
registerMarkdown(syntax);
|
|
66
|
+
const language = await syntax.getLanguage('markdown');
|
|
67
|
+
|
|
68
|
+
const code = '`code here`';
|
|
69
|
+
const matches = await language.getMatches(syntax, code);
|
|
70
|
+
|
|
71
|
+
assertToken(code, matches, 'code', '`code here`');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('Markdown can match code blocks', async () => {
|
|
75
|
+
const syntax = new Syntax();
|
|
76
|
+
registerMarkdown(syntax);
|
|
77
|
+
const language = await syntax.getLanguage('markdown');
|
|
78
|
+
|
|
79
|
+
const code = '```javascript\nconst x = 1;\n```';
|
|
80
|
+
const matches = await language.getMatches(syntax, code);
|
|
81
|
+
|
|
82
|
+
assertToken(code, matches, 'code', '```javascript\nconst x = 1;\n```');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('Markdown can match links', async () => {
|
|
86
|
+
const syntax = new Syntax();
|
|
87
|
+
registerMarkdown(syntax);
|
|
88
|
+
const language = await syntax.getLanguage('markdown');
|
|
89
|
+
|
|
90
|
+
const code = '[text](http://example.com)';
|
|
91
|
+
const matches = await language.getMatches(syntax, code);
|
|
92
|
+
|
|
93
|
+
// Should match the link text and URL as separate tokens
|
|
94
|
+
assertToken(code, matches, 'string', 'text');
|
|
95
|
+
assertToken(code, matches, 'link', 'http://example.com');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('Markdown can match images', async () => {
|
|
99
|
+
const syntax = new Syntax();
|
|
100
|
+
registerMarkdown(syntax);
|
|
101
|
+
const language = await syntax.getLanguage('markdown');
|
|
102
|
+
|
|
103
|
+
const code = '';
|
|
104
|
+
const matches = await language.getMatches(syntax, code);
|
|
105
|
+
|
|
106
|
+
assertToken(code, matches, 'link', '');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('Markdown can match blockquotes', async () => {
|
|
110
|
+
const syntax = new Syntax();
|
|
111
|
+
registerMarkdown(syntax);
|
|
112
|
+
const language = await syntax.getLanguage('markdown');
|
|
113
|
+
|
|
114
|
+
const code = '> This is a quote';
|
|
115
|
+
const matches = await language.getMatches(syntax, code);
|
|
116
|
+
|
|
117
|
+
assertToken(code, matches, 'quote', '> This is a quote');
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test('Markdown can match unordered lists', async () => {
|
|
121
|
+
const syntax = new Syntax();
|
|
122
|
+
registerMarkdown(syntax);
|
|
123
|
+
const language = await syntax.getLanguage('markdown');
|
|
124
|
+
|
|
125
|
+
const code = '- List item';
|
|
126
|
+
const matches = await language.getMatches(syntax, code);
|
|
127
|
+
|
|
128
|
+
assertToken(code, matches, 'list-marker', '- ');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('Markdown can match ordered lists', async () => {
|
|
132
|
+
const syntax = new Syntax();
|
|
133
|
+
registerMarkdown(syntax);
|
|
134
|
+
const language = await syntax.getLanguage('markdown');
|
|
135
|
+
|
|
136
|
+
const code = '1. List item';
|
|
137
|
+
const matches = await language.getMatches(syntax, code);
|
|
138
|
+
|
|
139
|
+
assertToken(code, matches, 'list-marker', '1. ');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test('Markdown: fenced block followed by inline code does not merge', async () => {
|
|
143
|
+
const syntax = new Syntax();
|
|
144
|
+
registerMarkdown(syntax);
|
|
145
|
+
const language = await syntax.getLanguage('markdown');
|
|
146
|
+
|
|
147
|
+
const code = "```\nfoo\n```\n\n`project`";
|
|
148
|
+
const matches = await language.getMatches(syntax, code);
|
|
149
|
+
|
|
150
|
+
// Expect a fenced code block token:
|
|
151
|
+
assertToken(code, matches, 'code', '```\nfoo\n```');
|
|
152
|
+
|
|
153
|
+
// Expect a separate inline code token for `project`:
|
|
154
|
+
assertToken(code, matches, 'code', '`project`');
|
|
155
|
+
|
|
156
|
+
// Ensure there is no token that incorrectly spans the fence backticks
|
|
157
|
+
// and the following inline backtick (e.g., "````" boundary merge):
|
|
158
|
+
const badSpan = matches.find(m =>
|
|
159
|
+
m.type === 'code' &&
|
|
160
|
+
code.substring(m.offset, m.offset + m.length).includes('````')
|
|
161
|
+
);
|
|
162
|
+
assert.strictEqual(badSpan, undefined);
|
|
163
|
+
});
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Nginx configuration syntax highlighting
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {test} from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import {JSDOM} from 'jsdom';
|
|
8
|
+
import Syntax from '../../../Syntax.js';
|
|
9
|
+
|
|
10
|
+
const dom = new JSDOM('<!DOCTYPE html><html><body></body></html>');
|
|
11
|
+
global.window = dom.window;
|
|
12
|
+
global.document = dom.window.document;
|
|
13
|
+
global.HTMLElement = dom.window.HTMLElement;
|
|
14
|
+
global.customElements = dom.window.customElements;
|
|
15
|
+
|
|
16
|
+
const syntax = new Syntax();
|
|
17
|
+
|
|
18
|
+
test('Nginx language can be registered', async () => {
|
|
19
|
+
const language = await syntax.getResource('nginx');
|
|
20
|
+
assert.ok(language);
|
|
21
|
+
assert.equal(language.name, 'nginx');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('nginx: directive matches simple directives', async () => {
|
|
25
|
+
const language = await syntax.getResource('nginx');
|
|
26
|
+
const matches = await language.getMatches(syntax, 'listen 80;');
|
|
27
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
28
|
+
assert.ok(directives.length > 0);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('nginx: directive matches directives with parameters', async () => {
|
|
32
|
+
const language = await syntax.getResource('nginx');
|
|
33
|
+
const matches = await language.getMatches(syntax, 'server_name example.com;');
|
|
34
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
35
|
+
assert.ok(directives.length > 0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('nginx: directive matches root directive', async () => {
|
|
39
|
+
const language = await syntax.getResource('nginx');
|
|
40
|
+
const matches = await language.getMatches(syntax, 'root /var/www/html;');
|
|
41
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
42
|
+
assert.ok(directives.length > 0);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('nginx: directive matches index directive', async () => {
|
|
46
|
+
const language = await syntax.getResource('nginx');
|
|
47
|
+
const matches = await language.getMatches(
|
|
48
|
+
syntax,
|
|
49
|
+
'index index.html index.htm;'
|
|
50
|
+
);
|
|
51
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
52
|
+
assert.ok(directives.length > 0);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('nginx: directive matches access_log directive', async () => {
|
|
56
|
+
const language = await syntax.getResource('nginx');
|
|
57
|
+
const matches = await language.getMatches(
|
|
58
|
+
syntax,
|
|
59
|
+
'access_log /var/log/nginx/access.log;'
|
|
60
|
+
);
|
|
61
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
62
|
+
assert.ok(directives.length > 0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('nginx: function matches directive name with web link', async () => {
|
|
66
|
+
const language = await syntax.getResource('nginx');
|
|
67
|
+
const matches = await language.getMatches(syntax, 'listen 80;');
|
|
68
|
+
const functions = matches.filter(m => m.type === 'function');
|
|
69
|
+
assert.ok(functions.length > 0);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('nginx: keyword matches server block', async () => {
|
|
73
|
+
const language = await syntax.getResource('nginx');
|
|
74
|
+
const matches = await language.getMatches(syntax, 'server {');
|
|
75
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
76
|
+
assert.ok(keywords.some(m => m.value === 'server'));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('nginx: keyword matches http block', async () => {
|
|
80
|
+
const language = await syntax.getResource('nginx');
|
|
81
|
+
const matches = await language.getMatches(syntax, 'http {');
|
|
82
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
83
|
+
assert.ok(keywords.some(m => m.value === 'http'));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('nginx: keyword matches location block', async () => {
|
|
87
|
+
const language = await syntax.getResource('nginx');
|
|
88
|
+
const matches = await language.getMatches(syntax, 'location / {');
|
|
89
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
90
|
+
assert.ok(keywords.some(m => m.value === 'location'));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('nginx: keyword matches upstream block', async () => {
|
|
94
|
+
const language = await syntax.getResource('nginx');
|
|
95
|
+
const matches = await language.getMatches(syntax, 'upstream backend {');
|
|
96
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
97
|
+
assert.ok(keywords.some(m => m.value === 'upstream'));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('nginx: keyword matches events block', async () => {
|
|
101
|
+
const language = await syntax.getResource('nginx');
|
|
102
|
+
const matches = await language.getMatches(syntax, 'events {');
|
|
103
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
104
|
+
assert.ok(keywords.some(m => m.value === 'events'));
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('nginx: variable matches simple variable', async () => {
|
|
108
|
+
const language = await syntax.getResource('nginx');
|
|
109
|
+
const matches = await language.getMatches(syntax, '$host');
|
|
110
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
111
|
+
assert.ok(variables.some(m => m.value.includes('host')));
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('nginx: variable matches request_uri variable', async () => {
|
|
115
|
+
const language = await syntax.getResource('nginx');
|
|
116
|
+
const matches = await language.getMatches(syntax, '$request_uri');
|
|
117
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
118
|
+
assert.ok(variables.length > 0);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('nginx: variable matches remote_addr variable', async () => {
|
|
122
|
+
const language = await syntax.getResource('nginx');
|
|
123
|
+
const matches = await language.getMatches(syntax, '$remote_addr');
|
|
124
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
125
|
+
assert.ok(variables.length > 0);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('nginx: variable matches http_user_agent variable', async () => {
|
|
129
|
+
const language = await syntax.getResource('nginx');
|
|
130
|
+
const matches = await language.getMatches(syntax, '$http_user_agent');
|
|
131
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
132
|
+
assert.ok(variables.length > 0);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('nginx: variable matches in directive', async () => {
|
|
136
|
+
const language = await syntax.getResource('nginx');
|
|
137
|
+
const matches = await language.getMatches(
|
|
138
|
+
syntax,
|
|
139
|
+
'return 301 https://$host$request_uri;'
|
|
140
|
+
);
|
|
141
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
142
|
+
assert.ok(variables.length > 0);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('nginx: perlStyleComment matches hash comments', async () => {
|
|
146
|
+
const language = await syntax.getResource('nginx');
|
|
147
|
+
const matches = await language.getMatches(syntax, '# This is a comment');
|
|
148
|
+
const comments = matches.filter(m => m.type === 'comment');
|
|
149
|
+
assert.ok(comments.length > 0);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('nginx: singleQuotedString matches single-quoted strings', async () => {
|
|
153
|
+
const language = await syntax.getResource('nginx');
|
|
154
|
+
const matches = await language.getMatches(syntax, "'text/html'");
|
|
155
|
+
const strings = matches.filter(m => m.type === 'string');
|
|
156
|
+
assert.ok(strings.length > 0);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('nginx: doubleQuotedString matches double-quoted strings', async () => {
|
|
160
|
+
const language = await syntax.getResource('nginx');
|
|
161
|
+
const matches = await language.getMatches(syntax, '"application/json"');
|
|
162
|
+
const strings = matches.filter(m => m.type === 'string');
|
|
163
|
+
assert.ok(strings.length > 0);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('nginx: complete server block', async () => {
|
|
167
|
+
const code = `server {
|
|
168
|
+
listen 80;
|
|
169
|
+
server_name example.com;
|
|
170
|
+
root /var/www/html;
|
|
171
|
+
}`;
|
|
172
|
+
const language = await syntax.getResource('nginx');
|
|
173
|
+
const matches = await language.getMatches(syntax, code);
|
|
174
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
175
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
176
|
+
assert.ok(keywords.length > 0);
|
|
177
|
+
assert.ok(directives.length > 0);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test('nginx: location block with proxy_pass', async () => {
|
|
181
|
+
const code = `location / {
|
|
182
|
+
proxy_pass http://backend;
|
|
183
|
+
}`;
|
|
184
|
+
const language = await syntax.getResource('nginx');
|
|
185
|
+
const matches = await language.getMatches(syntax, code);
|
|
186
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
187
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
188
|
+
assert.ok(keywords.length > 0);
|
|
189
|
+
assert.ok(directives.length > 0);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
test('nginx: rewrite directive with regex', async () => {
|
|
193
|
+
const language = await syntax.getResource('nginx');
|
|
194
|
+
const matches = await language.getMatches(
|
|
195
|
+
syntax,
|
|
196
|
+
'rewrite ^/old-path(.*)$ /new-path$1 permanent;'
|
|
197
|
+
);
|
|
198
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
199
|
+
assert.ok(directives.length > 0);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('nginx: ssl directives', async () => {
|
|
203
|
+
const code = `ssl_certificate /etc/nginx/ssl/cert.pem;
|
|
204
|
+
ssl_certificate_key /etc/nginx/ssl/key.pem;`;
|
|
205
|
+
const language = await syntax.getResource('nginx');
|
|
206
|
+
const matches = await language.getMatches(syntax, code);
|
|
207
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
208
|
+
assert.ok(directives.length > 0);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('nginx: gzip directives', async () => {
|
|
212
|
+
const code = `gzip on;
|
|
213
|
+
gzip_types text/plain text/css application/json;`;
|
|
214
|
+
const language = await syntax.getResource('nginx');
|
|
215
|
+
const matches = await language.getMatches(syntax, code);
|
|
216
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
217
|
+
assert.ok(directives.length > 0);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('nginx: upstream with servers', async () => {
|
|
221
|
+
const code = `upstream backend {
|
|
222
|
+
server 127.0.0.1:8080;
|
|
223
|
+
server 127.0.0.1:8081;
|
|
224
|
+
}`;
|
|
225
|
+
const language = await syntax.getResource('nginx');
|
|
226
|
+
const matches = await language.getMatches(syntax, code);
|
|
227
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
228
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
229
|
+
assert.ok(keywords.length > 0);
|
|
230
|
+
assert.ok(directives.length > 0);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
test('nginx: add_header directive', async () => {
|
|
234
|
+
const language = await syntax.getResource('nginx');
|
|
235
|
+
const matches = await language.getMatches(
|
|
236
|
+
syntax,
|
|
237
|
+
'add_header X-Frame-Options "SAMEORIGIN";'
|
|
238
|
+
);
|
|
239
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
240
|
+
const strings = matches.filter(m => m.type === 'string');
|
|
241
|
+
assert.ok(directives.length > 0);
|
|
242
|
+
assert.ok(strings.length > 0);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
test('nginx: try_files directive', async () => {
|
|
246
|
+
const language = await syntax.getResource('nginx');
|
|
247
|
+
const matches = await language.getMatches(
|
|
248
|
+
syntax,
|
|
249
|
+
'try_files $uri $uri/ /index.html;'
|
|
250
|
+
);
|
|
251
|
+
const directives = matches.filter(m => m.type === 'directive');
|
|
252
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
253
|
+
assert.ok(directives.length > 0);
|
|
254
|
+
assert.ok(variables.length > 0);
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test('nginx: if directive with condition', async () => {
|
|
258
|
+
const code = `if ($request_method = POST) {
|
|
259
|
+
return 405;
|
|
260
|
+
}`;
|
|
261
|
+
const language = await syntax.getResource('nginx');
|
|
262
|
+
const matches = await language.getMatches(syntax, code);
|
|
263
|
+
const keywords = matches.filter(m => m.type === 'keyword');
|
|
264
|
+
const variables = matches.filter(m => m.type === 'variable');
|
|
265
|
+
assert.ok(keywords.length > 0);
|
|
266
|
+
assert.ok(variables.length > 0);
|
|
267
|
+
});
|