Team Ai
Datasetpublic

Brunobkr/llama.cpp_AlgMor24_github

ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
index.js483 linesDownload Raw Back to lib
1/**2 * @import {ElementContent, Element, RootData, Root} from 'hast'3 * @import {Emitter, HLJSOptions as HljsOptions, HighlightResult, LanguageFn} from 'highlight.js'4 */5 6/**7 * @typedef {Object} ExtraOptions8 *   Extra fields.9 * @property {ReadonlyArray<string> | null | undefined} [subset]10 *   List of allowed languages (default: all registered languages).11 *12 * @typedef Options13 *   Configuration for `highlight`.14 * @property {string | null | undefined} [prefix='hljs-']15 *   Class prefix (default: `'hljs-'`).16 *17 * @typedef {Options & ExtraOptions} AutoOptions18 *   Configuration for `highlightAuto`.19 */20 21import {ok as assert} from 'devlop'22import HighlightJs from 'highlight.js/lib/core'23 24/** @type {AutoOptions} */25const emptyOptions = {}26 27const defaultPrefix = 'hljs-'28 29/**30 * Create a `lowlight` instance.31 *32 * @param {Readonly<Record<string, LanguageFn>> | null | undefined} [grammars]33 *   Grammars to add (optional).34 * @returns35 *   Lowlight.36 */37export function createLowlight(grammars) {38  const high = HighlightJs.newInstance()39 40  if (grammars) {41    register(grammars)42  }43 44  return {45    highlight,46    highlightAuto,47    listLanguages,48    register,49    registerAlias,50    registered51  }52 53  /**54   * Highlight `value` (code) as `language` (name).55   *56   * @example57   *   ```js58   *   import {common, createLowlight} from 'lowlight'59   *60   *   const lowlight = createLowlight(common)61   *62   *   console.log(lowlight.highlight('css', 'em { color: red }'))63   *   ```64   *65   *   Yields:66   *67   *   ```js68   *   {type: 'root', children: [Array], data: {language: 'css', relevance: 3}}69   *   ```70   *71   * @param {string} language72   *   Programming language name.73   * @param {string} value74   *   Code to highlight.75   * @param {Readonly<Options> | null | undefined} [options={}]76   *   Configuration (optional).77   * @returns {Root}78   *   Tree; with the following `data` fields: `language` (`string`), detected79   *   programming language name; `relevance` (`number`), how sure lowlight is80   *   that the given code is in the language.81   */82  function highlight(language, value, options) {83    assert(typeof language === 'string', 'expected `string` as `name`')84    assert(typeof value === 'string', 'expected `string` as `value`')85    const settings = options || emptyOptions86    const prefix =87      typeof settings.prefix === 'string' ? settings.prefix : defaultPrefix88 89    if (!high.getLanguage(language)) {90      throw new Error('Unknown language: `' + language + '` is not registered')91    }92 93    // See: <https://github.com/highlightjs/highlight.js/issues/3621#issuecomment-1528841888>94    high.configure({__emitter: HastEmitter, classPrefix: prefix})95 96    const result = /** @type {HighlightResult & {_emitter: HastEmitter}} */ (97      high.highlight(value, {ignoreIllegals: true, language})98    )99 100    // `highlight.js` seems to use this (currently) for broken grammars, so let’s101    // keep it in there just to be sure.102    /* c8 ignore next 5 */103    if (result.errorRaised) {104      throw new Error('Could not highlight with `Highlight.js`', {105        cause: result.errorRaised106      })107    }108 109    const root = result._emitter.root110 111    // Cast because it is always defined.112    const data = /** @type {RootData} */ (root.data)113 114    data.language = result.language115    data.relevance = result.relevance116 117    return root118  }119 120  /**121   * Highlight `value` (code) and guess its programming language.122   *123   * @example124   *   ```js125   *   import {common, createLowlight} from 'lowlight'126   *127   *   const lowlight = createLowlight(common)128   *129   *   console.log(lowlight.highlightAuto('"hello, " + name + "!"'))130   *   ```131   *132   *   Yields:133   *134   *   ```js135   *   {type: 'root', children: [Array], data: {language: 'arduino', relevance: 2}}136   *   ```137   *138   * @param {string} value139   *   Code to highlight.140   * @param {Readonly<AutoOptions> | null | undefined} [options={}]141   *   Configuration (optional).142   * @returns {Root}143   *   Tree; with the following `data` fields: `language` (`string`), detected144   *   programming language name; `relevance` (`number`), how sure lowlight is145   *   that the given code is in the language.146   */147  function highlightAuto(value, options) {148    assert(typeof value === 'string', 'expected `string` as `value`')149    const settings = options || emptyOptions150    const subset = settings.subset || listLanguages()151 152    let index = -1153    let relevance = 0154    /** @type {Root | undefined} */155    let result156 157    while (++index < subset.length) {158      const name = subset[index]159 160      if (!high.getLanguage(name)) continue161 162      const current = highlight(name, value, options)163 164      if (165        current.data &&166        current.data.relevance !== undefined &&167        current.data.relevance > relevance168      ) {169        relevance = current.data.relevance170        result = current171      }172    }173 174    return (175      result || {176        type: 'root',177        children: [],178        data: {language: undefined, relevance}179      }180    )181  }182 183  /**184   * List registered languages.185   *186   * @example187   *   ```js188   *   import {createLowlight} from 'lowlight'189   *   import markdown from 'highlight.js/lib/languages/markdown'190   *191   *   const lowlight = createLowlight()192   *193   *   console.log(lowlight.listLanguages()) // => []194   *195   *   lowlight.register({markdown})196   *197   *   console.log(lowlight.listLanguages()) // => ['markdown']198   *   ```199   *200   * @returns {Array<string>}201   *   Names of registered language.202   */203  function listLanguages() {204    return high.listLanguages()205  }206 207  /**208   * Register languages.209   *210   * @example211   *   ```js212   *   import {createLowlight} from 'lowlight'213   *   import xml from 'highlight.js/lib/languages/xml'214   *215   *   const lowlight = createLowlight()216   *217   *   lowlight.register({xml})218   *219   *   // Note: `html` is an alias for `xml`.220   *   console.log(lowlight.highlight('html', '<em>Emphasis</em>'))221   *   ```222   *223   *   Yields:224   *225   *   ```js226   *   {type: 'root', children: [Array], data: {language: 'html', relevance: 2}}227   *   ```228   *229   * @overload230   * @param {Readonly<Record<string, LanguageFn>>} grammars231   * @returns {undefined}232   *233   * @overload234   * @param {string} name235   * @param {LanguageFn} grammar236   * @returns {undefined}237   *238   * @param {Readonly<Record<string, LanguageFn>> | string} grammarsOrName239   *   Grammars or programming language name.240   * @param {LanguageFn | undefined} [grammar]241   *   Grammar, if with name.242   * @returns {undefined}243   *   Nothing.244   */245  function register(grammarsOrName, grammar) {246    if (typeof grammarsOrName === 'string') {247      assert(grammar !== undefined, 'expected `grammar`')248      high.registerLanguage(grammarsOrName, grammar)249    } else {250      /** @type {string} */251      let name252 253      for (name in grammarsOrName) {254        if (Object.hasOwn(grammarsOrName, name)) {255          high.registerLanguage(name, grammarsOrName[name])256        }257      }258    }259  }260 261  /**262   * Register aliases.263   *264   * @example265   *   ```js266   *   import {createLowlight} from 'lowlight'267   *   import markdown from 'highlight.js/lib/languages/markdown'268   *269   *   const lowlight = createLowlight()270   *271   *   lowlight.register({markdown})272   *273   *   // lowlight.highlight('mdown', '<em>Emphasis</em>')274   *   // ^ would throw: Error: Unknown language: `mdown` is not registered275   *276   *   lowlight.registerAlias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']})277   *   lowlight.highlight('mdown', '<em>Emphasis</em>')278   *   // ^ Works!279   *   ```280   *281   * @overload282   * @param {Readonly<Record<string, ReadonlyArray<string> | string>>} aliases283   * @returns {undefined}284   *285   * @overload286   * @param {string} language287   * @param {ReadonlyArray<string> | string} alias288   * @returns {undefined}289   *290   * @param {Readonly<Record<string, ReadonlyArray<string> | string>> | string} aliasesOrName291   *   Map of programming language names to one or more aliases, or programming292   *   language name.293   * @param {ReadonlyArray<string> | string | undefined} [alias]294   *   One or more aliases for the programming language, if with `name`.295   * @returns {undefined}296   *   Nothing.297   */298  function registerAlias(aliasesOrName, alias) {299    if (typeof aliasesOrName === 'string') {300      assert(alias !== undefined)301      high.registerAliases(302        // Note: copy needed because hljs doesn’t accept readonly arrays yet.303        typeof alias === 'string' ? alias : [...alias],304        {languageName: aliasesOrName}305      )306    } else {307      /** @type {string} */308      let key309 310      for (key in aliasesOrName) {311        if (Object.hasOwn(aliasesOrName, key)) {312          const aliases = aliasesOrName[key]313          high.registerAliases(314            // Note: copy needed because hljs doesn’t accept readonly arrays yet.315            typeof aliases === 'string' ? aliases : [...aliases],316            {languageName: key}317          )318        }319      }320    }321  }322 323  /**324   * Check whether an alias or name is registered.325   *326   * @example327   *   ```js328   *   import {createLowlight} from 'lowlight'329   *   import javascript from 'highlight.js/lib/languages/javascript'330   *331   *   const lowlight = createLowlight({javascript})332   *333   *   console.log(lowlight.registered('funkyscript')) // => `false`334   *335   *   lowlight.registerAlias({javascript: 'funkyscript'})336   *   console.log(lowlight.registered('funkyscript')) // => `true`337   *   ```338   *339   * @param {string} aliasOrName340   *   Name of a language or alias for one.341   * @returns {boolean}342   *   Whether `aliasOrName` is registered.343   */344  function registered(aliasOrName) {345    return Boolean(high.getLanguage(aliasOrName))346  }347}348 349/** @type {Emitter} */350class HastEmitter {351  /**352   * @param {Readonly<HljsOptions>} options353   *   Configuration.354   * @returns355   *   Instance.356   */357  constructor(options) {358    /** @type {HljsOptions} */359    this.options = options360    /** @type {Root} */361    this.root = {362      type: 'root',363      children: [],364      data: {language: undefined, relevance: 0}365    }366    /** @type {[Root, ...Array<Element>]} */367    this.stack = [this.root]368  }369 370  /**371   * @param {string} value372   *   Text to add.373   * @returns {undefined}374   *   Nothing.375   *376   */377  addText(value) {378    if (value === '') return379 380    const current = this.stack[this.stack.length - 1]381    const tail = current.children[current.children.length - 1]382 383    if (tail && tail.type === 'text') {384      tail.value += value385    } else {386      current.children.push({type: 'text', value})387    }388  }389 390  /**391   *392   * @param {unknown} rawName393   *   Name to add.394   * @returns {undefined}395   *   Nothing.396   */397  startScope(rawName) {398    this.openNode(String(rawName))399  }400 401  /**402   * @returns {undefined}403   *   Nothing.404   */405  endScope() {406    this.closeNode()407  }408 409  /**410   * @param {HastEmitter} other411   *   Other emitter.412   * @param {string} name413   *   Name of the sublanguage.414   * @returns {undefined}415   *   Nothing.416   */417  __addSublanguage(other, name) {418    const current = this.stack[this.stack.length - 1]419    // Assume only element content.420    const results = /** @type {Array<ElementContent>} */ (other.root.children)421 422    if (name) {423      current.children.push({424        type: 'element',425        tagName: 'span',426        properties: {className: [name]},427        children: results428      })429    } else {430      current.children.push(...results)431    }432  }433 434  /**435   * @param {string} name436   *   Name to add.437   * @returns {undefined}438   *   Nothing.439   */440  openNode(name) {441    const self = this442    // First “class” gets the prefix. Rest gets a repeated underscore suffix.443    // See: <https://github.com/highlightjs/highlight.js/commit/51806aa>444    // See: <https://github.com/wooorm/lowlight/issues/43>445    const className = name.split('.').map(function (d, i) {446      return i ? d + '_'.repeat(i) : self.options.classPrefix + d447    })448    const current = this.stack[this.stack.length - 1]449    /** @type {Element} */450    const child = {451      type: 'element',452      tagName: 'span',453      properties: {className},454      children: []455    }456 457    current.children.push(child)458    this.stack.push(child)459  }460 461  /**462   * @returns {undefined}463   *   Nothing.464   */465  closeNode() {466    this.stack.pop()467  }468 469  /**470   * @returns {undefined}471   *   Nothing.472   */473  finalize() {}474 475  /**476   * @returns {string}477   *   Nothing.478   */479  toHTML() {480    return ''481  }482}483 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai