Skip to content

Commit b9c2627

Browse files
committed
feat: add language razor
1 parent e0d8438 commit b9c2627

10 files changed

Lines changed: 77 additions & 1 deletion

File tree

LANGUAGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
- [x] Erlang (`erlang`)
7676
- [x] Nix (`nix`)
7777
- [x] HCL (`hcl`)
78+
- [x] Razor (`razor`)
7879

7980
## Pending
8081

@@ -84,7 +85,6 @@
8485
- [ ] OCaml (`ocaml`)
8586
- [ ] Protocol Buffers (`protobuf`)
8687
- [ ] Racket (`racket`)
87-
- [ ] Razor (`razor`)
8888
- [ ] Rego (`rego`)
8989
- [ ] Solidity (`solidity`)
9090
- [ ] TeX (`tex`)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ import { powershell } from "code-languages/powershell";
9797
import { pug } from "code-languages/pug";
9898
import { python } from "code-languages/python";
9999
import { r } from "code-languages/r";
100+
import { razor } from "code-languages/razor";
100101
import { ruby } from "code-languages/ruby";
101102
import { scala } from "code-languages/scala";
102103
import { scss } from "code-languages/scss";
@@ -166,6 +167,7 @@ console.log(powershell.extensions);
166167
console.log(pug.version);
167168
console.log(python.publishedDate);
168169
console.log(r.version);
170+
console.log(razor.extensions);
169171
console.log(ruby.website);
170172
console.log(scala.version);
171173
console.log(scss.extensions);
@@ -241,6 +243,7 @@ import {
241243
pug,
242244
rust,
243245
r,
246+
razor,
244247
ruby,
245248
scala,
246249
scss,
@@ -309,6 +312,7 @@ console.log(localizeLanguage(powershell).name);
309312
console.log(localizeLanguage(pug, "es").description);
310313
console.log(go.logo);
311314
console.log(localizeLanguage(r, "es").description);
315+
console.log(localizeLanguage(razor, "es").description);
312316
console.log(localizeLanguage(ruby, "es").description);
313317
console.log(localizeLanguage(scala, "es").description);
314318
console.log(localizeLanguage(scss).name);
@@ -471,6 +475,7 @@ console.log(detectLanguages("include/config.h").map((language) => language.slug)
471475
| <img src="https://cdn.simpleicons.org/pug/A86454" alt="Pug logo" width="24" height="24"> | Pug | `pug` | `.pug`, `.jade` | `3.0.4` | `code-languages/pug` |
472476
| <img src="https://commons.wikimedia.org/wiki/Special:FilePath/Python-logo-notext.svg" alt="Python logo" width="24" height="24"> | Python | `python` | `.py`, `.pyw` | `3.14.4` | `code-languages/python` |
473477
| <img src="https://www.r-project.org/logo/Rlogo.svg" alt="R logo" width="24" height="24"> | R | `r` | `.r`, `.R`, `.rmd`, `.Rmd`, `.qmd`, `.Rprofile` | `4.6.0` | `code-languages/r` |
478+
| <img src="https://cdn.simpleicons.org/dotnet/512BD4" alt="Razor logo" width="24" height="24"> | Razor | `razor` | `.cshtml`, `.razor` | `10.0.8` | `code-languages/razor` |
474479
| <img src="https://www.ruby-lang.org/images/header-ruby-logo.png" alt="Ruby logo" width="24" height="24"> | Ruby | `ruby` | `.rb`, `.rbw`, `.rake`, `.gemspec`, `Gemfile`, `Rakefile`, `config.ru` | `4.0.4` | `code-languages/ruby` |
475480
| <img src="https://www.rust-lang.org/logos/rust-logo-512x512.png" alt="Rust logo" width="24" height="24"> | Rust | `rust` | `.rs` | `1.95.0` | `code-languages/rust` |
476481
| <img src="https://cdn.simpleicons.org/scala/DC322F" alt="Scala logo" width="24" height="24"> | Scala | `scala` | `.scala`, `.sc` | `3.8.3` | `code-languages/scala` |

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,11 @@
391391
"import": "./dist/languages/perl.js",
392392
"require": "./dist/languages/perl.cjs"
393393
},
394+
"./razor": {
395+
"types": "./dist/languages/razor.d.ts",
396+
"import": "./dist/languages/razor.js",
397+
"require": "./dist/languages/razor.cjs"
398+
},
394399
"./yaml": {
395400
"types": "./dist/languages/yaml.d.ts",
396401
"import": "./dist/languages/yaml.js",

scripts/check-language-versions.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,19 @@ const checkers = {
384384
sourceUrl: "https://www.r-project.org/",
385385
};
386386
},
387+
async razor() {
388+
const json = await fetchJson(
389+
"https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json",
390+
);
391+
const versions = json["releases-index"]
392+
?.map((release) => release["latest-release"])
393+
.filter((version) => /^\d+\.\d+\.\d+$/.test(version));
394+
395+
return {
396+
latestVersion: latestSemver(versions),
397+
sourceUrl: "https://builds.dotnet.microsoft.com/dotnet/release-metadata/releases-index.json",
398+
};
399+
},
387400
async rust() {
388401
const toml = await fetchText("https://static.rust-lang.org/dist/channel-rust-stable.toml");
389402
const match = toml.match(/pkg\.rust\]\s+version = "(\d+\.\d+\.\d+)/);

src/catalog.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import { powershell } from "./languages/powershell";
5252
import { pug } from "./languages/pug";
5353
import { python } from "./languages/python";
5454
import { r } from "./languages/r";
55+
import { razor } from "./languages/razor";
5556
import { ruby } from "./languages/ruby";
5657
import { rust } from "./languages/rust";
5758
import { scala } from "./languages/scala";
@@ -129,6 +130,7 @@ export const languages = [
129130
pug,
130131
python,
131132
r,
133+
razor,
132134
ruby,
133135
rust,
134136
scala,

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export { powershell } from "./languages/powershell";
6565
export { pug } from "./languages/pug";
6666
export { python } from "./languages/python";
6767
export { r } from "./languages/r";
68+
export { razor } from "./languages/razor";
6869
export { ruby } from "./languages/ruby";
6970
export { rust } from "./languages/rust";
7071
export { scala } from "./languages/scala";

src/language-registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const languageIndex = [
7474
{ slug: "pug", extensions: [".pug", ".jade"] },
7575
{ slug: "python", extensions: [".py", ".pyw"] },
7676
{ slug: "r", extensions: [".r", ".R", ".rmd", ".Rmd", ".qmd", ".Rprofile"] },
77+
{ slug: "razor", extensions: [".cshtml", ".razor"] },
7778
{
7879
slug: "ruby",
7980
extensions: [".rb", ".rbw", ".rake", ".gemspec", "Gemfile", "Rakefile", "config.ru"],
@@ -157,6 +158,7 @@ export const languageLoaders = {
157158
pug: () => import("./languages/pug").then((module) => module.pug),
158159
python: () => import("./languages/python").then((module) => module.python),
159160
r: () => import("./languages/r").then((module) => module.r),
161+
razor: () => import("./languages/razor").then((module) => module.razor),
160162
ruby: () => import("./languages/ruby").then((module) => module.ruby),
161163
rust: () => import("./languages/rust").then((module) => module.rust),
162164
scala: () => import("./languages/scala").then((module) => module.scala),

src/languages/razor.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import type { Language } from "../types";
2+
3+
export const razor = {
4+
slug: "razor",
5+
publishedDate: "2010-07-01",
6+
extensions: [".cshtml", ".razor"],
7+
author: "Microsoft",
8+
website: "https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor",
9+
paradigms: ["templating", "component-based", "server-side", "declarative"],
10+
tooling: {
11+
runtimes: ["ASP.NET Core", ".NET", "Blazor"],
12+
packageManagers: ["NuGet"],
13+
ecosystems: [".NET", "ASP.NET Core", "Web", "Blazor"],
14+
},
15+
version: "10.0.8",
16+
logo: "https://cdn.simpleicons.org/dotnet/512BD4",
17+
i18n: {
18+
en: {
19+
name: "Razor",
20+
description:
21+
"Microsoft's markup syntax for ASP.NET Core views, Razor Pages, and Blazor components.",
22+
longDescription:
23+
"Razor is a markup syntax and templating language used by ASP.NET Core to combine HTML with C# expressions, directives, layouts, tag helpers, components, and server-side or interactive rendering logic.\n\nIt is used in MVC views, Razor Pages, Razor Class Libraries, and Blazor components. Razor files commonly define page templates, reusable UI components, forms, layouts, routing, component parameters, and bindings within .NET web applications.",
24+
},
25+
es: {
26+
name: "Razor",
27+
description:
28+
"La sintaxis de marcado de Microsoft para vistas ASP.NET Core, Razor Pages y componentes Blazor.",
29+
longDescription:
30+
"Razor es una sintaxis de marcado y lenguaje de templates usado por ASP.NET Core para combinar HTML con expresiones C#, directivas, layouts, tag helpers, componentes y logica de renderizado server-side o interactiva.\n\nSe usa en vistas MVC, Razor Pages, Razor Class Libraries y componentes Blazor. Los archivos Razor suelen definir templates de paginas, componentes UI reutilizables, formularios, layouts, routing, parametros de componentes y bindings dentro de aplicaciones web .NET.",
31+
},
32+
},
33+
} satisfies Language;

tests/detect.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
meson,
2323
metal,
2424
perl,
25+
razor,
2526
ruby,
2627
svelte,
2728
svn,
@@ -141,6 +142,11 @@ describe("detectLanguage", () => {
141142
expect(detectLanguage("lib/App/CLI.pm")).toBe(perl);
142143
});
143144

145+
it("detects Razor views and components", () => {
146+
expect(detectLanguage("Views/Home/Index.cshtml")).toBe(razor);
147+
expect(detectLanguage("Components/App.razor")).toBe(razor);
148+
});
149+
144150
it("handles nested paths and case-insensitive names", () => {
145151
expect(detectLanguage("packages/api/DOCKERFILE")).toBe(dockerfile);
146152
});

tests/languages/razor.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { describe, it } from "vitest";
2+
import { razor } from "../../src/languages/razor";
3+
import { expectValidLanguage } from "../language-contract";
4+
5+
describe("razor", () => {
6+
it("satisfies the Language contract", () => {
7+
expectValidLanguage(razor, "razor");
8+
});
9+
});

0 commit comments

Comments
 (0)