utopia-project 0.37.6 → 0.38.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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/context/documentation-guidelines.md +12 -7
  4. data/lib/utopia/project/import_map.rb +1 -0
  5. data/lib/utopia/project/version.rb +1 -1
  6. data/pages/_page.xnode +8 -13
  7. data/public/_components/@socketry/syntax/Syntax/CodeElement.js +293 -0
  8. data/public/_components/@socketry/syntax/Syntax/Errors.js +52 -0
  9. data/public/_components/@socketry/syntax/Syntax/Language/apache.js +49 -0
  10. data/public/_components/@socketry/syntax/Syntax/Language/applescript.js +157 -0
  11. data/public/_components/@socketry/syntax/Syntax/Language/assembly.js +42 -0
  12. data/public/_components/@socketry/syntax/Syntax/Language/bash-script.js +108 -0
  13. data/public/_components/@socketry/syntax/Syntax/Language/bash.js +32 -0
  14. data/public/_components/@socketry/syntax/Syntax/Language/basic.js +232 -0
  15. data/public/_components/@socketry/syntax/Syntax/Language/c++.js +1 -0
  16. data/public/_components/@socketry/syntax/Syntax/Language/c.js +1 -0
  17. data/public/_components/@socketry/syntax/Syntax/Language/clang.js +201 -0
  18. data/public/_components/@socketry/syntax/Syntax/Language/cpp.js +1 -0
  19. data/public/_components/@socketry/syntax/Syntax/Language/csharp.js +166 -0
  20. data/public/_components/@socketry/syntax/Syntax/Language/css.js +244 -0
  21. data/public/_components/@socketry/syntax/Syntax/Language/diff.js +24 -0
  22. data/public/_components/@socketry/syntax/Syntax/Language/go.js +135 -0
  23. data/public/_components/@socketry/syntax/Syntax/Language/haskell.js +110 -0
  24. data/public/_components/@socketry/syntax/Syntax/Language/html.js +69 -0
  25. data/public/_components/@socketry/syntax/Syntax/Language/io.js +68 -0
  26. data/public/_components/@socketry/syntax/Syntax/Language/java.js +134 -0
  27. data/public/_components/@socketry/syntax/Syntax/Language/javascript.js +89 -0
  28. data/public/_components/@socketry/syntax/Syntax/Language/json.js +36 -0
  29. data/public/_components/@socketry/syntax/Syntax/Language/lisp.js +38 -0
  30. data/public/_components/@socketry/syntax/Syntax/Language/lua.js +87 -0
  31. data/public/_components/@socketry/syntax/Syntax/Language/markdown.js +112 -0
  32. data/public/_components/@socketry/syntax/Syntax/Language/nginx.js +37 -0
  33. data/public/_components/@socketry/syntax/Syntax/Language/objective-c.js +1 -0
  34. data/public/_components/@socketry/syntax/Syntax/Language/ocaml.js +225 -0
  35. data/public/_components/@socketry/syntax/Syntax/Language/pascal.js +166 -0
  36. data/public/_components/@socketry/syntax/Syntax/Language/patch.js +2 -0
  37. data/public/_components/@socketry/syntax/Syntax/Language/perl5.js +317 -0
  38. data/public/_components/@socketry/syntax/Syntax/Language/php-script.js +112 -0
  39. data/public/_components/@socketry/syntax/Syntax/Language/php.js +18 -0
  40. data/public/_components/@socketry/syntax/Syntax/Language/plain.js +20 -0
  41. data/public/_components/@socketry/syntax/Syntax/Language/protobuf.js +77 -0
  42. data/public/_components/@socketry/syntax/Syntax/Language/python.js +208 -0
  43. data/public/_components/@socketry/syntax/Syntax/Language/ruby.js +124 -0
  44. data/public/_components/@socketry/syntax/Syntax/Language/scala.js +81 -0
  45. data/public/_components/@socketry/syntax/Syntax/Language/smalltalk.js +30 -0
  46. data/public/_components/@socketry/syntax/Syntax/Language/sql.js +865 -0
  47. data/public/_components/@socketry/syntax/Syntax/Language/super-collider.js +70 -0
  48. data/public/_components/@socketry/syntax/Syntax/Language/swift.js +176 -0
  49. data/public/_components/@socketry/syntax/Syntax/Language/xml.js +76 -0
  50. data/public/_components/@socketry/syntax/Syntax/Language/xrb.js +33 -0
  51. data/public/_components/@socketry/syntax/Syntax/Language/yaml.js +29 -0
  52. data/public/_components/@socketry/syntax/Syntax/Language.js +276 -0
  53. data/public/_components/@socketry/syntax/Syntax/Loader.js +78 -0
  54. data/public/_components/@socketry/syntax/Syntax/Match.js +546 -0
  55. data/public/_components/@socketry/syntax/Syntax/Rule.js +306 -0
  56. data/public/_components/@socketry/syntax/Syntax.js +356 -0
  57. data/public/_components/@socketry/syntax/license.md +21 -0
  58. data/public/_components/@socketry/syntax/package.json +43 -0
  59. data/public/_components/@socketry/syntax/readme.md +162 -0
  60. data/public/_components/@socketry/syntax/themes/base/apache.css +1 -0
  61. data/public/_components/@socketry/syntax/themes/base/applescript.css +1 -0
  62. data/public/_components/@socketry/syntax/themes/base/assembly.css +1 -0
  63. data/public/_components/@socketry/syntax/themes/base/bash.css +1 -0
  64. data/public/_components/@socketry/syntax/themes/base/basic.css +1 -0
  65. data/public/_components/@socketry/syntax/themes/base/c.css +1 -0
  66. data/public/_components/@socketry/syntax/themes/base/clang.css +0 -0
  67. data/public/_components/@socketry/syntax/themes/base/csharp.css +1 -0
  68. data/public/_components/@socketry/syntax/themes/base/css.css +22 -0
  69. data/public/_components/@socketry/syntax/themes/base/diff.css +48 -0
  70. data/public/_components/@socketry/syntax/themes/base/go.css +1 -0
  71. data/public/_components/@socketry/syntax/themes/base/haskell.css +1 -0
  72. data/public/_components/@socketry/syntax/themes/base/html.css +1 -0
  73. data/public/_components/@socketry/syntax/themes/base/io.css +1 -0
  74. data/public/_components/@socketry/syntax/themes/base/java.css +1 -0
  75. data/public/_components/@socketry/syntax/themes/base/javascript.css +1 -0
  76. data/public/_components/@socketry/syntax/themes/base/json.css +41 -0
  77. data/public/_components/@socketry/syntax/themes/base/lisp.css +1 -0
  78. data/public/_components/@socketry/syntax/themes/base/lua.css +1 -0
  79. data/public/_components/@socketry/syntax/themes/base/markdown.css +16 -0
  80. data/public/_components/@socketry/syntax/themes/base/nginx.css +1 -0
  81. data/public/_components/@socketry/syntax/themes/base/ocaml.css +1 -0
  82. data/public/_components/@socketry/syntax/themes/base/pascal.css +1 -0
  83. data/public/_components/@socketry/syntax/themes/base/perl5.css +1 -0
  84. data/public/_components/@socketry/syntax/themes/base/php-script.css +1 -0
  85. data/public/_components/@socketry/syntax/themes/base/php.css +1 -0
  86. data/public/_components/@socketry/syntax/themes/base/plain.css +1 -0
  87. data/public/_components/@socketry/syntax/themes/base/protobuf.css +1 -0
  88. data/public/_components/@socketry/syntax/themes/base/python.css +1 -0
  89. data/public/_components/@socketry/syntax/themes/base/ruby.css +23 -0
  90. data/public/_components/@socketry/syntax/themes/base/scala.css +3 -0
  91. data/public/_components/@socketry/syntax/themes/base/smalltalk.css +1 -0
  92. data/public/_components/@socketry/syntax/themes/base/sql.css +1 -0
  93. data/public/_components/@socketry/syntax/themes/base/super-collider.css +33 -0
  94. data/public/_components/@socketry/syntax/themes/base/swift.css +1 -0
  95. data/public/_components/@socketry/syntax/themes/base/syntax.css +63 -0
  96. data/public/_components/@socketry/syntax/themes/base/xml.css +1 -0
  97. data/public/_components/@socketry/syntax/themes/base/xrb.css +29 -0
  98. data/public/_components/@socketry/syntax/themes/base/yaml.css +1 -0
  99. data/public/_components/@socketry/syntax/themes/theming.md +233 -0
  100. data/public/_static/sidebar.js +55 -22
  101. data/public/_static/site.css +0 -4
  102. data.tar.gz.sig +0 -0
  103. metadata +94 -1
  104. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b346c378a8a6bfc3886f286a9ed7a272980a5f10079220217c569f97ca106e65
