-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from akvelon/issue48_generateMode-typescript
Migrate generateMode() function to TypeScript (#48)
- Loading branch information
Showing
3 changed files
with
141 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import hljs from "highlight.js"; | ||
|
||
import { Mode } from "./types.js"; | ||
|
||
// Map of all modes exported from HighlightJS. | ||
export const commonModes = importCommonModes(); | ||
|
||
function importCommonModes(): Map<string, Mode> { | ||
const allExported = Object.entries(hljs); | ||
const modeArray = allExported.filter(([key, value]) => isMode(key, value)); | ||
return new Map<string, Mode>(modeArray as [string, Mode][]); | ||
} | ||
|
||
function isMode(key: string, value: any): boolean { | ||
// SCREAMING_CAPS only. | ||
if (!/^[A-Z][_0-9A-Z]*$/.test(key)) { | ||
return false; | ||
} | ||
|
||
if (key.endsWith("_RE")) { | ||
return false; | ||
} | ||
|
||
if (typeof value === "function") { | ||
return false; | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters