Learn Rust by implementing a tiny Markdown formatter.
(WIP)
hello-world.md
# hello
world!
# Format
$ md-fmt hello-world.md --write
# JSON
$ md-fmt hello-world.md --json | jq '.body[] | select(.type == "Section").value.title'
"hello"
use anyhow::Result;
use mdfmt_core::{format, parse, Block, Section};
fn main() -> Result<()> {
let note = mdfmt_core::parse("# foo")?;
for block in note.body {
match block {
Block::Section(Section { title, .. }) => {
println!("title: {title}");
},
_ => {},
}
}
let formatted = format("# foo")?;
println!("formatted: {}", formatted);
}
import { format, parse } from 'mdfmt-js';
const note = parse('# Hello, world!');
for (const block of note.body) {
switch (block.type) {
case 'Section': {
console.log(`title: ${block.title}`);
break;
}
default: {
break;
}
}
}
const formatted = format('# Hello, world!');
console.log(`formatted: ${formatted}`);