Crates.io | mdxjs |
lib.rs | mdxjs |
version | 0.2.13 |
source | src |
created_at | 2022-10-19 19:33:04.810252 |
updated_at | 2024-11-06 11:38:33.42938 |
description | Compile MDX to JavaScript in Rust. |
homepage | https://github.com/wooorm/mdxjs-rs |
repository | https://github.com/wooorm/mdxjs-rs |
max_upload_size | |
id | 691846 |
size | 496,596 |
Compile MDX to JavaScript in Rust.
You can use this crate when you’re dealing with the Rust language and want
to compile MDX to JavaScript.
To parse the MDX format to a syntax tree, use markdown-rs
instead.
This project does not yet support plugins.
To benefit from the unified (remark and rehype) ecosystem, use
@mdx-js/mdx
.
This Rust crate works exactly like the npm package @mdx-js/mdx
.
It uses the Rust crates markdown-rs
and SWC to deal with the
markdown and JavaScript inside MDX.
mdxjs.com
With Rust (rust edition 2018+, ±version 1.56+), install with cargo
:
cargo add mdxjs
extern crate mdxjs;
fn main() -> Result<(), markdown::message::Message> {
println!(
"{}",
mdxjs::compile(
r###"
import {Chart} from './snowfall.js'
export const year = 2018
# Last year’s snowfall
In {year}, the snowfall was above average.
It was followed by a warm spring which caused
flood conditions in many of the nearby rivers.
<Chart year={year} color="#fcb32c" />
"###,
&Default::default()
)?
);
Ok(())
}
Yields (prettified):
import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from 'react/jsx-runtime'
import {Chart} from './snowfall.js'
export const year = 2018
function _createMdxContent(props) {
const _components = Object.assign({h1: 'h1', p: 'p'}, props.components)
return _jsxs(_Fragment, {
children: [
_jsx(_components.h1, {children: 'Last year’s snowfall'}),
'\n',
_jsxs(_components.p, {
children: [
'In ',
year,
', the snowfall was above average.\nIt was followed by a warm spring which caused\nflood conditions in many of the nearby rivers.'
]
}),
'\n',
_jsx(Chart, {year: year, color: '#fcb32c'})
]
})
}
function MDXContent(props = {}) {
const {wrapper: MDXLayout} = props.components || {}
return MDXLayout
? _jsx(MDXLayout, Object.assign({}, props, {children: _jsx(_createMdxContent, props)}))
: _createMdxContent(props)
}
export default MDXContent
mdxjs-rs
exposes
compile
,
JsxRuntime
,
Options
,
and a few other structs and enums.
See the crate docs for more info.
mdxjs-rs
is tested with a lot of tests.
These tests reach all branches in the code, which means that this project has
100% code coverage.
The following bash scripts are useful when working on this project:
RUST_BACKTRACE=1 cargo run --example lib
cargo fmt && cargo fix
cargo fmt --check && cargo clippy --all-targets
RUST_BACKTRACE=1 cargo test
cargo doc --document-private-items
mdxjs-rs
follows SemVer.
MDX is a programming language. It is JavaScript. It is not safe to let people you don’t trust write MDX.
See contributing.md
for ways to help.
See support.md
for ways to get help.
See code-of-conduct.md
for how to communicate in and around this
project.
Support this effort and give back by sponsoring:
Special thanks go out to: