Git Product home page Git Product logo

highlighter's Introduction

Highlighter

RichText highlighting Lua code with a pure Lua lexer

Installation

Wally:

[dependencies]
Highlighter = "boatbomber/[email protected]"

Roblox Model:

Download from Releases

API

Functions:

function Highlighter.highlight(props: types.HighlightProps): () -> ()

Highlights the given textObject with the given props and returns a cleanup function. Highlighting will automatically update when needed, so the cleanup function will disconnect those connections and remove all labels.

function Highlighter.refresh(): ()

Refreshes all highlighted textObjects. Automatically runs when the theme changes.

function Highlighter.setTokenColors(colors: types.TokenColors): ()

Sets the token colors to the given colors and refreshes all highlighted textObjects.

function Highlighter.getTokenColor(tokenName: types.TokenName): Color3

Gets a token color by name. Mainly useful for setting "background" token color on other UI objects behind your text.

function Highlighter.matchStudioSettings(): ()

Matches the token colors to the Studio theme settings and refreshes all highlighted textObjects. Does nothing when not run in a Studio plugin.

Types:

type TextObject = TextLabel | TextBox

type TokenName =
    "background"
    | "iden"
    | "keyword"
    | "builtin"
    | "string"
    | "number"
    | "comment"
    | "operator"
    | "custom"

type TokenColors = {
    ["background"]: Color3?,
    ["iden"]: Color3?,
    ["keyword"]: Color3?,
    ["builtin"]: Color3?,
    ["string"]: Color3?,
    ["number"]: Color3?,
    ["comment"]: Color3?,
    ["operator"]: Color3?,
    ["custom"]: Color3?,
}

type HighlightProps = {
    textObject: TextObject,
    src: string?,
    forceUpdate: boolean?,
    lexer: Lexer?,
    customLang: { [string]: string }?,
}

type Lexer = {
    scan: (src: string) -> () -> (string, string),
    navigator: () -> any,
    finished: boolean?,
}

Simple Example

local Highlighter = require(script.Highlighter)

-- When using in a Studio Plugin, this will automatically match the Studio theme
Highlighter.matchStudioSettings()

-- Add syntax highlighting to myTextLabel
Highlighter.highlight({
    textObject: myTextLabel,
})

highlighter's People

Contributors

boatbomber avatar benmactavsin avatar nidhogames avatar policefighter761 avatar snowyshiro avatar quenty avatar pw4k avatar bobbybob2131 avatar howmanysmall avatar

Stargazers

 avatar

Watchers

 avatar

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.