Skip to content

Commit

Permalink
Update types and exports
Browse files Browse the repository at this point in the history
  • Loading branch information
noClaps committed Jan 3, 2025
1 parent b2ba18c commit 4674258
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 9 deletions.
1 change: 0 additions & 1 deletion .github/workflows/build-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ jobs:
- run: |
mkdir dist
bun run build --target wasm32-wasip1-threads
echo "/** The type of bundled language used by the Highlight package */\nexport type BundledLanguage = string;" >> dist/index.d.ts
- uses: actions/upload-artifact@v4
with:
path: dist
2 changes: 1 addition & 1 deletion highlight.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { highlight, type BundledLanguage, type Theme } from "./main.ts";
import { highlight, type BundledLanguage, type Theme } from "./index.ts";

const theme: Theme = {
fg: "#fff",
Expand Down
69 changes: 69 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
export { highlight, type Theme } from "./dist/index.js";

/** A list of the languages supported by Highlight. */
export const bundledLanguages = [
// Agda
"agda",
// C
"c",
// C++
"cpp",
"c++",
// CSS
"css",
// Go
"go",
"golang",
// Haskell
"haskell",
"hs",
// HTML
"html",
// Java
"java",
// JavaScript
"javascript",
"js",
"jsx",
// JSDoc
"jsdoc",
// JSON
"json",
// OCaml
"ocaml",
"ml",
"ocaml_interface",
"ocaml_type",
// PHP
"php",
"php_only",
// Python
"python",
"py",
// Ruby
"ruby",
"rb",
// Rust
"rust",
"rs",
// Scala
"scala",
// Shell
"shellscript",
"shell",
"bash",
"zsh",
"sh",
// TypeScript
"typescript",
"ts",
"tsx",
// Plain
"plaintext",
"plain",
"text",
"txt",
] as const;

/** The type of bundled language used by the Highlight package */
export type BundledLanguage = (typeof bundledLanguages)[number];
2 changes: 0 additions & 2 deletions main.ts

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"@napi-rs/wasm-runtime": "^0.2.6",
"@types/bun": "^1.1.14"
},
"exports": "./main.ts",
"exports": "./index.ts",
"files": [
"main.ts",
"index.ts",
"dist",
"LICENSE",
"README.md",
"package.json"
Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ fn escape_html(input: String) -> String {
.replace('>', ">")
}

/// A list of the languages supported by Highlight.
#[napi(js_name = "bundledLanguages")]
pub const BUNDLED_LANGUAGES: [&str; 41] = [
// Agda
"agda",
Expand Down Expand Up @@ -238,7 +236,11 @@ const htmlOutput = highlight(code, "ts", theme);
```
*/
#[napi]
pub fn highlight(code: String, language: String, theme: Option<Theme>) -> String {
pub fn highlight(
code: String,
#[napi(ts_arg_type = "BundledLanguage")] language: String,
theme: Option<Theme>,
) -> String {
if !BUNDLED_LANGUAGES.contains(&language.as_str()) {
panic!("Language {} is not supported by Highlight", language);
}
Expand Down

0 comments on commit 4674258

Please sign in to comment.