32 个版本
新版本 0.2.7 | 2024年8月19日 |
---|---|
0.2.5 | 2024年7月2日 |
0.1.23 | 2024年2月5日 |
0.1.21 | 2023年12月21日 |
0.1.2 | 2022年11月25日 |
21 在 开发工具 中排名
每月下载量:3,569
460KB
10K SLoC
mdxjs-rs
在 Rust 中编译 MDX 到 JavaScript。
何时使用此工具?
当你使用 Rust 语言并希望将 MDX 编译为 JavaScript 时,可以使用此软件包。要解析 MDX 格式到语法树,请使用 markdown-rs
。
此项目目前不支持插件。为了从统一的(remark 和 rehype)生态系统受益,请使用 @mdx-js/mdx
。
这是什么?
这个 Rust 软件包的工作方式与 npm 包 @mdx-js/mdx
完全相同。它使用 Rust 软件包 markdown-rs
和 SWC 来处理 MDX 中的 Markdown 和 JavaScript。
问题
内容
安装
使用 Rust (rust edition 2018+,±版本 1.56+),使用 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(())
}
结果(格式化后)
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
API
mdxjs-rs
提供了 compile
、JsxRuntime
、Options
以及一些其他结构体和枚举。
更多详细信息请参阅 crate 文档。
项目
测试
mdxjs-rs
已经过大量测试。这些测试覆盖了代码的所有分支,这意味着该项目具有100%的代码覆盖率。
以下bash脚本在处理此项目时非常有用
- 运行示例
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
遵循 SemVer。
安全
MDX 是一种编程语言。它是 JavaScript。不要让不信任的人编写 MDX。
贡献
有关帮助的途径,请参阅 contributing.md
。有关获取帮助的途径,请参阅 support.md
。有关如何在项目中沟通的指南,请参阅 code-of-conduct.md
。
赞助
通过赞助支持此项目并回馈
- GitHub Sponsors(个人;每月或一次性)
- OpenCollective 或 GitHub Sponsors(统一;每月或一次性)
感谢
特别感谢
- Vercel 为初始开发提供资金
许可证
依赖关系
~12MB
~254K SLoC