Giter VIP home page Giter VIP logo

lowlight's Introduction

lowlight

Build Coverage Downloads Size

Virtual syntax highlighting for virtual DOMs and non-HTML things based on highlight.js.

Contents

What is this?

This package uses highlight.js for syntax highlighting and outputs objects (ASTs) instead of a string of HTML. It can support 190+ programming languages.

When should I use this?

This package is useful when you want to perform syntax highlighting in a place where serialized HTML wouldn’t work or wouldn’t work well. For example, you can use lowlight when you want to show code in a CLI by rendering to ANSI sequences, when you’re using virtual DOM frameworks (such as React or Preact) so that diffing can be performant, or when you’re working with ASTs (rehype).

You can use the similar refractor if you want to use Prism grammars instead. If you’re looking for a really good (but rather heavy) alternative, use starry-night.

Install

This package is ESM only. In Node.js (version 16+), install with npm:

npm install lowlight

In Deno with esm.sh:

import {all, common, createLowlight} from 'https://esm.sh/lowlight@3'

In browsers with esm.sh:

<script type="module">
  import {all, common, createLowlight} from 'https://esm.sh/lowlight@3?bundle'
</script>

Use

import {common, createLowlight} from 'lowlight'

const lowlight = createLowlight(common)

const tree = lowlight.highlight('js', '"use strict";')

console.dir(tree, {depth: undefined})

Yields:

{
  type: 'root',
  children: [
    {
      type: 'element',
      tagName: 'span',
      properties: {className: ['hljs-meta']},
      children: [{type: 'text', value: '"use strict"'}]
    },
    {type: 'text', value: ';'}
  ],
  data: {language: 'js', relevance: 10}
}

API

This package exports the identifiers all, common, and createLowlight. There is no default export.

all

Map of all (±190) grammars (Record<string, LanguageFn>).

common

Map of common (37) grammars (Record<string, LanguageFn>).

createLowlight([grammars])

Create a lowlight instance.

Parameters
Returns

Lowlight (Lowlight).

lowlight.highlight(language, value[, options])

Highlight value (code) as language (name).

Parameters
  • language (string) — programming language name
  • value (string) — code to highlight
  • options (Options, optional) — configuration
Returns

Tree (Root); with the following data fields: language (string), detected programming language name; relevance (number), how sure lowlight is that the given code is in the language.

Example
import {common, createLowlight} from 'lowlight'

const lowlight = createLowlight(common)

console.log(lowlight.highlight('css', 'em { color: red }'))

Yields:

{type: 'root', children: [Array], data: {language: 'css', relevance: 3}}

lowlight.highlightAuto(value[, options])

Highlight value (code) and guess its programming language.

Parameters
  • value (string) — code to highlight
  • options (AutoOptions, optional) — configuration
Returns

Tree (Root); with the following data fields: language (string), detected programming language name; relevance (number), how sure lowlight is that the given code is in the language.

Example
import {common, createLowlight} from 'lowlight'

const lowlight = createLowlight(common)

console.log(lowlight.highlightAuto('"hello, " + name + "!"'))

Yields:

{type: 'root', children: [Array], data: {language: 'arduino', relevance: 2}}

lowlight.listLanguages()

List registered languages.

Returns

Names of registered language (Array<string>).

Example
import {createLowlight} from 'lowlight'
import markdown from 'highlight.js/lib/languages/markdown'

const lowlight = createLowlight()

console.log(lowlight.listLanguages()) // => []

lowlight.register({markdown})

console.log(lowlight.listLanguages()) // => ['markdown']

lowlight.register(grammars)

Register languages.

Signatures
  • register(name, grammar)
  • register(grammars)
Parameters
Returns

Nothing (undefined).

Example
import {createLowlight} from 'lowlight'
import xml from 'highlight.js/lib/languages/xml'

const lowlight = createLowlight()

lowlight.register({xml})

