View on GitHub

MicroLighter

No more spans!

Blazingly fast!!

Lazy-loaded grammars!!!

CSS for humans!!!1

Install

Add MicroLighter to your project, import a theme, then mark each code block with a language-* class.

npm install microlighter
import { highlightAll } from "microlighter";
import "microlighter/themes/github.css";

await highlightAll();
<pre><code class="language-javascript">const answer = 42;</code></pre>

Prefer automatic setup? Import the minified auto-runner instead. It highlights the page immediately and re-highlights when a syntax-highlight event is dispatched.

import "microlighter/microlighter.min.js";

Want copy controls or line numbers? Import the custom element bundle and wrap the same standard <pre><code> markup.

import "microlighter/micro-lighter-element.min.js";
<micro-lighter language="javascript" controls="copy" line-numbers>
  <pre><code>const answer = 42;</code></pre>
</micro-lighter>
Try the custom element demo Read more in the docs

Code samples

Supports the TextMate grammar format used by VS Code.

Markup

<!-- This div centers the div that centers the button. -->
<div class="centerer">
  <div class="centered">
    <button id="victory" type="button">Center me</button>
  </div>
</div>

<style>
  .centerer {
    display: grid;
    min-height: 100vh;
    place-items: center;
  }

  .centered {
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>

<script>
  document.querySelector("#victory").addEventListener("click", event => {
    event.target.textContent = "Still centered.";
  });
</script>

Markdown

# Yet Another Todo App

![build: passing](https://img.shields.io/badge/build-passing-brightgreen)
![coverage: probably](https://img.shields.io/badge/coverage-probably-yellow)
![works: here](https://img.shields.io/badge/works-on_my_machine-blue)

A **blazingly fast** todo app for developers who found the other
47,000 todo apps insufficiently opinionated.

## Install

    npm install yet-another-todo

## Usage

Run `npm start`, add "write documentation" to the list, then ignore it.

## Documentation

Coming soon™

> Production-ready, once we decide what production means.

Python

def readable_version(groups: list[list[str]]) -> list[str]:
    words = []
    for group in groups:
        for sentence in group:
            for word in sentence.split():
                if len(word) > 3:
                    words.append(word.lower())
    return words


def pythonic_version(groups: list[list[str]]) -> list[str]:
    return [
        word.lower()
        for group in groups
        for sentence in group
        for word in sentence.split()
        if len(word) > 3
    ]  # Pythonic.


assert readable_version([["Simple is better than nested"]]) == \
    pythonic_version([["Simple is better than nested"]])

SQL

-- Find meetings that could have been emails
SELECT
  m.title,
  COUNT(a.user_id) AS witnesses,
  SUM(m.duration_minutes) / 60.0 AS hours_wasted
FROM meetings AS m
JOIN attendees AS a ON a.meeting_id = m.id
WHERE m.could_have_been_email = TRUE
  AND m.outcome = 'another_meeting'
GROUP BY m.id, m.title
HAVING COUNT(a.user_id) > 2
ORDER BY hours_wasted DESC
LIMIT 10;

C++

#include <iostream>
#include <memory>
#include <string>

class Meeting {
public:
    explicit Meeting(std::string agenda)
        : agenda_(std::move(agenda)) {}

    ~Meeting() {
        std::cout << "This meeting has finally ended.\n";
    }

private:
    std::string agenda_;
};

std::unique_ptr<Meeting> make_meeting(std::string agenda) {
    return std::make_unique<Meeting>(std::move(agenda));
}

int main() {
    auto meeting = make_meeting("Discuss the next meeting");
    auto sequel = std::move(meeting); // Ownership is now perfectly clear.
    return 0;
}

TSX

import { useCallback, useEffect, useMemo, useState } from "react";

export function YetAnotherTodoApp(): JSX.Element {
  const [done, setDone] = useState(false);
  const completedCount = useMemo(() => Number(done), [done]);
  const toggle = useCallback(() => setDone(value => !value), []);

  useEffect(() => {
    console.log(`${completedCount} productivity units achieved`);
  }, [completedCount]);

  return (
    <label>
      <input type="checkbox" checked={done} onChange={toggle} />
      Write a simpler todo app
      {/* TODO: replace this with a state management library. */}
    </label>
  );
}

Supported languages

Every grammar below ships as its own module and loads only when a page actually uses it. That includes formats like Git diff and config languages like TOML that aren't strictly "programming languages" but still get real TextMate scoping.

Web

  • HTML
  • CSS
  • SCSS
  • JavaScript
  • TypeScript
  • TSX
  • Svelte
  • Vue

Systems

  • C
  • C++
  • Rust
  • Go
  • Assembly

Application

  • Java
  • C#
  • Kotlin
  • Swift
  • Objective-C
  • Dart
  • PHP

Scripting

  • Python
  • Ruby
  • Bash
  • Perl
  • PowerShell
  • Lua
  • R

Data, config & docs

  • JSON
  • YAML
  • TOML
  • SQL
  • Markdown
  • GraphQL
  • Dockerfile
  • Git diff

Playground

Theme code