4
- data.tar.gz: a71630176c80d071004d6c268927b45d7fc4df9c5f897576dedec7df865142fd
3
+ metadata.gz: 00ba83cfcaea0e83dbd4e927e4ed1483fa7079c94b56c9a480616a421b04fcaa
4
+ data.tar.gz: 48b8ceb3698e82e2d3f460f53f5e085540251c4e054abe0ff0560133de2d5d40
5
5
  SHA512:
6
- metadata.gz: bf9edae394344d8e134a878c69763904931da1997b0b1da656d81c6a86ef01c0b8eabe20b62b27f07d59930e6126c96dc34a80168c71943ab2c27935ada1b8fa
7
- data.tar.gz: 516c3bbd85608535f40171f423d110f785830260f0915d3d097610968167f892c1195ecb16cdf1c111a77d9c19015cb7d2b38e4661c3e256d32d9fcb895510de
6
+ metadata.gz: e59af3ae609bd5d28aafaaf9af6d7d50acb365e625986b8983277fe71d0615afb95552f32b24d27c586c15417c4e1e376db1353968d116b8dedf7c919b0e8286
7
+ data.tar.gz: 6e3652aa2c16b3406afb0c8ab4cb47d2f259ad5b2c15e4c368c50d6df6214e60c79e3c11ca4d592f54e4b5332dd30fe3d8f3876f9ff4fee34ecc961a9548f7b5
checksums.yaml.gz.sig CHANGED
Binary file
@@ -73,11 +73,12 @@ Every feature or concept should be introduced with clear context about why users
73
73
  1. **Problem statement**: What challenge does this solve?
74
74
  2. **Use cases**: When would users encounter this need?
75
75
  3. **Solution overview**: How does this feature address the problem?
76
- 4. **Implementation**: Code examples and detailed usage
76
+ 4. **Implementation**: Code examples and detailed usage.
77
77
 
78
- **Example:**
78
+ #### Example
79
+
80
+ ❌ Poor context:
79
81
 
80
- ❌ **Poor context**:
81
82
  ~~~markdown
82
83
  ## Transactions
83
84
 
@@ -90,7 +91,8 @@ client.exec
90
91
  ```
91
92
  ~~~
92
93
 
93
- **Good context**:
94
+ ✅ Good context:
95
+
94
96
  ~~~markdown
95
97
  ## Transactions
96
98
 
@@ -127,7 +129,8 @@ When documenting advanced features, follow this structure:
127
129
  4. **Best Practices**: When to use vs when not to use
128
130
  5. **Common Pitfalls**: What to watch out for
129
131
 
130
- **Template:**
132
+ #### Template
133
+
131
134
  ```markdown
132
135
  ## [Feature Name]
133
136
 
@@ -234,13 +237,15 @@ Help users understand when to choose between alternatives:
234
237
 
235
238
  Every code example should demonstrate a realistic scenario, not abstract operations:
236
239
 
237
- **Abstract**:
240
+ ❌ Abstract:
241
+
238
242
  ```ruby
239
243
  client.set("key", "value")
240
244
  client.get("key")
241
245
  ```
242
246
 