// Note: `html` is an alias for `xml`.
console.log(lowlight.highlight('html', '<em>Emphasis</em>'))

Yields:

{type: 'root', children: [Array], data: {language: 'html', relevance: 2}}

lowlight.registerAlias(aliases)

Register aliases.

Signatures
  • registerAlias(aliases)
  • registerAlias(name, alias)
Parameters
  • aliases (Record<string, Array<string> | string>) — map of programming language names to one or more aliases
  • name (string) — programming language name
  • alias (Array<string> | string) — one or more aliases for the programming language
Returns

Nothing (undefined).

Example
import {createLowlight} from 'lowlight'
import markdown from 'highlight.js/lib/languages/markdown'

const lowlight = createLowlight()

lowlight.register({markdown})

// lowlight.highlight('mdown', '<em>Emphasis</em>')
// ^ would throw: Error: Unknown language: `mdown` is not registered

lowlight.registerAlias({markdown: ['mdown', 'mkdn', 'mdwn', 'ron']})
lowlight.highlight('mdown', '<em>Emphasis</em>')
// ^ Works!

lowlight.registered(aliasOrlanguage)

Check whether an alias or name is registered.

Parameters
  • aliasOrlanguage (string) — name of a language or alias for one
Returns

Whether aliasOrName is registered (boolean).

Example
import {createLowlight} from 'lowlight'
import javascript from 'highlight.js/lib/languages/javascript'

const lowlight = createLowlight({javascript})

console.log(lowlight.registered('funkyscript')) // => `false`

lowlight.registerAlias({javascript: 'funkyscript'})
console.log(lowlight.registered('funkyscript')) // => `true`

AutoOptions

Configuration for highlightAuto (TypeScript type).

Fields
  • prefix (string, default: 'hljs-') — class prefix
  • subset (Array<string>, default: all registered languages) — list of allowed languages

LanguageFn

Highlight.js grammar (TypeScript type).

Type
type {LanguageFn} from 'highlight.js'

Options

Configuration for highlight (TypeScript type).

Fields
  • prefix (string, default: 'hljs-') — class prefix

Examples

Example: serializing hast as html

hast trees as returned by lowlight can be serialized with hast-util-to-html:

import {common, createLowlight} from 'lowlight'
import {toHtml} from 'hast-util-to-html'

const lowlight = createLowlight(common)

const tree = lowlight.highlight('js', '"use strict";')

console.log(toHtml(tree))

Yields:

<span class="hljs-meta">"use strict"</span>;

Example: turning hast into preact, react, etc

hast trees as returned by lowlight can be turned into nodes of any framework that supports JSX, such as preact, react, solid, svelte, vue, and more, with hast-util-to-jsx-runtime:

import {toJsxRuntime} from 'hast-util-to-jsx-runtime'
// @ts-expect-error: react types don’t type these.
import {Fragment, jsx, jsxs} from 'react/jsx-runtime'
import {common, createLowlight} from 'lowlight'

const lowlight = createLowlight(common)

const tree = lowlight.highlight('js', '"use strict";')

console.log(toJsxRuntime(tree, {Fragment, jsx, jsxs}))

Yields:

{
  $$typeof: Symbol(react.element),
  type: Symbol(react.fragment),
  key: null,
  ref: null,
  props: {children: [[Object], ';']},
  _owner: null,
  _store: {}
}

Types

This package is fully typed with TypeScript. It exports the additional types AutoOptions, LanguageFn, and Options.

It also registers root.data with @types/hast. If you’re working with the data fields, make sure to import this package somewhere in your types, as that registers the new fields on the file.

/**
 * @typedef {import('hast').Root} Root
 *
 * @typedef {import('lowlight')}
 */

import {VFile} from 'vfile'

/** @type {Root} */
const root = {type: 'root', children: []}

console.log(root.data?.language) //=> TS now knows that this is a `string?`.

Data

