From 04f69115c9a58cae31650f45abfa03bc35f5bf2d Mon Sep 17 00:00:00 2001 From: Robert McGovern Date: Fri, 3 Feb 2023 02:54:07 +0000 Subject: [PATCH] remove files --- src/HighlightLines.js | 33 ------------------ src/HighlightLinesGroup.js | 68 -------------------------------------- src/PrismLoader.js | 42 ----------------------- src/PrismNormalizeAlias.js | 42 ----------------------- src/getAttributes.js | 62 ---------------------------------- 5 files changed, 247 deletions(-) delete mode 100644 src/HighlightLines.js delete mode 100644 src/HighlightLinesGroup.js delete mode 100644 src/PrismLoader.js delete mode 100644 src/PrismNormalizeAlias.js delete mode 100644 src/getAttributes.js diff --git a/src/HighlightLines.js b/src/HighlightLines.js deleted file mode 100644 index 4aa8312..0000000 --- a/src/HighlightLines.js +++ /dev/null @@ -1,33 +0,0 @@ -class HighlightLines { - constructor(rangeStr) { - this.highlights = this.convertRangeToHash(rangeStr); - } - - convertRangeToHash(rangeStr) { - let hash = {}; - if( !rangeStr ) { - return hash; - } - - let ranges = rangeStr.split(",").map(function(range) { - return range.trim(); - }); - - for(let range of ranges) { - let startFinish = range.split('-'); - let start = parseInt(startFinish[0], 10); - let end = parseInt(startFinish[1] || start, 10); - - for( let j = start, k = end; j<=k; j++ ) { - hash[j] = true; - } - } - return hash; - } - - isHighlighted(lineNumber) { - return !!this.highlights[lineNumber]; - } -} - -module.exports = HighlightLines; diff --git a/src/HighlightLinesGroup.js b/src/HighlightLinesGroup.js deleted file mode 100644 index 47c0aaa..0000000 --- a/src/HighlightLinesGroup.js +++ /dev/null @@ -1,68 +0,0 @@ -const HighlightLines = require("./HighlightLines"); - -class HighlightLinesGroup { - constructor(str, delimiter) { - this.init(str, delimiter); - } - - init(str = "", delimiter = " ") { - this.str = str; - this.delimiter = delimiter; - - let split = str.split(this.delimiter); - this.highlights = new HighlightLines(split.length === 1 ? split[0] : ""); - this.highlightsAdd = new HighlightLines(split.length === 2 ? split[0] : ""); - this.highlightsRemove = new HighlightLines(split.length === 2 ? split[1] : ""); - } - - isHighlighted(lineNumber) { - return this.highlights.isHighlighted(lineNumber); - } - - isHighlightedAdd(lineNumber) { - return this.highlightsAdd.isHighlighted(lineNumber); - } - - isHighlightedRemove(lineNumber) { - return this.highlightsRemove.isHighlighted(lineNumber); - } - - hasTagMismatch(line) { - let startCount = line.split(" or on the line. - // for example, we can’t wrap with - if(this.hasTagMismatch(line)) { - return line; - } - - return before + line + after; - } - - getLineMarkup(lineNumber, line, extraClasses = []) { - let extraClassesStr = (extraClasses.length ? " " + extraClasses.join(" ") : ""); - - if (this.isHighlighted(lineNumber)) { - return this.splitLineMarkup(line, ``, ``); - } - if (this.isHighlightedAdd(lineNumber)) { - return this.splitLineMarkup(line, ``, ``); - } - if (this.isHighlightedRemove(lineNumber)) { - return this.splitLineMarkup(line, ``, ``); - } - - return this.splitLineMarkup( line, ``, ``); - } -} - -module.exports = HighlightLinesGroup; diff --git a/src/PrismLoader.js b/src/PrismLoader.js deleted file mode 100644 index a3515a2..0000000 --- a/src/PrismLoader.js +++ /dev/null @@ -1,42 +0,0 @@ -const Prism = require("prismjs"); -const PrismLoader = require("prismjs/components/index.js"); -// Avoid "Language does not exist: " console logs -PrismLoader.silent = true; - -const PrismAlias = require("./PrismNormalizeAlias"); - -module.exports = function(language) { - let diffRemovedRawName = language; - if(language.startsWith("diff-")) { - diffRemovedRawName = language.substr("diff-".length); - } - // aliasing should ignore diff- - let aliasedName = PrismAlias(diffRemovedRawName); - - if(!Prism.languages[ aliasedName ]) { - PrismLoader(aliasedName); - } - if(!Prism.languages[ aliasedName ]) { - throw new Error(`"${language}" is not a valid Prism.js language for eleventy-plugin-syntaxhighlight`); - } - - if(!language.startsWith("diff-")) { - return Prism.languages[ aliasedName ]; - } - - // language has diff- prefix - let fullLanguageName = `diff-${aliasedName}`; - - if(!Prism.languages.diff) { - PrismLoader("diff"); - // Bundled Plugin - require("prismjs/plugins/diff-highlight/prism-diff-highlight"); - } - - // Store into with aliased keys - // ts -> diff-typescript - // js -> diff-javascript - Prism.languages[ fullLanguageName ] = Prism.languages.diff; - - return Prism.languages[ fullLanguageName ]; -}; diff --git a/src/PrismNormalizeAlias.js b/src/PrismNormalizeAlias.js deleted file mode 100644 index 40e9bb3..0000000 --- a/src/PrismNormalizeAlias.js +++ /dev/null @@ -1,42 +0,0 @@ -const Prism = require("prismjs"); - -const HARDCODED_ALIASES = { - njk: "jinja2", - nunjucks: "jinja2", -}; - -// This was added to make `ts` resolve to `typescript` correctly. -// The Prism loader doesn’t seem to always handle aliasing correctly. -module.exports = function(language) { - try { - // Careful this is not public API stuff: - // https://github.com/PrismJS/prism/issues/2146 - const PrismComponents = require("prismjs/components.json"); - let langs = PrismComponents.languages; - - // Manual override - if(HARDCODED_ALIASES[language]) { - language = HARDCODED_ALIASES[language]; - } - - if(langs[ language ]) { - return language; - } - for(let langName in langs) { - if(Array.isArray(langs[langName].alias)) { - for(let alias of langs[langName].alias) { - if(alias === language) { - return langName; - } - } - } else if(langs[langName].alias === language) { - return langName; - } - } - } catch(e) { - // Couldn’t find the components file, aliases may not resolve correctly - // See https://github.com/11ty/eleventy-plugin-syntaxhighlight/issues/19 - } - - return language; -} diff --git a/src/getAttributes.js b/src/getAttributes.js deleted file mode 100644 index 603c6a5..0000000 --- a/src/getAttributes.js +++ /dev/null @@ -1,62 +0,0 @@ -function attributeEntryToString(attribute, context) { - let [key, value] = attribute; - - if (typeof value === "function") { // Callback must return a string or a number - value = value(context); // Run the provided callback and store the result - } - - if (typeof value !== "string" && typeof value !== "number") { - throw new Error( - `Attribute "${key}" must have, or evaluate to, a value of type string or number, not "${typeof value}".` - ); - } - - return `${key}="${value}"`; -} - -/** - * ## Usage - * The function `getAttributes` is used to convert an object, `attributes`, with HTML attributes as keys and the values as the corresponding HTML attribute's values. - * If it is falsey, an empty string will be returned. - * - * ```js - getAttributes({ - tabindex: 0, - 'data-language': function (context) { return context.language; }, - 'data-otherStuff': 'value' - }) // => ' tabindex="0" data-language="JavaScript" data-otherStuff="value"' - ``` - * - * @param {{[s: string]: string | number}} attributes An object with key-value pairs that represent attributes. - * @param {object} context An object with the current context. - * @param {string} context.content The code to parse and highlight. - * @param {string} context.language The language for the current instance. - * @param {object} context.options The options passed to the syntax highlighter. - * @returns {string} A string containing the above HTML attributes preceded by a single space. - */ -function getAttributes(attributes, context = {}) { - let langClass = context.language ? `language-${context.language}` : ""; - - if (!attributes) { - return langClass ? ` class="${langClass}"` : ""; - } else if (typeof attributes === "object") { - if(!("class" in attributes) && langClass) { - // class attribute should be first in order - let tempAttrs = { class: langClass }; - for(let key in attributes) { - tempAttrs[key] = attributes[key]; - } - attributes = tempAttrs; - } - - const formattedAttributes = Object.entries(attributes).map( - entry => attributeEntryToString(entry, context) - ); - - return formattedAttributes.length ? ` ${formattedAttributes.join(" ")}` : ""; - } else if (typeof attributes === "string") { - throw new Error("Syntax highlighter plugin custom attributes on
 and  must be an object. Received: " + JSON.stringify(attributes));
-  }
-}
-
-module.exports = getAttributes;