forked from sashin/sashinexists
run npm install to generate a package lock
This commit is contained in:
21
node_modules/marked-highlight/LICENSE
generated
vendored
Normal file
21
node_modules/marked-highlight/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 @markedjs
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
90
node_modules/marked-highlight/README.md
generated
vendored
Normal file
90
node_modules/marked-highlight/README.md
generated
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
# marked-highlight
|
||||
|
||||
Highlight code blocks
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install marked-highlight
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
You will need to provide a function that transforms the `code` to html.
|
||||
|
||||
```js
|
||||
import { Marked } from "marked";
|
||||
import { markedHighlight } from "marked-highlight";
|
||||
import hljs from 'highlight.js';
|
||||
|
||||
// or UMD script
|
||||
// <script src="https://cdn.jsdelivr.net/npm/marked/lib/marked.umd.js"></script>
|
||||
// <script src="https://cdn.jsdelivr.net/npm/marked-highlight/lib/index.umd.js"></script>
|
||||
// const {markedHighlight} = globalThis.markedHighlight;
|
||||
const marked = new Marked(
|
||||
markedHighlight({
|
||||
langPrefix: 'hljs language-',
|
||||
highlight(code, lang, info) {
|
||||
const language = hljs.getLanguage(lang) ? lang : 'plaintext';
|
||||
return hljs.highlight(code, { language }).value;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
marked.parse(`
|
||||
\`\`\`javascript
|
||||
const highlight = "code";
|
||||
\`\`\`
|
||||
`);
|
||||
// <pre><code class="hljs language-javascript">
|
||||
// <span class="hljs-keyword">const</span> highlight = <span class="hljs-string">"code"</span>;
|
||||
// </code></pre>
|
||||
```
|
||||
|
||||
The `async` option should be set to `true` if the `highlight` function returns a `Promise`.
|
||||
|
||||
```js
|
||||
import { Marked } from "marked";
|
||||
import { markedHighlight } from "marked-highlight";
|
||||
import pygmentize from 'pygmentize-bundled';
|
||||
|
||||
const marked = new Marked(
|
||||
markedHighlight({
|
||||
async: true,
|
||||
highlight(code, lang, info) {
|
||||
return new Promise((resolve, reject) => {
|
||||
pygmentize({ lang, format: 'html' }, code, function (err, result) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(result.toString());
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
await marked.parse(`
|
||||
\`\`\`javascript
|
||||
const highlight = "code";
|
||||
\`\`\`
|
||||
`);
|
||||
// <pre><code class="language-javascript">
|
||||
// <div class="highlight">
|
||||
// <pre>
|
||||
// <span class="kr">const</span> <span class="nx">highlight</span> <span class="o">=</span> <span class="s2">"code"</span><span class="p">;</span>
|
||||
// </pre>
|
||||
// </div>
|
||||
// </code></pre>
|
||||
```
|
||||
|
||||
### `options`
|
||||
|
||||
| option | type | default | description |
|
||||
|--------|--------|---------|:------------|
|
||||
| async | boolean | `false` | If the highlight function returns a promise set this to `true`. Don't forget to `await` the call to `marked.parse` |
|
||||
| langPrefix | string | `'language-'` | A prefix to add to the class of the `code` tag. |
|
||||
| highlight | function | `(code: string, lang: string) => {}` | Required. The function to transform the code to html. |
|
||||
97
node_modules/marked-highlight/lib/index.cjs
generated
vendored
Normal file
97
node_modules/marked-highlight/lib/index.cjs
generated
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
'use strict';
|
||||
|
||||
function markedHighlight(options) {
|
||||
if (typeof options === 'function') {
|
||||
options = {
|
||||
highlight: options,
|
||||
};
|
||||
}
|
||||
|
||||
if (!options || typeof options.highlight !== 'function') {
|
||||
throw new Error('Must provide highlight function');
|
||||
}
|
||||
|
||||
if (typeof options.langPrefix !== 'string') {
|
||||
options.langPrefix = 'language-';
|
||||
}
|
||||
|
||||
return {
|
||||
async: !!options.async,
|
||||
walkTokens(token) {
|
||||
if (token.type !== 'code') {
|
||||
return;
|
||||
}
|
||||
|
||||
const lang = getLang(token.lang);
|
||||
|
||||
if (options.async) {
|
||||
return Promise.resolve(options.highlight(token.text, lang, token.lang || '')).then(updateToken(token));
|
||||
}
|
||||
|
||||
const code = options.highlight(token.text, lang, token.lang || '');
|
||||
if (code instanceof Promise) {
|
||||
throw new Error('markedHighlight is not set to async but the highlight function is async. Set the async option to true on markedHighlight to await the async highlight function.');
|
||||
}
|
||||
updateToken(token)(code);
|
||||
},
|
||||
useNewRenderer: true,
|
||||
renderer: {
|
||||
code(code, infoString, escaped) {
|
||||
// istanbul ignore next
|
||||
if (typeof code === 'object') {
|
||||
escaped = code.escaped;
|
||||
infoString = code.lang;
|
||||
code = code.text;
|
||||
}
|
||||
const lang = getLang(infoString);
|
||||
const classAttr = lang
|
||||
? ` class="${options.langPrefix}${escape(lang)}"`
|
||||
: '';
|
||||
code = code.replace(/\n$/, '');
|
||||
return `<pre><code${classAttr}>${escaped ? code : escape(code, true)}\n</code></pre>`;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function getLang(lang) {
|
||||
return (lang || '').match(/\S*/)[0];
|
||||
}
|
||||
|
||||
function updateToken(token) {
|
||||
return (code) => {
|
||||
if (typeof code === 'string' && code !== token.text) {
|
||||
token.escaped = true;
|
||||
token.text = code;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// copied from marked helpers
|
||||
const escapeTest = /[&<>"']/;
|
||||
const escapeReplace = new RegExp(escapeTest.source, 'g');
|
||||
const escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
|
||||
const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
|
||||
const escapeReplacements = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
};
|
||||
const getEscapeReplacement = (ch) => escapeReplacements[ch];
|
||||
function escape(html, encode) {
|
||||
if (encode) {
|
||||
if (escapeTest.test(html)) {
|
||||
return html.replace(escapeReplace, getEscapeReplacement);
|
||||
}
|
||||
} else {
|
||||
if (escapeTestNoEncode.test(html)) {
|
||||
return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
|
||||
}
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
exports.markedHighlight = markedHighlight;
|
||||
103
node_modules/marked-highlight/lib/index.umd.js
generated
vendored
Normal file
103
node_modules/marked-highlight/lib/index.umd.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.markedHighlight = {}));
|
||||
})(this, (function (exports) { 'use strict';
|
||||
|
||||
function markedHighlight(options) {
|
||||
if (typeof options === 'function') {
|
||||
options = {
|
||||
highlight: options,
|
||||
};
|
||||
}
|
||||
|
||||
if (!options || typeof options.highlight !== 'function') {
|
||||
throw new Error('Must provide highlight function');
|
||||
}
|
||||
|
||||
if (typeof options.langPrefix !== 'string') {
|
||||
options.langPrefix = 'language-';
|
||||
}
|
||||
|
||||
return {
|
||||
async: !!options.async,
|
||||
walkTokens(token) {
|
||||
if (token.type !== 'code') {
|
||||
return;
|
||||
}
|
||||
|
||||
const lang = getLang(token.lang);
|
||||
|
||||
if (options.async) {
|
||||
return Promise.resolve(options.highlight(token.text, lang, token.lang || '')).then(updateToken(token));
|
||||
}
|
||||
|
||||
const code = options.highlight(token.text, lang, token.lang || '');
|
||||
if (code instanceof Promise) {
|
||||
throw new Error('markedHighlight is not set to async but the highlight function is async. Set the async option to true on markedHighlight to await the async highlight function.');
|
||||
}
|
||||
updateToken(token)(code);
|
||||
},
|
||||
useNewRenderer: true,
|
||||
renderer: {
|
||||
code(code, infoString, escaped) {
|
||||
// istanbul ignore next
|
||||
if (typeof code === 'object') {
|
||||
escaped = code.escaped;
|
||||
infoString = code.lang;
|
||||
code = code.text;
|
||||
}
|
||||
const lang = getLang(infoString);
|
||||
const classAttr = lang
|
||||
? ` class="${options.langPrefix}${escape(lang)}"`
|
||||
: '';
|
||||
code = code.replace(/\n$/, '');
|
||||
return `<pre><code${classAttr}>${escaped ? code : escape(code, true)}\n</code></pre>`;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function getLang(lang) {
|
||||
return (lang || '').match(/\S*/)[0];
|
||||
}
|
||||
|
||||
function updateToken(token) {
|
||||
return (code) => {
|
||||
if (typeof code === 'string' && code !== token.text) {
|
||||
token.escaped = true;
|
||||
token.text = code;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// copied from marked helpers
|
||||
const escapeTest = /[&<>"']/;
|
||||
const escapeReplace = new RegExp(escapeTest.source, 'g');
|
||||
const escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
|
||||
const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
|
||||
const escapeReplacements = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
};
|
||||
const getEscapeReplacement = (ch) => escapeReplacements[ch];
|
||||
function escape(html, encode) {
|
||||
if (encode) {
|
||||
if (escapeTest.test(html)) {
|
||||
return html.replace(escapeReplace, getEscapeReplacement);
|
||||
}
|
||||
} else {
|
||||
if (escapeTestNoEncode.test(html)) {
|
||||
return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
|
||||
}
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
|
||||
exports.markedHighlight = markedHighlight;
|
||||
|
||||
}));
|
||||
76
node_modules/marked-highlight/package.json
generated
vendored
Normal file
76
node_modules/marked-highlight/package.json
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
{
|
||||
"name": "marked-highlight",
|
||||
"version": "2.1.4",
|
||||
"description": "marked highlight",
|
||||
"main": "./lib/index.cjs",
|
||||
"module": "./src/index.js",
|
||||
"browser": "./lib/index.umd.js",
|
||||
"types": "./src/index.d.ts",
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
"marked",
|
||||
"extension",
|
||||
"highlight"
|
||||
],
|
||||
"files": [
|
||||
"lib/",
|
||||
"src/"
|
||||
],
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./src/index.d.ts",
|
||||
"import": "./src/index.js",
|
||||
"require": "./lib/index.cjs"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest --verbose",
|
||||
"test:cover": "jest --coverage",
|
||||
"test:types": "tsd -t src/index.d.ts -f types_test/index.test-d.ts",
|
||||
"lint": "eslint",
|
||||
"build": "rollup -c rollup.config.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/markedjs/marked-highlight.git"
|
||||
},
|
||||
"author": "Tony Brix <Tony@Brix.ninja> (https://Tony.Brix.ninja)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/markedjs/marked-highlight/issues"
|
||||
},
|
||||
"homepage": "https://github.com/markedjs/marked-highlight#readme",
|
||||
"peerDependencies": {
|
||||
"marked": ">=4 <15"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.25.2",
|
||||
"@babel/preset-env": "^7.25.3",
|
||||
"@markedjs/eslint-config": "^1.0.1",
|
||||
"@semantic-release/changelog": "^6.0.3",
|
||||
"@semantic-release/commit-analyzer": "^13.0.0",
|
||||
"@semantic-release/git": "^10.0.1",
|
||||
"@semantic-release/github": "^10.1.3",
|
||||
"@semantic-release/npm": "^12.0.1",
|
||||
"@semantic-release/release-notes-generator": "^14.0.1",
|
||||
"babel-jest": "^29.7.0",
|
||||
"eslint": "^9.8.0",
|
||||
"globals": "^15.9.0",
|
||||
"highlight.js": "^11.10.0",
|
||||
"jest-cli": "^29.7.0",
|
||||
"marked": "^14.0.0",
|
||||
"pygmentize-bundled": "^2.3.0",
|
||||
"rollup": "^4.20.0",
|
||||
"semantic-release": "^24.0.0",
|
||||
"tsd": "^0.31.1"
|
||||
},
|
||||
"tsd": {
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"marked-highlight": [
|
||||
"./src"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
91
node_modules/marked-highlight/src/index.d.ts
generated
vendored
Normal file
91
node_modules/marked-highlight/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
declare module 'marked-highlight' {
|
||||
/**
|
||||
* A synchronous function to highlight code
|
||||
*
|
||||
* @param code The raw code to be highlighted
|
||||
* @param language The language tag found immediately after the code block
|
||||
* opening marker (e.g. ```typescript -> language='typescript')
|
||||
* @param info The full string after the code block opening marker
|
||||
* (e.g. ```ts twoslash -> info='ts twoslash')
|
||||
* @return The highlighted code as a HTML string
|
||||
*/
|
||||
type SyncHighlightFunction = (code: string, language: string, info: string) => string;
|
||||
|
||||
/**
|
||||
* An asynchronous function to highlight code
|
||||
*
|
||||
* @param code The raw code to be highlighted
|
||||
* @param language The language tag found immediately after the code block
|
||||
* opening marker (e.g. ```typescript -> language='typescript')
|
||||
* @param info The full string after the code block opening marker
|
||||
* (e.g. ```ts twoslash -> info='ts twoslash')
|
||||
* @return A Promise for the highlighted code as a HTML string
|
||||
*/
|
||||
type AsyncHighlightFunction = (code: string, language: string, info: string) => Promise<string>;
|
||||
|
||||
/**
|
||||
* Options for configuring the marked-highlight extension using a synchronous
|
||||
* highlighting function.
|
||||
*/
|
||||
interface SynchronousOptions {
|
||||
/** Function to highlight code with */
|
||||
highlight: SyncHighlightFunction;
|
||||
/**
|
||||
* Not necessary when using a synchronous highlighting function, but can be
|
||||
* set without harm (it will make `marked.parse()` return a promise if true;
|
||||
* pass the {async: true} option to marked.parse() to tell TypeScript this)
|
||||
*/
|
||||
async?: boolean;
|
||||
/**
|
||||
* The language tag found immediately after the code block opening marker is
|
||||
* appended to this to form the class attribute added to the <code> element.
|
||||
*/
|
||||
langPrefix?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options for configuring the marked-highlight extension using an
|
||||
* asynchronous highlighting function.
|
||||
*
|
||||
* Note that the {async: true} option should also be passed to marked.parse()
|
||||
* when using an asynchronous highlighting function to tell TypeScript that it
|
||||
* will return a Promise.
|
||||
*/
|
||||
interface AsynchronousOptions {
|
||||
/** Function to highlight code with */
|
||||
highlight: AsyncHighlightFunction;
|
||||
/** Must be set to true when using an asynchronous highlight function */
|
||||
async: true;
|
||||
/**
|
||||
* The language tag found immediately after the code block opening marker is
|
||||
* appended to this to form the class attribute added to the <code> element.
|
||||
*/
|
||||
langPrefix?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures a marked extension to apply syntax highlighing to code elements.
|
||||
*
|
||||
* @param options Options for the extension
|
||||
* @return A MarkedExtension to be passed to `marked.use()`
|
||||
*/
|
||||
export function markedHighlight(options: SynchronousOptions): import('marked').MarkedExtension;
|
||||
|
||||
/**
|
||||
* Configures a marked extension to apply syntax highlighing to code elements.
|
||||
*
|
||||
* @param options Options for the extension
|
||||
* @return A MarkedExtension to be passed to `marked.use()`
|
||||
*/
|
||||
export function markedHighlight(options: AsynchronousOptions): import('marked').MarkedExtension;
|
||||
|
||||
/**
|
||||
* Configures a marked extension to apply syntax highlighing to code elements.
|
||||
*
|
||||
* @param highlightFunction A synchronous function to apply syntax highlighting
|
||||
* @return A MarkedExtension to be passed to `marked.use()`
|
||||
*/
|
||||
export function markedHighlight(
|
||||
highlightFunction: SyncHighlightFunction
|
||||
): import('marked').MarkedExtension;
|
||||
}
|
||||
93
node_modules/marked-highlight/src/index.js
generated
vendored
Normal file
93
node_modules/marked-highlight/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
export function markedHighlight(options) {
|
||||
if (typeof options === 'function') {
|
||||
options = {
|
||||
highlight: options,
|
||||
};
|
||||
}
|
||||
|
||||
if (!options || typeof options.highlight !== 'function') {
|
||||
throw new Error('Must provide highlight function');
|
||||
}
|
||||
|
||||
if (typeof options.langPrefix !== 'string') {
|
||||
options.langPrefix = 'language-';
|
||||
}
|
||||
|
||||
return {
|
||||
async: !!options.async,
|
||||
walkTokens(token) {
|
||||
if (token.type !== 'code') {
|
||||
return;
|
||||
}
|
||||
|
||||
const lang = getLang(token.lang);
|
||||
|
||||
if (options.async) {
|
||||
return Promise.resolve(options.highlight(token.text, lang, token.lang || '')).then(updateToken(token));
|
||||
}
|
||||
|
||||
const code = options.highlight(token.text, lang, token.lang || '');
|
||||
if (code instanceof Promise) {
|
||||
throw new Error('markedHighlight is not set to async but the highlight function is async. Set the async option to true on markedHighlight to await the async highlight function.');
|
||||
}
|
||||
updateToken(token)(code);
|
||||
},
|
||||
useNewRenderer: true,
|
||||
renderer: {
|
||||
code(code, infoString, escaped) {
|
||||
// istanbul ignore next
|
||||
if (typeof code === 'object') {
|
||||
escaped = code.escaped;
|
||||
infoString = code.lang;
|
||||
code = code.text;
|
||||
}
|
||||
const lang = getLang(infoString);
|
||||
const classAttr = lang
|
||||
? ` class="${options.langPrefix}${escape(lang)}"`
|
||||
: '';
|
||||
code = code.replace(/\n$/, '');
|
||||
return `<pre><code${classAttr}>${escaped ? code : escape(code, true)}\n</code></pre>`;
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function getLang(lang) {
|
||||
return (lang || '').match(/\S*/)[0];
|
||||
}
|
||||
|
||||
function updateToken(token) {
|
||||
return (code) => {
|
||||
if (typeof code === 'string' && code !== token.text) {
|
||||
token.escaped = true;
|
||||
token.text = code;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// copied from marked helpers
|
||||
const escapeTest = /[&<>"']/;
|
||||
const escapeReplace = new RegExp(escapeTest.source, 'g');
|
||||
const escapeTestNoEncode = /[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/;
|
||||
const escapeReplaceNoEncode = new RegExp(escapeTestNoEncode.source, 'g');
|
||||
const escapeReplacements = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": ''',
|
||||
};
|
||||
const getEscapeReplacement = (ch) => escapeReplacements[ch];
|
||||
function escape(html, encode) {
|
||||
if (encode) {
|
||||
if (escapeTest.test(html)) {
|
||||
return html.replace(escapeReplace, getEscapeReplacement);
|
||||
}
|
||||
} else {
|
||||
if (escapeTestNoEncode.test(html)) {
|
||||
return html.replace(escapeReplaceNoEncode, getEscapeReplacement);
|
||||
}
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
Reference in New Issue
Block a user