mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
Add more syntax highlighting grammars
Also adds a convenience function for adding them
This commit is contained in:
@@ -68,28 +68,23 @@ function pageResolver(pageName) {
|
|||||||
const slug = slugify(pageName, { lower: true });
|
const slug = slugify(pageName, { lower: true });
|
||||||
return ["/", "/projects/"].map((p) => p + slug);
|
return ["/", "/projects/"].map((p) => p + slug);
|
||||||
}
|
}
|
||||||
// import { grammars } from 'tm-grammars'
|
import { grammars } from 'tm-grammars'
|
||||||
// console.log()
|
// console.log()
|
||||||
// let http = grammars.find((grammar) => grammar.name == "json")
|
|
||||||
// console.log(http)
|
/**
|
||||||
// import httpGrammar from 'tm-grammars/grammars/http.json' assert { type: "json" };
|
* @param {string} name
|
||||||
// @ts-ignore
|
*/
|
||||||
// http.grammar = httpGrammar;
|
function getGrammar(name) {
|
||||||
// console.log(import.meta.resolve('tm-grammars/grammars/http.json'))
|
let metadata = grammars.find((grammar) => grammar.name == name)
|
||||||
const httpHighlight = {
|
if (!metadata) {
|
||||||
id: 'http',
|
throw "Grammar not found"
|
||||||
// aliases: ['http', "https"],
|
}
|
||||||
grammar: JSON.parse(readFileSync(fileURLToPath(import.meta.resolve('tm-grammars/grammars/http.json')), 'utf8')),
|
return {
|
||||||
categories: ['web', 'utility'],
|
...metadata,
|
||||||
displayName: 'HTTP',
|
id: name,
|
||||||
embedded: ['shellscript', 'json', 'xml', 'graphql'],
|
|
||||||
lastUpdate: '2023-07-24T09:58:17Z',
|
grammar: JSON.parse(readFileSync(fileURLToPath(import.meta.resolve('tm-grammars/grammars/' + name + '.json')), 'utf8')),
|
||||||
license: 'MIT',
|
}
|
||||||
licenseUrl: 'https://raw.githubusercontent.com/Huachao/vscode-restclient/master/LICENSE',
|
|
||||||
name: 'http',
|
|
||||||
scopeName: 'source.http',
|
|
||||||
sha: 'a89f8bce1b5e3d5bd955f10916b0c101e20431d3',
|
|
||||||
source: 'https://github.com/Huachao/vscode-restclient/blob/a89f8bce1b5e3d5bd955f10916b0c101e20431d3/syntaxes/http.tmLanguage.json',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const hrefTemplate = (/** @type {string} */ permalink) => permalink
|
const hrefTemplate = (/** @type {string} */ permalink) => permalink
|
||||||
@@ -109,7 +104,13 @@ const hrefTemplate = (/** @type {string} */ permalink) => permalink
|
|||||||
// }]
|
// }]
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
|
/**
|
||||||
|
* @param {{level: number, title: string}[]} headings
|
||||||
|
*/
|
||||||
function buildNestedHeadings(headings) {
|
function buildNestedHeadings(headings) {
|
||||||
|
/**
|
||||||
|
* @type {{level: number, title: string, children: unknown}[]}
|
||||||
|
*/
|
||||||
let result = [];
|
let result = [];
|
||||||
let stack = [{ level: 0, children: result }];
|
let stack = [{ level: 0, children: result }];
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ function add_toc_remark(opts) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_data_to_fm(opts) {
|
function add_data_to_fm(_opts) {
|
||||||
return async function transformer(tree, vFile) {
|
return async function transformer(tree, vFile) {
|
||||||
if (!vFile.data.fm) vFile.data.fm = {};
|
if (!vFile.data.fm) vFile.data.fm = {};
|
||||||
|
|
||||||
@@ -325,7 +326,7 @@ const config = {
|
|||||||
|
|
||||||
highlight: {
|
highlight: {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
highlighter: await createHighlighter({ theme: "github-dark", langs: [httpHighlight] }),
|
highlighter: await createHighlighter({ theme: "github-dark", langs: ["http", "jsx", "javascript", "typescript", "rust"].map(getGrammar) }),
|
||||||
alias: {
|
alias: {
|
||||||
ts: "typescript",
|
ts: "typescript",
|
||||||
mdx: "markdown",
|
mdx: "markdown",
|
||||||
|
|||||||
Reference in New Issue
Block a user