243
- **Contextual**:
247
+ ✅ Contextual:
248
+
244
249
  ```ruby
245
250
  # Store user session data:
246
251
  client.set("session:#{session_id}", user_data.to_json)
@@ -4,6 +4,7 @@ module Utopia
4
4
  module Project
5
5
  IMPORT_MAP = Utopia::ImportMap.build(base: "/_components/") do |map|
6
6
  map.import("mermaid", "./mermaid/mermaid.esm.min.mjs")
7
+ map.import("@socketry/syntax", "./@socketry/syntax/Syntax.js")
7
8
  end
8
9
  end
9
10
  end
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Utopia
7
7
  module Project
8
- VERSION = "0.37.6"
8
+ VERSION = "0.38.0"
9
9
  end
10
10
  end
data/pages/_page.xnode CHANGED
@@ -15,23 +15,19 @@
15
15
  <link rel="icon" type="image/png" href="/_static/icon.png" />
16
16
  <link rel="stylesheet" href="/_static/site.css" type="text/css" media="screen" />
17
17
 
18
- #{Utopia::Project::IMPORT_MAP.relative_to(request.path + "/")}
18
+ #{Utopia::Project::IMPORT_MAP.relative_to(request.env["REQUEST_PATH"]).to_html}
19
19
 
20
20
  <script src="/_components/jquery/jquery.min.js"></script>
21
- <script src="/_components/jquery-syntax/jquery.syntax.min.js"></script>
22
21
 
23
22
  <script src="/_static/links.js"></script>
24
-
25
- <script type="text/javascript">
26
- //<![CDATA[
27
- jQuery(function($) {
28
- $.syntax();
29
- });
30
- //]]>
31
- </script>
32
-
33
- <script type="module">
23
+
24
+ <script type="module">
34
25
  // <![CDATA[
26
+ import {Syntax} from '@socketry/syntax';
27
+ document.addEventListener('DOMContentLoaded', async function() {
28
+ await Syntax.highlight();
29
+ });
30
+
35
31
  import mermaid from 'mermaid';
36
32
  const isDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
37
33
  const theme = isDarkMode ? 'dark' : 'default';
@@ -39,7 +35,6 @@
39
35
  // ]]>
40
36
  </script>
41
37
  </head>
42
-
43
38
  <body>
44
39
  <content:header />
45
40
 
@@ -0,0 +1,293 @@
1
+ import Syntax from '../Syntax.js';
2
+
3
+ const supportsAdopted =
4
+ typeof CSSStyleSheet !== 'undefined' &&
5
+ 'adoptedStyleSheets' in Document.prototype;
6
+
7
+ /**
8
+ * CodeElement - Web Component for syntax highlighting with isolated styles
9
+ *
10
+ * Usage:
11
+ * <syntax-code language="javascript">const x = 1;</syntax-code>
12
+ * <pre><syntax-code language="ruby">puts "Hello"</syntax-code></pre>
13
+ */
14
+ export class CodeElement extends HTMLElement {
15
+ static get observedAttributes() {
16
+ return ['language', 'theme', 'wrap'];
17
+ }
18
+
19
+ #syntax = null;
20
+ #shadow;
21
+ #adoptedHrefs = new Set();
22
+ #highlighted = false;
23
+
24
+ constructor() {
25
+ super();
26
+ }
27
+
28
+ get syntax() {
29
+ return this.#syntax || Syntax.default;
30
+ }
31
+
32
+ set syntax(value) {
33
+ this.#syntax = value;
34
+ // Re-render with new syntax instance if already connected:
35
+ if (this.isConnected && !this.#highlighted) {
36
+ this.#render();
37
+ }
38
+ }
39
+
40
+ get language() {
41
+ return (
42
+ this.getAttribute('language') ||
43
+ this.#detectLanguageFromClass()
44
+ );
45
+ }
46
+
47
+ set language(value) {
48
+ if (value == null) {
49
+ this.removeAttribute('language');
50
+ } else {
51
+ this.setAttribute('language', value);
52
+ }
53
+ }
54
+
55
+ get theme() {
56
+ return this.getAttribute('theme') || this.syntax.defaultOptions.theme;
57
+ }
58
+
59
+ set theme(value) {
60
+ if (value == null) {
61
+ this.removeAttribute('theme');
62
+ } else {
63
+ this.setAttribute('theme', value);
64
+ }
65
+ }
66
+
67
+ get wrap() {
68
+ return this.hasAttribute('wrap');
69
+ }
70
+
71
+ set wrap(value) {
72
+ if (value) {
73
+ this.setAttribute('wrap', '');
74
+ } else {
75
+ this.removeAttribute('wrap');
76
+ }
77
+ }
78
+
79
+ connectedCallback() {
80
+ // Detect if we're inside a <pre> element and set wrap attribute
81
+ if (this.parentElement?.tagName === 'PRE') {
82
+ this.wrap = true;
83
+ }
84
+
85
+ // Don't re-highlight if already done
86
+ if (this.#highlighted) {
87
+ return;
88
+ }
89
+
90
+ if (!this.#shadow) {
91
+ this.#shadow = this.attachShadow({mode: 'open'});
92
+ }
93
+
94
+ this.#render();
95
+ }
96
+
97
+ attributeChangedCallback(name, oldValue, newValue) {
98
+ if (oldValue === newValue) {
99
+ return;
100
+ }
101
+
102
+ if (
103
+ (name === 'language' || name === 'theme' || name === 'wrap') &&
104
+ this.isConnected &&
105
+ this.#shadow
106
+ ) {
107
+ // Reset highlighted flag to allow re-rendering
108
+ this.#highlighted = false;
109
+ this.#adoptedHrefs.clear();
110
+ this.#render();
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Detect language from class names (e.g., language-javascript, brush-ruby)
116
+ */
117
+ #detectLanguageFromClass() {
118
+ const classes = this.className.split(/\s+/);
119
+
120
+ for (const cls of classes) {
121
+ // Match language-* or brush-* patterns
122
+ const match = cls.match(/^(?:language|brush)-(.+)$/);
123
+ if (match) {
124
+ return match[1];
125
+ }
126
+ }
127
+
128
+ return null;
129
+ }
130
+
131
+ /**
132
+ * Get the code content to highlight
133
+ */
134
+ #getCodeContent() {
135
+ // Check if there's a <code> child element
136
+ const codeElement = this.querySelector('code');
137
+ if (codeElement) {
138
+ return codeElement.textContent;
139
+ }
140
+
141
+ return this.textContent;
142
+ }
143
+
144
+ /**
145
+ * Load theme CSS into shadow root
146
+ */
147
+ async #loadStylesheets(languageName) {
148
+ // Guard: ensure shadow root exists
149
+ if (!this.#shadow) {
150
+ return;
151
+ }
152
+
153
+ const themeRoot = new URL(
154
+ this.syntax.themeRoot,
155
+ typeof document !== 'undefined' ? document.baseURI : import.meta.url
156
+ );
157
+
158
+ const urls = [
159
+ new URL('syntax.css', themeRoot),
160
+ new URL(`${languageName}.css`, themeRoot)
161
+ ];
162
+
163
+ if (supportsAdopted && this.#shadow.adoptedStyleSheets !== undefined) {
164
+ const sheets = Array.from(this.#shadow.adoptedStyleSheets);
165
+ for (const url of urls) {
166
+ const href = url.toString();
167
+ if (this.#adoptedHrefs.has(href)) continue;
168
+ try {
169
+ const result = await this.syntax.getStyleSheet(url);
170
+ if (result.sheet) {
171
+ sheets.push(result.sheet);
172
+ this.#adoptedHrefs.add(href);
173
+ }
174
+ } catch (error) {
175
+ console.warn(`Failed to load ${href}:`, error);
176
+ }
177
+ }
178
+ this.#shadow.adoptedStyleSheets = sheets;
179
+ } else {
180
+ // Fallback: inline <style> tags in shadow root
181
+ for (const url of urls) {
182
+ const href = url.toString();
183
+ if (this.#adoptedHrefs.has(href)) continue;
184
+ try {
185
+ const result = await this.syntax.getStyleSheet(url);
186
+ const style = document.createElement('style');
187
+ style.textContent = result.cssText;
188
+ this.#shadow.appendChild(style);
189
+ this.#adoptedHrefs.add(href);
190
+ } catch (error) {
191
+ console.warn(`Failed to load ${href}:`, error);
192
+ }
193
+ }
194
+ }
195
+ }
196
+
197
+ /**
198
+ * Perform syntax highlighting and render into shadow DOM
199
+ */
200
+ async #render() {
201
+ try {
202
+ const languageName = this.language;
203
+
204
+ if (!languageName) {
205
+ console.warn('<syntax-code>: No language specified');
206
+ return;
207
+ }
208
+
209
+ // Get or auto-load the language
210
+ const language = await this.syntax.getLanguage(languageName);
211
+
212
+ if (!language) {
213
+ console.warn(
214
+ `<syntax-code>: Language '${languageName}' not found and could not be loaded`
215
+ );
216
+ return;
217
+ }
218
+
219
+ // Load theme CSS into shadow root using the language's canonical name
220
+ await this.#loadStylesheets(language.name);
221
+
222
+ const code = this.#getCodeContent();
223
+
224
+ // Clear shadow DOM before rendering (must happen before appendChild to remove old content, but after loadStylesheets since fallback path may have appended <style> elements):
225
+ this.#shadow.innerHTML = '';
226
+
227
+ // Highlight and append - language.process() returns a <code> element:
228
+ const highlighted = await language.process(this.syntax, code);
229
+ this.#shadow.appendChild(highlighted);
230
+
231
+ // Clear light DOM only after successful render to avoid losing content on errors:
232
+ this.textContent = '';
233
+
234
+ this.#highlighted = true;
235
+ } catch (error) {
236
+ console.warn('<syntax-code> render failed:', error);
237
+ }
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Auto-register the custom element
243
+ */
244
+ if (
245
+ typeof customElements !== 'undefined' &&
246
+ !customElements.get('syntax-code')
247
+ ) {
248
+ customElements.define('syntax-code', CodeElement);
249
+ }
250
+
251
+ /**
252
+ * Compatibility layer - upgrade existing code blocks to web components
253
+ */
254
+ export function upgradeAll(selector, syntax = null) {
255
+ const elements = document.querySelectorAll(selector);
256
+
257
+ for (const element of elements) {
258
+ // Create a syntax-code wrapper
259
+ const wrapper = document.createElement('syntax-code');
260
+ if (syntax) {
261
+ wrapper.syntax = syntax;
262
+ }
263
+
264
+ // Try to detect language from various sources
265
+ let language = element.getAttribute('lang') || element.getAttribute('language');
266
+
267
+ if (!language) {
268
+ // Check class names
269
+ const classes = element.className.split(/\s+/);
270
+ for (const cls of classes) {
271
+ const match = cls.match(/^(?:language|brush)-(.+)$/);
272
+ if (match) {
273
+ language = match[1];
274
+ break;
275
+ }
276
+ }
277
+ }
278
+
279
+ if (language) {
280
+ wrapper.setAttribute('language', language);
281
+ }
282
+
283
+ // Copy the code content into the wrapper
284
+ wrapper.textContent = element.textContent;
285
+
286
+ // Replace <code> with <syntax-code>, leaving <pre> parent in place
287
+ const parent = element.parentElement;
288
+ parent.replaceChild(wrapper, element);
289
+ }
290
+ }
291
+
292
+ export {Syntax};
293
+ export default CodeElement;
@@ -0,0 +1,52 @@
1
+ export class GenericSyntaxError extends Error {
2
+ constructor(message, options = {}) {
3
+ super(message, options);
4
+ Object.defineProperty(this, 'name', {value: this.constructor.name});
5
+ }
6
+ }
7
+
8
+ export class LanguageNotFoundError extends GenericSyntaxError {
9
+ constructor(language, options = {}) {
10
+ super(`Language not found: ${language}`, options);
11
+ this.language = language;
12
+ }
13
+ }
14
+
15
+ export class LanguageLoadError extends GenericSyntaxError {
16
+ constructor(language, url, options = {}) {
17
+ super(`Failed to load language '${language}' from ${url}`, options);
18
+ this.language = language;
19
+ this.url = url;
20
+ }
21
+ }
22
+
23
+ export class StyleSheetLoadError extends GenericSyntaxError {
24
+ constructor(url, status, options = {}) {
25
+ super(`Failed to load stylesheet ${url} (status: ${status})`, options);
26
+ this.url = url;
27
+ this.status = status;
28
+ }
29
+ }
30
+
31
+ export class RuleApplyError extends GenericSyntaxError {
32
+ constructor(rule, options = {}) {
33
+ const pattern =
34
+ rule?.pattern instanceof RegExp
35
+ ? `/${rule.pattern.source}/${rule.pattern.flags}`
36
+ : String(rule?.pattern);
37
+ const type = rule?.type || rule?.klass || 'unknown';
38
+ super(`Rule apply failed (type=${type}, pattern=${pattern})`, options);
39
+ this.rule = rule;
40
+ }
41
+ }
42
+
43
+ export class HighlightRenderError extends GenericSyntaxError {}
44
+
45
+ export default {
46
+ GenericSyntaxError,
47
+ LanguageNotFoundError,
48
+ LanguageLoadError,
49
+ StyleSheetLoadError,
50
+ RuleApplyError,
51
+ HighlightRenderError
52
+ };
@@ -0,0 +1,49 @@
1
+ import {Language} from '../Language.js';
2
+ import {Rule} from '../Rule.js';
3
+
4
+ const language = new Language('apache');
5
+
6
+ language.push({
7
+ pattern: /(<(\w+).*?>)/i,
8
+ matches: Rule.extractMatches(
9
+ {
10
+ type: 'tag',
11
+ allow: ['attribute', 'tag-name', 'string']
12
+ },
13
+ {
14
+ type: 'tag-name',
15
+ process: Rule.webLinkProcess(
16
+ 'http://httpd.apache.org/docs/trunk/mod/directive-dict.html#'
17
+ )
18
+ }
19
+ )
20
+ });
21
+
22
+ language.push({
23
+ pattern: /(<\/(\w+).*?>)/i,
24
+ matches: Rule.extractMatches(
25
+ {type: 'tag', allow: ['tag-name']},
26
+ {type: 'tag-name'}
27
+ )
28
+ });
29
+
30
+ language.push({
31
+ pattern: /^\s+([A-Z][\w]+)/m,
32
+ matches: Rule.extractMatches({
33
+ type: 'function',
34
+ allow: ['attribute'],
35
+ process: Rule.webLinkProcess(
36
+ 'http://httpd.apache.org/docs/trunk/mod/directive-dict.html#'
37
+ )
38
+ })
39
+ });
40
+
41
+ language.push(Rule.perlStyleComment);
42
+ language.push(Rule.singleQuotedString);
43
+ language.push(Rule.doubleQuotedString);
44
+
45
+ language.push(Rule.webLink);
46
+
47
+ export default function register(syntax) {
48
+ syntax.register('apache', language);
49
+ }
@@ -0,0 +1,157 @@
1
+ import {Language} from '../Language.js';
2
+ import {Rule} from '../Rule.js';
3
+
4
+ const language = new Language('applescript');
5
+
6
+ var keywords = [
7
+ 'after',
8
+ 'before',
9
+ 'beginning',
10
+ 'continue',
11
+ 'copy',
12
+ 'each',
13
+ 'end',
14
+ 'every',
15
+ 'from',
16
+ 'get',
17
+ 'global',
18
+ 'in',
19
+ 'local',
20
+ 'named',
21
+ 'of',
22
+ 'return',
23
+ 'set',
24
+ 'some',
25
+ 'that',
26
+ 'the',
27
+ 'then',
28
+ 'times',
29
+ 'to',
30
+ 'where',
31
+ 'whose',
32
+ 'with',
33
+ 'without'
34
+ ];
35
+
36
+ language.push(keywords, {type: 'keyword'});
37
+
38
+ var ordinals = [
39
+ 'first',
40
+ 'second',
41
+ 'third',
42
+ 'fourth',
43
+ 'fifth',
44
+ 'sixth',
45
+ 'seventh',
46
+ 'eighth',
47
+ 'ninth',
48
+ 'tenth',
49
+ 'last',
50
+ 'front',
51
+ 'back',
52
+ 'middle'
53
+ ];
54
+
55
+ language.push(ordinals, {type: 'keyword'});
56
+
57
+ var specials = [
58
+ 'activate',
59
+ 'add',
60
+ 'alias',
61
+ 'AppleScript',
62
+ 'ask',
63
+ 'attachment',
64
+ 'boolean',
65
+ 'class',
66
+ 'constant',
67
+ 'delete',
68
+ 'duplicate',
69
+ 'empty',
70
+ 'exists',
71
+ 'false',
72
+ 'id',
73
+ 'integer',
74
+ 'list',
75
+ 'make',
76
+ 'message',
77
+ 'modal',
78
+ 'modified',
79
+ 'new',
80
+ 'no',
81
+ 'paragraph',
82
+ 'pi',
83
+ 'properties',
84
+ 'quit',
85
+ 'real',
86
+ 'record',
87
+ 'remove',
88
+ 'rest',
89
+ 'result',
90
+ 'reveal',
91
+ 'reverse',
92
+ 'run',
93
+ 'running',
94
+ 'save',
95
+ 'string',
96
+ 'true',
97
+ 'word',
98
+ 'yes'
99
+ ];
100
+
101
+ language.push(specials, {type: 'keyword'});
102
+
103
+ language.push(Rule.webLink);
104
+
105
+ // AppleScript supports multiple comment styles
106
+ language.push({
107
+ pattern: /(\-\-|#).*$/m,
108
+ type: 'comment',
109
+ allow: ['href']
110
+ });
111
+
112
+ language.push({
113
+ pattern: /\(\*(?:[\s\S]*?\(\*[\s\S]*?\*\))*[\s\S]*?\*\)/m,
114
+ type: 'comment',
115
+ allow: ['href']
116
+ });
117
+
118
+ language.push(Rule.doubleQuotedString);
119
+
120
+ // Ordinal numbers (1st, 2nd, 3rd, etc.)
121
+ language.push({
122
+ pattern: /\b\d+(st|nd|rd|th)\b/,
123
+ type: 'constant'
124
+ });
125
+
126
+ // Regular numbers
127
+ language.push({
128
+ pattern: /\b-?\d+\.?\d*(?:E[+\-]?\d+)?\b/,
129
+ type: 'constant'
130
+ });
131
+
132
+ language.push({
133
+ pattern: /&|¬|=|≠|>|<|≥|>=|≤|<=|\*|\+|-|\/|÷|\^/,
134
+ type: 'operator'
135
+ });
136
+
137
+ language.push({
138
+ pattern:
139
+ /\b(?:and|as|div|mod|not|or|return(?!\s&)(ing)?|equals|(is(n't| not)? )?equal( to)?|does(n't| not) equal|(is(n't| not)? )?(greater|less) than( or equal( to)?)?|(comes|does(n't| not) come) (after|before)|is(n't| not)?( in)? (back|front) of|is(n't| not)? behind|is(n't| not)?( (in|contained by))?|does(n't| not) contain|contain(s)?|(start|begin|end)(s)? with|((but|end) )?(consider|ignor)ing|prop(erty)?|(a )?ref(erence)?( to)?|repeat (until|while|with)|((end|exit) )?repeat|((else|end) )?if|else|(end )?(script|tell|try)|(on )?error|(put )?into|(of )?(it|me)|its|my|with (timeout( of)?|transaction)|end (timeout|transaction))\b/,
140
+ type: 'keyword'
141
+ });
142
+
143
+ language.push({
144
+ pattern:
145
+ /\b(?:about|above|against|around|at|below|beneath|beside|between|by|(apart|aside) from|(instead|out) of|into|on(to)?|over|since|thr(ough|u)|under)\b/,
146
+ type: 'keyword'
147
+ });
148
+
149
+ language.push({
150
+ pattern:
151
+ /\b(?:adding folder items to|after receiving|choose( ((remote )?application|color|folder|from list|URL))?|clipboard info|set the clipboard to|(the )?clipboard|entire contents|display(ing| (alert|dialog|mode))?|document( (edited|file|nib name))?|file( (name|type))?|(info )?for|giving up after|(name )?extension|quoted form|return(ed)?|second(?! item)(s)?|list (disks|folder)|text item(s| delimiters)?|(Unicode )?text|(disk )?item(s)?|((current|list) )?view|((container|key) )?window|with (data|icon( (caution|note|stop))?|parameter(s)?|prompt|properties|seed|title)|case|diacriticals|hyphens|numeric strings|punctuation|white space|folder creation|application(s( folder)?| (processes|scripts position|support))?|((desktop )?(pictures )?|(documents|downloads|favorites|home|keychain|library|movies|music|public|scripts|sites|system|users|utilities|workflows) )folder|desktop|Folder Action scripts|font(s| panel)?|help|internet plugins|modem scripts|(system )?preferences|printer descriptions|scripting (additions|components)|shared (documents|libraries)|startup (disk|items)|temporary items|trash|on server|in AppleTalk zone|((as|long|short) )?user name|user (ID|locale)|(with )?password|in (bundle( with identifier)?|directory)|(close|open for) access|read|write( permission)?|(g|s)et eof|using( delimiters)?|starting at|default (answer|button|color|country code|entr(y|ies)|identifiers|items|name|location|script editor)|hidden( answer)?|open(ed| (location|untitled))?|error (handling|reporting)|(do( shell)?|load|run|store) script|administrator privileges|altering line endings|get volume settings|(alert|boot|input|mount|output|set) volume|output muted|(fax|random )?number|round(ing)?|up|down|toward zero|to nearest|as taught in school|system (attribute|info)|((AppleScript( Studio)?|system) )?version|(home )?directory|(IPv4|primary Ethernet) address|CPU (type|speed)|physical memory|time (stamp|to GMT)|replacing|ASCII (character|number)|localized string|from table|offset|summarize|beep|delay|say|(empty|multiple) selections allowed|(of|preferred) type|invisibles|showing( package contents)?|editable URL|(File|FTP|News|Media|Web) [Ss]ervers|Telnet hosts|Directory services|Remote applications|waiting until completion|saving( (in|to))?|path (for|to( (((current|frontmost) )?application|resource))?)|POSIX (file|path)|(background|RGB) color|(OK|cancel) button name|cancel button|button(s)?|cubic ((centi)?met(re|er)s|yards|feet|inches)|square ((kilo)?met(re|er)s|miles|yards|feet)|(centi|kilo)?met(re|er)s|miles|yards|feet|inches|lit(re|er)s|gallons|quarts|(kilo)?grams|ounces|pounds|degrees (Celsius|Fahrenheit|Kelvin)|print( (dialog|settings))?|clos(e(able)?|ing)|(de)?miniaturized|miniaturizable|zoom(ed|able)|attribute run|action (method|property|title)|phone|email|((start|end)ing|home) page|((birth|creation|current|custom|modification) )?date|((((phonetic )?(first|last|middle))|computer|host|maiden|related) |nick)?name|aim|icq|jabber|msn|yahoo|address(es)?|save addressbook|should enable action|city|country( code)?|formatte(r|d address)|(palette )?label|state|street|zip|AIM [Hh]andle(s)?|my card|select(ion| all)?|unsaved|(alpha )?value|entr(y|ies)|group|(ICQ|Jabber|MSN) handle|person|people|company|department|icon image|job title|note|organization|suffix|vcard|url|copies|collating|pages (across|down)|request print time|target( printer)?|((GUI Scripting|Script menu) )?enabled|show Computer scripts|(de)?activated|awake from nib|became (key|main)|call method|of (class|object)|center|clicked toolbar item|closed|for document|exposed|(can )?hide|idle|keyboard (down|up)|event( (number|type))?|launch(ed)?|load (image|movie|nib|sound)|owner|log|mouse (down|dragged|entered|exited|moved|up)|move|column|localization|resource|script|register|drag (info|types)|resigned (active|key|main)|resiz(e(d)?|able)|right mouse (down|dragged|up)|scroll wheel|(at )?index|should (close|open( untitled)?|quit( after last window closed)?|zoom)|((proposed|screen) )?bounds|show(n)?|behind|in front of|size (mode|to fit)|update(d| toolbar item)?|was (hidden|miniaturized)|will (become active|close|finish launching|hide|miniaturize|move|open|quit|(resign )?active|((maximum|minimum|proposed) )?size|show|zoom)|bundle|data source|movie|pasteboard|sound|tool(bar| tip)|(color|open|save) panel|coordinate system|frontmost|main( (bundle|menu|window))?|((services|(excluded from )?windows) )?menu|((executable|frameworks|resource|scripts|shared (frameworks|support)) )?path|(selected item )?identifier|data|content(s| view)?|character(s)?|click count|(command|control|option|shift) key down|context|delta (x|y|z)|key( code)?|location|pressure|unmodified characters|types|(first )?responder|playing|(allowed|selectable) identifiers|allows customization|(auto saves )?configuration|visible|image( name)?|menu form representation|tag|user(-| )defaults|associated file name|(auto|needs) display|current field editor|floating|has (resize indicator|shadow)|hides when deactivated|level|minimized (image|title)|opaque|position|release when closed|sheet|title(d)?)\b/,
152
+ type: 'keyword'
153
+ });
154
+
155
+ export default function register(syntax) {
156
+ syntax.register('applescript', language);
157
+ }