mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Remove shiki lang path property support (#9196)
This commit is contained in:
parent
153a5abb90
commit
37697a2c55
7 changed files with 22 additions and 427 deletions
21
.changeset/plenty-candles-help.md
Normal file
21
.changeset/plenty-candles-help.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
'astro': major
|
||||
---
|
||||
|
||||
Removes support for Shiki custom language's `path` property. The language JSON file should be imported and passed to the option instead.
|
||||
|
||||
```diff
|
||||
// astro.config.js
|
||||
+ import customLang from './custom.tmLanguage.json'
|
||||
|
||||
export default defineConfig({
|
||||
markdown: {
|
||||
shikiConfig: {
|
||||
langs: [
|
||||
- { path: './custom.tmLanguage.json' },
|
||||
+ customLang,
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
|
@ -1,7 +1,4 @@
|
|||
---
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type {
|
||||
BuiltinLanguage,
|
||||
BuiltinTheme,
|
||||
|
@ -64,23 +61,6 @@ const {
|
|||
|
||||
// shiki -> shikiji compat
|
||||
if (typeof lang === 'object') {
|
||||
// shikiji does not support `path`
|
||||
// https://github.com/shikijs/shiki/blob/facb6ff37996129626f8066a5dccb4608e45f649/packages/shiki/src/loader.ts#L98
|
||||
const langPath = (lang as any).path;
|
||||
if (langPath) {
|
||||
// shiki resolves path from within its package directory :shrug:
|
||||
const astroRoot = fileURLToPath(new URL('../', import.meta.url));
|
||||
const normalizedPath = path.isAbsolute(langPath) ? langPath : path.resolve(astroRoot, langPath);
|
||||
try {
|
||||
const content = fs.readFileSync(normalizedPath, 'utf-8');
|
||||
const parsed = JSON.parse(content);
|
||||
Object.assign(lang, parsed);
|
||||
} catch (e) {
|
||||
throw new Error(`Unable to find language file at ${normalizedPath}`, {
|
||||
cause: e,
|
||||
});
|
||||
}
|
||||
}
|
||||
// `id` renamed to `name` (always override)
|
||||
if ((lang as any).id) {
|
||||
lang.name = (lang as any).id;
|
||||
|
|
|
@ -8,10 +8,9 @@ import { markdownConfigDefaults } from '@astrojs/markdown-remark';
|
|||
import { bundledThemes, type BuiltinTheme } from 'shikiji';
|
||||
import type { AstroUserConfig, ViteUserConfig } from '../../@types/astro.js';
|
||||
|
||||
import fs from 'node:fs';
|
||||
import type { OutgoingHttpHeaders } from 'node:http';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
import { pathToFileURL } from 'node:url';
|
||||
import { z } from 'zod';
|
||||
import { appendForwardSlash, prependForwardSlash, removeTrailingForwardSlash } from '../path.js';
|
||||
|
||||
|
@ -238,25 +237,6 @@ export const AstroConfigSchema = z.object({
|
|||
for (const lang of langs) {
|
||||
// shiki -> shikiji compat
|
||||
if (typeof lang === 'object') {
|
||||
// shikiji does not support `path`
|
||||
// https://github.com/shikijs/shiki/blob/facb6ff37996129626f8066a5dccb4608e45f649/packages/shiki/src/loader.ts#L98
|
||||
const langPath = (lang as any).path;
|
||||
if (langPath) {
|
||||
// shiki resolves path from within its package directory :shrug:
|
||||
const astroRoot = fileURLToPath(new URL('../../../', import.meta.url));
|
||||
const normalizedPath = path.isAbsolute(langPath)
|
||||
? langPath
|
||||
: path.resolve(astroRoot, langPath);
|
||||
try {
|
||||
const content = fs.readFileSync(normalizedPath, 'utf-8');
|
||||
const parsed = JSON.parse(content);
|
||||
Object.assign(lang, parsed);
|
||||
} catch (e) {
|
||||
throw new Error(`Unable to find language file at ${normalizedPath}`, {
|
||||
cause: e,
|
||||
});
|
||||
}
|
||||
}
|
||||
// `id` renamed to `name` (always override)
|
||||
if ((lang as any).id) {
|
||||
lang.name = (lang as any).id;
|
||||
|
|
|
@ -95,10 +95,6 @@ describe('Astro Markdown Shiki', () => {
|
|||
|
||||
const unknownLang = $('.astro-code').get(1);
|
||||
expect(unknownLang.attribs.style).to.contain('background-color:#24292e;color:#e1e4e8;');
|
||||
|
||||
const caddyLang = $('.astro-code').last();
|
||||
const caddySegments = caddyLang.find('.line');
|
||||
expect(caddySegments.get(1).children[0].attribs.style).to.contain('color:#B392F0');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -13,14 +13,6 @@ export default {
|
|||
grammar: riGrammar,
|
||||
aliases: ['ri'],
|
||||
},
|
||||
{
|
||||
id: 'caddy',
|
||||
scopeName: 'source.Caddyfile',
|
||||
// shiki compat: resolves from astro package directory.
|
||||
// careful as astro is linked, this relative path is based on astro/packages/astro.
|
||||
// it's weird but we're testing to prevent regressions.
|
||||
path: './test/fixtures/astro-markdown-shiki/langs/src/caddyfile.tmLanguage.json',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,365 +0,0 @@
|
|||
{
|
||||
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
|
||||
|
||||
"name": "Caddyfile",
|
||||
"fileTypes": ["Caddyfile"],
|
||||
"scopeName": "source.Caddyfile",
|
||||
|
||||
"patterns": [
|
||||
{ "include": "#comments" },
|
||||
{ "include": "#strings" },
|
||||
{ "include": "#domains" },
|
||||
{ "include": "#status_codes" },
|
||||
{ "include": "#path" },
|
||||
{ "include": "#global_options" },
|
||||
{ "include": "#matchers" },
|
||||
{ "include": "#directive" },
|
||||
{ "include": "#site_block_common" }
|
||||
],
|
||||
|
||||
"repository": {
|
||||
"comments": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "comment.line.Caddyfile",
|
||||
"match": "\\s#.*"
|
||||
},
|
||||
{
|
||||
"name": "comment.line.Caddyfile",
|
||||
"match": "^#.*"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"strings": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "Double Quoted Strings",
|
||||
"begin": "\"",
|
||||
"end": "\"",
|
||||
"name": "string.quoted.double.Caddyfile",
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.character.escape.Caddyfile",
|
||||
"match": "\\\\\""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"comment": "Backtick Strings",
|
||||
"begin": "`",
|
||||
"end": "`",
|
||||
"name": "string.quoted.single.Caddyfile"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"status_codes": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "constant.numeric.decimal",
|
||||
"match": "\\s[0-9]{3}(?!\\.)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"path": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control.caddyfile",
|
||||
"match": "(unix/)*/[a-zA-Z0-9_\\-./*]+"
|
||||
},
|
||||
{
|
||||
"name": "variable.other.property.caddyfile",
|
||||
"match": "\\*.[a-z]{1,5}"
|
||||
},
|
||||
{
|
||||
"name": "variable.other.property.caddyfile",
|
||||
"match": "\\*/?"
|
||||
},
|
||||
{
|
||||
"name": "variable.other.property.caddyfile",
|
||||
"match": "\\?/"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"domains": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "Domains and URLs",
|
||||
"name": "keyword.control.caddyfile",
|
||||
"match": "(https?://)*[a-z0-9-\\*]*(?:\\.[a-zA-Z]{2,})+(:[0-9]+)*\\S*"
|
||||
},
|
||||
{
|
||||
"comment": "localhost",
|
||||
"name": "keyword.control.caddyfile",
|
||||
"match": "localhost(:[0-9]+)*"
|
||||
},
|
||||
{
|
||||
"comment": "IPv4",
|
||||
"name": "keyword.control.caddyfile",
|
||||
"match": "((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
|
||||
},
|
||||
{
|
||||
"comment": "IPv6",
|
||||
"name": "keyword.control.caddyfile",
|
||||
"match": "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"
|
||||
},
|
||||
{
|
||||
"comment": "Ports",
|
||||
"name": "keyword.control.caddyfile",
|
||||
"match": ":[0-9]+"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"global_options": {
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "^(\\{)$",
|
||||
"end": "^(\\})$",
|
||||
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.definition.dictionary.begin" }
|
||||
},
|
||||
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.definition.dictionary.end" }
|
||||
},
|
||||
|
||||
"patterns": [
|
||||
{ "include": "#comments" },
|
||||
{
|
||||
"name": "support.constant.Caddyfile",
|
||||
"match": "^\\s*(debug|https?_port|default_bind|order|storage|storage_clean_interval|renew_interval|ocsp_interval|admin|log|grace_period|shutdown_delay|auto_https|email|default_sni|local_certs|skip_install_trust|acme_ca|acme_ca_root|acme_eab|acme_dns|on_demand_tls|key_type|cert_issuer|ocsp_stapling|preferred_chains|servers|pki|events)"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"site_block_common": {
|
||||
"patterns": [{ "include": "#placeholders" }, { "include": "#block" }]
|
||||
},
|
||||
|
||||
"matchers": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "Matchers",
|
||||
"name": "support.function.Caddyfile",
|
||||
"match": "@[^\\s]+(?=\\s)"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"placeholders": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "keyword.control.Caddyfile",
|
||||
"match": "\\{[\\[\\]\\w.\\$+-]+\\}"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"directive": {
|
||||
"patterns": [
|
||||
{
|
||||
"name": "entity.name.function.Caddyfile",
|
||||
"match": "^\\s*[a-zA-Z_\\-+]+"
|
||||
},
|
||||
{ "include": "#content_types" },
|
||||
{ "include": "#heredoc" }
|
||||
]
|
||||
},
|
||||
|
||||
"content_types": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "Content Types",
|
||||
"name": "variable.other.property.caddyfile",
|
||||
"match": "(application|audio|example|font|image|message|model|multipart|text|video)/[a-zA-Z0-9*+\\-.]+;* *[a-zA-Z0-9=\\-]*"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"block": {
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "\\{",
|
||||
"end": "\\}",
|
||||
|
||||
"patterns": [{ "include": "#block_content" }]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"block_content": {
|
||||
"patterns": [
|
||||
{
|
||||
"patterns": [
|
||||
{ "include": "#comments" },
|
||||
{ "include": "#strings" },
|
||||
{ "include": "#domains" },
|
||||
{ "include": "#status_codes" },
|
||||
{ "include": "#path" },
|
||||
{ "include": "#matchers" },
|
||||
{ "include": "#placeholders" },
|
||||
{ "include": "#directive" },
|
||||
{ "include": "#block" }
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"heredoc": {
|
||||
"patterns": [
|
||||
{
|
||||
"begin": "(?i)(?=<<\\s*([a-z_\\x{7f}-\\x{10ffff}][a-z0-9_\\x{7f}-\\x{10ffff}]*)\\s*$)",
|
||||
"end": "(?!\\G)",
|
||||
"name": "string.unquoted.heredoc.caddyfile",
|
||||
"patterns": [{ "include": "#heredoc_interior" }]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"heredoc_interior": {
|
||||
"patterns": [
|
||||
{
|
||||
"comment": "CSS",
|
||||
|
||||
"name": "meta.embedded.css",
|
||||
"contentName": "source.css",
|
||||
|
||||
"begin": "(<<)\\s*(CSS)(\\s*)$",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.begin.caddyfile" },
|
||||
"1": { "name": "punctuation.definition.string.begin" },
|
||||
"2": { "name": "keyword.operator.heredoc.caddyfile" },
|
||||
"4": { "name": "invalid.illegal.trailing-whitespace.caddyfile" }
|
||||
},
|
||||
|
||||
"end": "^\\s*(\\2)(?![A-Za-z0-9_\\x{7f}-\\x{10ffff}])",
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.end.caddyfile" },
|
||||
"1": { "name": "keyword.operator.heredoc.caddyfile" }
|
||||
},
|
||||
|
||||
"patterns": [{ "include": "source.css" }]
|
||||
},
|
||||
|
||||
{
|
||||
"comment": "HTML",
|
||||
|
||||
"name": "meta.embedded.html",
|
||||
"contentName": "text.html",
|
||||
|
||||
"begin": "(<<)\\s*(HTML)(\\s*)$",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.begin.caddyfile" },
|
||||
"1": { "name": "punctuation.definition.string.begin" },
|
||||
"2": { "name": "keyword.operator.heredoc.caddyfile" },
|
||||
"4": { "name": "invalid.illegal.trailing-whitespace.caddyfile" }
|
||||
},
|
||||
|
||||
"end": "^\\s*(\\2)(?![A-Za-z0-9_\\x{7f}-\\x{10ffff}])",
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.end.caddyfile" },
|
||||
"1": { "name": "keyword.operator.heredoc.caddyfile" }
|
||||
},
|
||||
|
||||
"patterns": [{ "include": "text.html.basic" }]
|
||||
},
|
||||
|
||||
{
|
||||
"comment": "JavaScript",
|
||||
|
||||
"name": "meta.embedded.js",
|
||||
"contentName": "source.js",
|
||||
|
||||
"begin": "(<<)\\s*(JAVASCRIPT|JS)(\\s*)$",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.begin.caddyfile" },
|
||||
"1": { "name": "punctuation.definition.string.begin" },
|
||||
"2": { "name": "keyword.operator.heredoc.caddyfile" },
|
||||
"4": { "name": "invalid.illegal.trailing-whitespace.caddyfile" }
|
||||
},
|
||||
|
||||
"end": "^\\s*(\\2)(?![A-Za-z0-9_\\x{7f}-\\x{10ffff}])",
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.end.caddyfile" },
|
||||
"1": { "name": "keyword.operator.heredoc.caddyfile" }
|
||||
},
|
||||
|
||||
"patterns": [{ "include": "source.js" }]
|
||||
},
|
||||
|
||||
{
|
||||
"comment": "JSON",
|
||||
|
||||
"name": "meta.embedded.json",
|
||||
"contentName": "source.json",
|
||||
|
||||
"begin": "(<<)\\s*(JSON)(\\s*)$",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.begin.caddyfile" },
|
||||
"1": { "name": "punctuation.definition.string.begin" },
|
||||
"2": { "name": "keyword.operator.heredoc.caddyfile" },
|
||||
"4": { "name": "invalid.illegal.trailing-whitespace.caddyfile" }
|
||||
},
|
||||
|
||||
"end": "^\\s*(\\2)(?![A-Za-z0-9_\\x{7f}-\\x{10ffff}])",
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.end.caddyfile" },
|
||||
"1": { "name": "keyword.operator.heredoc.caddyfile" }
|
||||
},
|
||||
|
||||
"patterns": [{ "include": "source.json" }]
|
||||
},
|
||||
|
||||
{
|
||||
"comment": "XML",
|
||||
|
||||
"name": "meta.embedded.xml",
|
||||
"contentName": "text.xml",
|
||||
|
||||
"begin": "(<<)\\s*(XML)(\\s*)$",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.begin.caddyfile" },
|
||||
"1": { "name": "punctuation.definition.string.begin" },
|
||||
"2": { "name": "keyword.operator.heredoc.caddyfile" },
|
||||
"4": { "name": "invalid.illegal.trailing-whitespace.caddyfile" }
|
||||
},
|
||||
|
||||
"end": "^\\s*(\\2)(?![A-Za-z0-9_\\x{7f}-\\x{10ffff}])",
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.end.caddyfile" },
|
||||
"1": { "name": "keyword.operator.heredoc.caddyfile" }
|
||||
},
|
||||
|
||||
"patterns": [{ "include": "text.xml" }]
|
||||
},
|
||||
|
||||
{
|
||||
"comment": "Any other heredoc",
|
||||
|
||||
"begin": "(?i)(<<)\\s*([a-z_\\x{7f}-\\x{10ffff}]+[a-z0-9_\\x{7f}-\\x{10ffff}]*)(\\s*)",
|
||||
"beginCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.begin.caddyfile" },
|
||||
"1": { "name": "punctuation.definition.string.caddyfile" },
|
||||
"2": { "name": "keyword.operator.heredoc.caddyfile" },
|
||||
"4": { "name": "invalid.illegal.trailing-whitespace.caddyfile" }
|
||||
},
|
||||
|
||||
"end": "^\\s*(\\2)(?![A-Za-z0-9_\\x{7f}-\\x{10ffff}])",
|
||||
"endCaptures": {
|
||||
"0": { "name": "punctuation.section.embedded.end.caddyfile" },
|
||||
"1": { "name": "keyword.operator.heredoc.caddyfile" }
|
||||
},
|
||||
|
||||
"patterns": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -24,12 +24,3 @@ fin
|
|||
```unknown
|
||||
This language does not exist
|
||||
```
|
||||
|
||||
```caddy
|
||||
example.com {
|
||||
root * /var/www/wordpress
|
||||
encode gzip
|
||||
php_fastcgi unix//run/php/php-version-fpm.sock
|
||||
file_server
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in a new issue