sillycode

Crates.iosillycode
lib.rssillycode
version0.0.5
created_at2025-05-22 21:47:23.89709+00
updated_at2026-01-21 00:05:25.672199+00
descriptionFast and safe implementation of sillycode parsing and rendering
homepage
repositoryhttps://github.com/luavixen/sillycode
max_upload_size
id1685666
size38,699
Lua (luavixen)

documentation

README

sillycode

Fast and safe sillycode parsing and rendering libraries for both Rust and JavaScript/TypeScript.

Each library implementation provides functionality to parse sillycode markup into structured parts and render them as HTML. For more information on sillycode and its syntax, see the sillycode guide.

Installation

JavaScript/TypeScript

npm install sillycode

Rust

[dependencies]
sillycode = "0.0.5"

Usage

JavaScript/TypeScript

import { parse, render } from 'sillycode';

const input = "[b]Hello[/b] [:)]";
const parts = parse(input);
const html = render(parts, false);

console.log(html);

Rust

use sillycode::{parse, render};

let input = "[b]Hello[/b] [:)]";
let parts = parse(input);
let html = render(parts, false);

println!("{}", html);

API Reference

JavaScript/TypeScript

For comprehensive information, including type definitions, for the JS/TS API, visit sillycode.netlify.app.

Core Functions

  • parse(input: string): Part[] - Parse sillycode markup into structured parts
  • render(parts: Part[], isEditor?: boolean, emoteSrcPrefix?: string): string - Render parts to HTML
  • length(parts: Part[]): number - Calculate display length of parts

DOM Utilities

  • reverse($root: HTMLElement): string - Extract sillycode markup from DOM elements
  • diff($expected: HTMLElement, $actual: HTMLElement): boolean - Efficiently diff and update DOM trees

Rust

Note that, unlike the JavaScript version, the Rust version doesn't support customizing the emote source prefix. Consider using a simple string replace instead.

Core Functions

  • parse(input: &str) -> Vec<Part> - Parse sillycode markup into structured parts
  • render(parts: impl IntoIterator<Item = Part>, is_editor: bool) -> String - Render parts to HTML
  • length(parts: &[Part]) -> usize - Calculate display length of parts

Types

  • Part - Enum for all parsed parts (text, style, emote, color, etc.)
  • StyleKind - Enum for style types (bold, italic, underline, etc.)
  • EmoteKind - Enum for emote types (smile, sad, etc.)
  • Color - Type alias for color strings

Authors

Made with ❤ by Lua (foxgirl.dev) :3c

License

This project is licensed under MIT. More info in the LICENSE file.

Commit count: 10

cargo fmt