Supercharge your markdown including RSCx components.

Overview

rscx-mdx

Render Markdown into HTML, while having custom RSCx components inside.

Usage

use rscx::{component, html, props};
use rscx_mdx::mdx::{Mdx, MdxComponentProps, MdxProps};

#[tokio::main]
async fn main() {
    let source = r#"---
title: "Hello, world!"
---

# Hello, world!

This is a **markdown** file with some *content*, but also custom RSCx components!

<CustomTitle />

<Layout>

## subtitle

</Layout>

"#;

    let res = html! {
        <Mdx source=source handler=handle />
    };

    println!("{}", res);
    // output ->
    //
    // <h1>Hello, world!</h1>
    // <p>This is a <strong>markdown</strong> file with some <em>content</em>, but also custom RSCx components!</p>
    // <h1>Some custom title!</h1>
    // <div class="layout">
    //     <h2>subtitle</h2>
    // </div>
}

/// handle is called everytime a custom component is encountered.
/// The props are standardized in the MdxComponentProps struct and can be later parsed and used
/// to render the component.
async fn handle(name: String, props: MdxComponentProps) -> String {
    match name.as_str() {
        "CustomTitle" => html! {
            <CustomTitle />
        },
        "Layout" => html! {
            <Layout>
                {props.children}
            </Layout>
        },
        _ => String::new(),
    }
}

// below we define some custom components that can be used in the markdown file

#[component]
fn CustomTitle() -> String {
    html! {
        <h1>Some custom title!</h1>
    }
}

#[props]
pub struct LayoutProps {
    children: String,
}

#[component]
fn Layout(props: LayoutProps) -> String {
    html! {
        <div class="layout">
            {props.children}
        </div>
    }
}
You might also like...
Introducing Inlyne, a GPU powered yet browsless tool to help you quickly view markdown files in the blink of an eye.
Introducing Inlyne, a GPU powered yet browsless tool to help you quickly view markdown files in the blink of an eye.

Inlyne - a GPU powered, browserless, markdown + html viewer inlyne README.md --theme dark/light About Markdown files are a wonderful tool to get forma

A Faster(⚡)  formatter, linter, bundler, and more for JavaScript, TypeScript, JSON, HTML, Markdown, and CSS Lapce Plugin
A Faster(⚡) formatter, linter, bundler, and more for JavaScript, TypeScript, JSON, HTML, Markdown, and CSS Lapce Plugin

Lapce Plugin for Rome Lapce-rome is a Lapce plugin for rome, The Rome is faster ⚡ , A formatter, linter, compiler, bundler, and more for JavaScript, T

scan markdown files and execute `console` blocks

exec-commands − scan markdown files and execute console blocks exec-commands is a utility to update command-line-tool examples embedded in markdown fi

mn is my project to learn rust, I will try to build a markdown editor

med is a markdown editor This is my project to learn rust programming language, I will try to build a powerful markdown editor. Highlight: Support Vim

Simple, omniglot, markdown-based literate programming and living documentation

Betwixt Simple, markdown-based, polyglot literate programming and documentation tests. Read code between the lines Summary Betwixt is heavily inspired

Simple, lightweight, markdown-based notes app I might actually finish eventually

Jupiter A simple markdown & git-based notes app for Linux. Features Lightweight with minimal dependencies Git integration for syncing & versioning Sea

Core Fiberplane data models and methods for transforming them (templates, providers, markdown conversion)

fiberplane This repository is a monorepo for Rust code that is used throughout Fiberplane's product. Overview base64uuid - A utility for working with

🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.
🏭 Convert Markdown documents into themed HTML pages with support for code syntax highlighting, LaTeX and Mermaid diagrams.

Marky Markdown Magician 🧙 Features Hot reload previewing 🔥 Conversion to HTML / PDF 🏭 Themes! ✨ Extensions - Math, diagrams, syntax-highlighting 🧩

Markdown to HTML converter written in Rust. Inspired by Katsuki Yuri's Makudaun Tool.
Markdown to HTML converter written in Rust. Inspired by Katsuki Yuri's Makudaun Tool.

Makurust Makurust is a powerful tool written in Rust that allows you to effortlessly convert your Markdown files into static HTML pages. Inspired by T

Comments
  • Make Syntect theme configurable

    Make Syntect theme configurable

    This should not be hardcoded: https://github.com/Pitasi/rscx-mdx/blob/ffc1001b579b827f49c8e040dbea5e3c98057743/src/markdown.rs#L42

    Available themes are listed here: https://github.com/trishume/syntect/blob/e9819fbcaf0eb5ea73448079aac78d00b8b4d140/src/dumps.rs#L203-L206

    opened by Pitasi 0
Owner
Antonio Pitasi
Antonio Pitasi
🕺 Run React code snippets/components from your command-line without config

Run React code snippets/components from your command-line without config.

Eliaz Bobadilla 11 Dec 30, 2022
A command-line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the returned URL.

Pup A command line tool aiming to upload the local image used in your markdown file to the GitHub repo and replace the local file path with the return

SteveLau 11 Aug 17, 2022
Pathfinding on grids using jumping point search and connected components.

grid_pathfinding A grid-based pathfinding system. Implements Jump Point Search with improved pruning rules for speedy pathfinding. Pre-computes connec

Thom van der Woude 16 Dec 12, 2022
Components of Fornjot that are no longer actively maintained. Pull requests still welcome!

Fornjot - Extra Components About These are extra components from the Fornjot repository, that are no longer actively maintained. Fornjot's goal was to

Hanno Braun 4 Jun 6, 2023
Transform jsx/tsx files to reactive views in js/ts to use in Web Components, insert into DOM or integrate with other libraries/frameworks

viewmill Features | Installation | Getting Started | Notes | Examples viewmill is aimed to create complex UIs from a simple form of JSX. It statically

apleshkov 6 Sep 4, 2023
Rust Server Components. JSX-like syntax and async out of the box.

RSCx - Rust Server Components RSCx is a server-side HTML rendering engine library with a neat developer experience and great performance. Features: al

Antonio Pitasi 21 Sep 19, 2023
Rust low-level minimalist APNG writer and PNG reader with just a few dependencies with all possible formats coverage (including HDR).

project Wiki https://github.com/js29a/micro_png/wiki at glance use micro_png::*; fn main() { // load an image let image = read_png("tmp/test.

jacek SQ6KBQ 8 Aug 30, 2023
mdBook is a utility to create modern online books from Markdown files.

Create book from markdown files. Like Gitbook but implemented in Rust

The Rust Programming Language 11.6k Jan 4, 2023
Tools - The Rome Toolchain. A linter, compiler, bundler, and more for JavaScript, TypeScript, HTML, Markdown, and CSS.

Rome is currently being rewritten in Rust. Read more about it in our latest blog post. The documentation below is out of date and available for poster

Rome 22k Jan 3, 2023