# Tui-markdown
An experimental Proof of Concept library for converting markdown content to a [Ratatui] `Text`
value. See [Markdown-reader] for an example application that uses this library.
[![Crate badge]][tui-markdown]
[![Docs.rs Badge]][API Docs]
[![Deps.rs Badge]][Dependency Status]
[![License Badge]](../LICENSE-MIT)
[![Codecov.io Badge]][Code Coverage]
[![Discord Badge]][Ratatui Discord]
[GitHub Repository] · [API Docs] · [Examples] · [Changelog] · [Contributing]
## Installation
```shell
cargo add tui-markdown
```
## Usage
```rust
let input = "# Heading\n\n**bold**"; // this can come from whereever
let text = tui_markdown::from_str(input);
text.render(area, &mut buf);
```
## Status
This is working code, but not every markdown feature is supported. PRs welcome!
- [x] Headings
- [x] Heading attributes / classes / anchors
- [x] Normal paragraphs
- [x] Block quotes
- [x] Nested block quotes
- [x] Bold (strong)
- [x] Italic (emphasis)
- [x] Strikethrough
- [x] Ordered lists
- [x] Unordered lists
- [x] Code blocks
- [ ] Html
- [ ] Footnotes
- [x] Linebreak handling
- [x] Rule
- [ ] Tables
- [x] Tasklists
- [ ] Links
- [ ] Images
- [x] Metadata blocks
- [x] Superscript
- [x] Subscript
Linebreaks are rendered with Markdown defaults: soft breaks become spaces, hard breaks insert a
new line.
Metadata blocks are rendered using the metadata block style so front matter is visible, including
the delimiter lines (for example `---` in YAML-style blocks).
```rust
use ratatui::text::Text;
use tui_markdown::from_str;
let markdown = r#"---
title: Demo
tags:
- one
- two
---
Body
"#;
let text = from_str(markdown);
assert_eq!(
text,
Text::from_iter([
"---".into(),
"title: Demo".into(),
"tags:".into(),
" - one".into(),
" - two".into(),
"---".into(),
"".into(),
"Body".into(),
])
);
```
## License
Copyright (c) 2024 Josh McKinney
This project is licensed under either of
- Apache License, Version 2.0
([LICENSE-APACHE](../LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license
([LICENSE-MIT](../LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.
See [CONTRIBUTING.md](../CONTRIBUTING.md).
[tui-markdown]: https://crates.io/crates/tui-markdown
[markdown-reader]: https://crates.io/crates/markdown-reader
[Ratatui]: https://crates.io/crates/ratatui
[Crate badge]: https://img.shields.io/crates/v/tui-markdown?logo=rust&style=for-the-badge
[Docs.rs Badge]: https://img.shields.io/docsrs/tui-markdown?logo=rust&style=for-the-badge
[Deps.rs Badge]: https://deps.rs/repo/github/joshka/tui-markdown/status.svg?path=tui-markdown&style=for-the-badge
[License Badge]: https://img.shields.io/crates/l/tui-markdown?style=for-the-badge
[Codecov.io Badge]: https://img.shields.io/codecov/c/github/joshka/tui-markdown?logo=codecov&style=for-the-badge&token=BAQ8SOKEST
[Discord Badge]: https://img.shields.io/discord/1070692720437383208?label=ratatui+discord&logo=discord&style=for-the-badge
[API Docs]: https://docs.rs/crate/tui-markdown/
[Dependency Status]: https://deps.rs/crate/tui-markdown
[Code Coverage]: https://app.codecov.io/gh/joshka/tui-markdown
[Ratatui Discord]: https://discord.gg/pMCEU9hNEj
[GitHub Repository]: https://github.com/joshka/tui-markdown
[Changelog]: https://github.com/joshka/tui-markdown/blob/main/tui-markdown/CHANGELOG.md
[Contributing]: https://github.com/joshka/tui-markdown/blob/main/CONTRIBUTING.md