If you’re using createLowlight(), no syntaxes are included yet. You can import all or common and pass them, such as with createLowlight(all). Checked syntaxes are included in common. All syntaxes are included in all.

You can also manually import syntaxes from highlight.js/lib/languages/xxx, where xxx is the name, such as 'highlight.js/lib/languages/wasm'.

  • 1c — 1C:Enterprise
  • abnf — Augmented Backus-Naur Form
  • accesslog — Apache Access Log
  • actionscript (as) — ActionScript
  • ada — Ada
  • angelscript (asc) — AngelScript
  • apache (apacheconf) — Apache config
  • applescript (osascript) — AppleScript
  • arcade — ArcGIS Arcade
  • arduino (ino) — Arduino
  • armasm (arm) — ARM Assembly
  • asciidoc (adoc) — AsciiDoc
  • aspectj — AspectJ
  • autohotkey (ahk) — AutoHotkey
  • autoit — AutoIt
  • avrasm — AVR Assembly
  • awk — Awk
  • axapta (x++) — X++
  • bash (sh) — Bash
  • basic — BASIC
  • bnf — Backus–Naur Form
  • brainfuck (bf) — Brainfuck
  • c (h) — C
  • cal — C/AL
  • capnproto (capnp) — Cap’n Proto
  • ceylon — Ceylon
  • clean (icl, dcl) — Clean
  • clojure (clj, edn) — Clojure
  • clojure-repl — Clojure REPL
  • cmake (cmake.in) — CMake
  • coffeescript (coffee, cson, iced) — CoffeeScript
  • coq — Coq
  • cos (cls) — Caché Object Script
  • cpp (cc, c++, h++, hpp, hh, hxx, cxx) — C++
  • crmsh (crm, pcmk) — crmsh
  • crystal (cr) — Crystal
  • csharp (cs, c#) — C#
  • csp — CSP
  • css — CSS
  • d — D
  • dart — Dart
  • delphi (dpr, dfm, pas, pascal) — Delphi
  • diff (patch) — Diff
  • django (jinja) — Django
  • dns (bind, zone) — DNS Zone
  • dockerfile (docker) — Dockerfile
  • dos (bat, cmd) — Batch file (DOS)
  • dsconfig — undefined
  • dts — Device Tree
  • dust (dst) — Dust
  • ebnf — Extended Backus-Naur Form
  • elixir (ex, exs) — Elixir
  • elm — Elm
  • erb — ERB
  • erlang (erl) — Erlang
  • erlang-repl — Erlang REPL
  • excel (xlsx, xls) — Excel formulae
  • fix — FIX
  • flix — Flix
  • fortran (f90, f95) — Fortran
  • fsharp (fs, f#) — F#
  • gams (gms) — GAMS
  • gauss (gss) — GAUSS
  • gcode (nc) — G-code (ISO 6983)
  • gherkin (feature) — Gherkin
  • glsl — GLSL
  • gml — GML
  • go (golang) — Go
  • golo — Golo
  • gradle — Gradle
  • graphql (gql) — GraphQL
  • groovy — Groovy
  • haml — HAML
  • handlebars (hbs, html.hbs, html.handlebars, htmlbars) — Handlebars
  • haskell (hs) — Haskell
  • haxe (hx) — Haxe
  • hsp — HSP
  • http (https) — HTTP
  • hy (hylang) — Hy
  • inform7 (i7) — Inform 7
  • ini (toml) — TOML, also INI
  • irpf90 — IRPF90
  • isbl — ISBL
  • java (jsp) — Java
  • javascript (js, jsx, mjs, cjs) — JavaScript
  • jboss-cli (wildfly-cli) — JBoss CLI
  • json — JSON
  • julia — Julia
  • julia-repl (jldoctest) — Julia REPL
  • kotlin (kt, kts) — Kotlin
  • lasso (ls, lassoscript) — Lasso
  • latex (tex) — LaTeX
  • ldif — LDIF
  • leaf — Leaf
  • less — Less
  • lisp — Lisp
  • livecodeserver — LiveCode
  • livescript (ls) — LiveScript
  • llvm — LLVM IR
  • lsl — LSL (Linden Scripting Language)
  • lua — Lua
  • makefile (mk, mak, make) — Makefile
  • markdown (md, mkdown, mkd) — Markdown
  • mathematica (mma, wl) — Mathematica
  • matlab — Matlab
  • maxima — Maxima
  • mel — MEL
  • mercury (m, moo) — Mercury
  • mipsasm (mips) — MIPS Assembly
  • mizar — Mizar
  • mojolicious — Mojolicious
  • monkey — Monkey
  • moonscript (moon) — MoonScript
  • n1ql — N1QL
  • nestedtext (nt) — Nested Text
  • nginx (nginxconf) — Nginx config
  • nim — Nim
  • nix (nixos) — Nix
  • node-repl — Node REPL
  • nsis — NSIS
  • objectivec (mm, objc, obj-c, obj-c++, objective-c++) — Objective-C
  • ocaml (ml) — OCaml
  • openscad (scad) — OpenSCAD
  • oxygene — Oxygene
  • parser3 — Parser3
  • perl (pl, pm) — Perl
  • pf (pf.conf) — Packet Filter config
  • pgsql (postgres, postgresql) — PostgreSQL
  • php — undefined
  • php-template — PHP template
  • plaintext (text, txt) — Plain text
  • pony — Pony
  • powershell (pwsh, ps, ps1) — PowerShell
  • processing (pde) — Processing
  • profile — Python profiler
  • prolog — Prolog
  • properties — .properties
  • protobuf (proto) — Protocol Buffers
  • puppet (pp) — Puppet
  • purebasic (pb, pbi) — PureBASIC
  • python (py, gyp, ipython) — Python
  • python-repl (pycon) — undefined
  • q (k, kdb) — Q
  • qml (qt) — QML
  • r — R
  • reasonml (re) — ReasonML
  • rib — RenderMan RIB
  • roboconf (graph, instances) — Roboconf
  • routeros (mikrotik) — MikroTik RouterOS script
  • rsl — RenderMan RSL
  • ruby (rb, gemspec, podspec, thor, irb) — Ruby
  • ruleslanguage — Oracle Rules Language
  • rust (rs) — Rust
  • sas — SAS
  • scala — Scala
  • scheme (scm) — Scheme
  • scilab (sci) — Scilab
  • scss — SCSS
  • shell (console, shellsession) — Shell Session
  • smali — Smali
  • smalltalk (st) — Smalltalk
  • sml (ml) — SML (Standard ML)
  • sqf — SQF
  • sql — SQL
  • stan (stanfuncs) — Stan
  • stata (do, ado) — Stata
  • step21 (p21, step, stp) — STEP Part 21
  • stylus (styl) — Stylus
  • subunit — SubUnit
  • swift — Swift
  • taggerscript — Tagger Script
  • tap — Test Anything Protocol
  • tcl (tk) — Tcl
  • thrift — Thrift
  • tp — TP
  • twig (craftcms) — Twig
  • typescript (ts, tsx, mts, cts) — TypeScript
  • vala — Vala
  • vbnet (vb) — Visual Basic .NET
  • vbscript (vbs) — VBScript
  • vbscript-html — VBScript in HTML
  • verilog (v, sv, svh) — Verilog
  • vhdl — VHDL
  • vim — Vim Script
  • wasm — WebAssembly
  • wren — Wren
  • x86asm — Intel x86 Assembly
  • xl (tao) — XL
  • xml (html, xhtml, rss, atom, xjb, xsd, xsl, plist, wsf, svg) — HTML, XML
  • xquery (xpath, xq, xqm) — XQuery
  • yaml (yml) — YAML
  • zephir (zep) — Zephir

CSS

lowlight does not inject CSS for the syntax highlighted code (because well, lowlight doesn’t have to be turned into HTML and might not run in a browser!). If you are in a browser, you can use any highlight.js theme. For example, to get GitHub Dark from cdnjs:

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">

Compatibility

This package is compatible with maintained versions of Node.js.

When we cut a new major release, we drop support for unmaintained versions of Node. This means we try to keep the current release line, lowlight@^3, compatible with Node.js 16.

Security

This package is safe.

Related

Projects

Contribute

Yes please! See How to Contribute to Open Source.

License

MIT © Titus Wormer

lowlight's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

lowlight's Issues

Allow empty prefix

Setting to an empty string still results in the default prefix.
I was expecting it to disable prefix completely.

Error: Must use import to load ES Module

Hi, I'm facing this error

Error: Must use import to load ES Module: /home/rootlinux2/Documents/fr-bs-atoms/node_modules/lowlight/index.js
require() of ES modules is not supported.

I'm using the latest version of lowlight "lowlight": "^2.6.1"

Handle subscopes differently/better?

Just saw that you're flattening scopes... why not preserve them?

IE: title.function becomes just "title" and "function" separately, which isn't really the same thing at all.

It seems like you're purposely losing data... and I'm not sure the benefit since you don't have to care about CSS or anything...

Is there a way to list the registered languages?

It doesn't look like there's any way to list the registered languages. I'm using this is a web form and I want to populate a dropdown with the available languages, but there doesn't seem to be a way of getting them.

It looks like highlight.js exports this with the listLanguages function, but since lowlight registers languages in a local variable, this function just returns an empty list.

is possible to release with a cjs module?

it seems that this awesome library is not easy to use in next js due to the ESM only new release.
I know this is more an issue for next-js than this library, but just wondering if would you consider to release a cjs version of lowlight ?

Are there any plans supporting 3rd party languages?

So HighlightJS is no longer accepting new language support to their repo, and instead are encouraging people publishing their own 3rd party language support, I was wondering if you had any plans to support these languages?
(I am happy to PR the language support that I made if you are open to the idea)

Add example in the README to use in a React component

That would be nice as I tried to use { lowlight.highlight("json", {somejson}).value } and I am getting an error

Error: Objects are not valid as a React child (found: object with keys {type, value}). If you meant to render a collection of children, use an array instead or wrap the object using createFragment(object) from the React add-ons. Check the render method of `QuickStart`.

I guess I am missing a specific initialization for React.

TypeError: hljs.SHEBANG is not a function

Reference: highlightjs/highlight.js#2654 (comment)

I think this is an upstream issue with Lowlight? If Lowlight is wrapping us it probably could copy ALL our properties, as sometimes new ones are added (even in minor releases).

Original posted issue:


I started getting this error in my application once I updated to highlight.js 10.1.2.

TypeError: hljs.SHEBANG is not a function
javascript
node_modules/highlight.js/lib/languages/javascript.js:269
  266 | name: 'JavaScript',
  267 | aliases: ['js', 'jsx', 'mjs', 'cjs'],
  268 | keywords: KEYWORDS$1,
> 269 | contains: [
      | ^  270 |   hljs.SHEBANG({
  271 |     binary: "node",
  272 |     relevance: 5

I'm using react-lowlight to do code highlighting. This is the code I have in my project:

import React from 'react';
import PropTypes from 'prop-types';
import Lowlight from 'react-lowlight';
import shallowCompare from 'react-addons-shallow-compare';
import js from 'highlight.js/lib/languages/javascript';
import nginx from 'highlight.js/lib/languages/nginx';

Lowlight.registerLanguage('js', js);
Lowlight.registerLanguage('nginx', nginx);

var createReactClass = require('create-react-class');
const CodeBlock = createReactClass({
    displayName: 'CodeBlock',
    propTypes: {
        value: PropTypes.string,
        language: PropTypes.string,
        inline: PropTypes.bool
    },

    shouldComponentUpdate(nextProps, nextState) {
        return shallowCompare(this, nextProps, nextState);
    },

    render: function() {
        let language = 'js';
        if(this.props.value && this.props.value.length > 0) {
            language = this.props.language;
        }

        return (
            <Lowlight
                language={language || 'js'}
                value={this.props.value || ''}
                inline={this.props.inline}
            />
        );
    }
});

export default CodeBlock;

I had to downgrade to highlight.js 10.0.2 to get my application to work.

Compatible with ES6 browsers

CleanShot 2023-12-20 at 18 18 23@2x

Object.hasOwn() was new feature introduced inES2022, which is incompatible with old browsers like chrome older than v92

so, use Object.prototype.hasOwnProperty.call() may be better.

Convert tree to LaTeX?

I’m writing code that outputs LaTeX. Lowlight seems like a good choice for highlighting code because it gives you access to an intermediate data structure (vs. the fully rendered HTML). The result should look like this:

\begin{Verbatim}[commandchars=\\\{\}]
\textcolor[RGB]{101,123,131}{#privateSlot }\textcolor[RGB]{133,153,0}{in }\textcolor[RGB]{101,123,131}{obj}
\end{Verbatim}

AFAICT, I’d have to:

  • Flatten the tree into a sequence of text nodes that are annotated with sequences of CSS class names.
  • Use a theme to map these sequences to actual colors and/or text weights.

This seems doable. I’m only wondering if someone has already done this (=mapping text fragments to colors), so that I don’t unnecessarily duplicate work.

Tiny private API change

Following our discussion I decided to rename the internals just a little (removing all mention of CSS from the abstract tree itself, as that is a concern of the renderer, not the tree).

highlightjs/highlight.js@1db1892

This should land in 10.6 but should be super easy for you to deal with. I also now use a language attribute instead of overloading kind for sublanguage stuff.

How to resolve TypeScript conflict errors?

I'm using the latest lowlight (2.3.0) and the latest highlight.js (11.2.0) and just importing lowlight into my Angular 12 app gives me this error:

lowlight-type-error

How can I resolve this issue?

Import the highlight languages asynchronously on demand

The size of the lowlight package is almost 900KB (minified!) because it imports all the highlight languages at the top of the module. This means that any package that uses lowlight should pay a huge penalty.

emphasize is among one of those packages which are huge because of this

Should recommend rehype-stringify

Using rehype on the browser imports their parser, which has parse5 in the dependency tree, a 186kb (as of today) dependency that'll never be used here. It was the largest portion of my node_modules bundle (I'm using this on browser)

Since rehype is a collection of plugins, I just used the stringify plugin and chucked the parser bloat from my bundle size. I believe this should be the recommendation in the doc here.

Happy to add a PR for the doc change if you'd like.

`main` branch not compat with remark-highlightjs?

Currently getting:
image

TypeError: Cannot read property 'highlight' of undefined

which occurs on this code:

data.hChildren = _lowlight.default.highlight(lang, node.value, {
  prefix
}).value;

which is transform via babel-jest -> babel -> @babel/plugin-transform-modules-commonjs

Versions:
lowlight main (as of today: 869119b)
remark-highlightjs: 6.0.0

re-export highligh.js `getLanguage`

In order to display more uniformly, I hope to export the getLanguage API of highlight.js.

If the project installs highlight.js repeatedly, I am worried that it is not the same highlight instance

Running highlight.js after using lowlight results in blank output from highlight.js

This is caused by the following:

lowlight/lib/core.js

Lines 61 to 67 in ebddb10

high.configure({__emitter: HastEmitter, classPrefix: prefix})
const result = /** @type {HighlightResult & {_emitter: HastEmitter}} */ (
high.highlight(value, {language, ignoreIllegals: true})
)
high.configure({})

configure changes highlight.js globals, but calling it with an empty object does not restore those globals. Leading to highlight.js being left in a broken state.

I'm not sure how to properly workaround this ATM. e.g. To force a separate copy of highlight.js for the use of lowlight.

Reproduction: https://stackblitz.com/edit/vitejs-vite-mjpizz?file=src/components/HelloWorld.vue

Incorrect Solidity hightlighting with certain comments

When using lowlight to apply styling to Solidity, it incorrectly parses comments in certain cases. Consider the following code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

contract MetaCoin {
  constructor() {
    balances[tx.origin/***stuff***/] = 10000;
  }
}

In particular, note the comment that comes after tx.origin (I know, a weird place for a comment). My setup is the following:

import { unified } from "unified";
import rehypeStringify from "rehype-stringify";
import { lowlight } from "lowlight/lib/core";
import { solidity } from "highlightjs-solidity";
lowlight.registerLanguage("solidity", solidity);
const processor = unified().use(rehypeStringify);
const highlighted = lowlight.highlight("solidity", source.contents);
const finishedText = processor.stringify(highlighted);

In finishedText you will notice that lowlight does not wrap the comment as a comment but rather skips the / and parses the *s as operator. However, if you put a space in the source code like tx.origin /***stuff***/ it correctly parses it as a comment.

Warning for missing `dosini` syntax

I am getting this error with react-app-markdown-with-custom-components example and https://github.com/rstacruz/cheatsheets content.

Error: Unknown language: `dosini` is not registered at coreHighlight (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/lowlight/lib/core.js:159:11) at High.highlight (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/lowlight/lib/core.js:112:20) at visitor (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/rehype-highlight/index.js:54:27) at one (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/unist-util-visit/index.js:31:16) at all (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/unist-util-visit/index.js:54:25) at one (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/unist-util-visit/index.js:39:14) at all (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/unist-util-visit/index.js:54:25) at one (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/unist-util-visit/index.js:39:14) at visit (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/unist-util-visit/index.js:22:3) at transformer (/home/mart/workspace/react-app-markdown-with-custom-components/node_modules/rehype-highlight/index.js:26:5) error An unexpected error occurred: "Command failed. Exit code: 1

Warning for missing `console` syntax

Following this https://gitter.im/MoOx/phenomic?at=57b6202998125cfb657bc8d7

I am getting this warning.

Warning: %s Module build failed: Error: Expected `console` to be registered
    at coreHighlight (/Users/moox/Sync/Development/phenomic/node_modules/lowlight/lib/core.js:354:15)
    at Object.highlight (/Users/moox/Sync/Development/phenomic/node_modules/lowlight/lib/core.js:898:22)
    at visitor (/Users/moox/Sync/Development/phenomic/node_modules/remark-highlight.js/dist/index.js:36:45)
    at one (/Users/moox/Sync/Development/phenomic/node_modules/unist-util-visit/index.js:72:22)
    at all (/Users/moox/Sync/Development/phenomic/node_modules/unist-util-visit/index.js:48:26)
    at one (/Users/moox/Sync/Development/phenomic/node_modules/unist-util-visit/index.js:76:20)
    at visit (/Users/moox/Sync/Development/phenomic/node_modules/unist-util-visit/index.js:82:5)
    at /Users/moox/Sync/Development/phenomic/node_modules/remark-highlight.js/dist/index.js:42:45
    at wrapped (/Users/moox/Sync/Development/phenomic/node_modules/trough/index.js:128:19)
    at next (/Users/moox/Sync/Development/phenomic/node_modules/trough/index.js:81:24)

As you mentionned on the chat, this is likely due to "console" not being recognized.
Ref highlightjs/highlight.js#1126 (as it's not in highlight.js as well for now).

I think one improvement is to make the warning message more clear. Something like

Lowlight expects "console" syntax language to be registered. Code can be highlighted with the appropriate syntax.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.