#html #markup #parser #rendering

sillycode

Fast and safe implementation of sillycode parsing and rendering

1 unstable release

new 0.0.3 May 22, 2025

#1928 in Parser implementations

MIT license

35KB
881 lines

sillycode

This repository provides fast and safe implementations of sillycode parsing and rendering in both JavaScript/TypeScript and Rust.

Installation

JavaScript/TypeScript

npm install sillycode

Rust

[dependencies]
sillycode = "0.0.3"

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

Core Functions

  • parse(input: string): Part[] - Parse sillycode markup into structured parts
  • render(parts: Part[], isEditor?: boolean): 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

Types

  • Part - Union type 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

Rust

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.

Dependencies

~245–700KB
~16K SLoC