Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free. Learn more →
Top 23 Rust Markdown Projects
-
gutenberg
A fast static site generator in a single binary with everything built-in. https://www.getzola.org
-
-
InfluxDB
Access the most powerful time series database as a service. Ingest, store, & analyze all types of time series data in a fully-managed, purpose-built database. Keep data forever with low-cost storage and superior data compression.
-
Quickest way I found to view .md files from my terminal is mdcat.
-
I opened up the src/App.tsx and added a and synced any text changes to React state.
import { useState } from "react"; import reactLogo from "./assets/react.svg"; import { invoke } from "@tauri-apps/api/tauri"; import "./App.css"; function App() { const [markdown, setMarkdown] = useState(""); return (
className="container">); } export default App;Welcome to Tauri!
className="row"> href="https://vitejs.dev" target="_blank">src="/vite.svg" className="logo vite" alt="Vite logo" /> href="https://tauri.app" target="_blank">
src="/tauri.svg" className="logo tauri" alt="Tauri logo" /> href="https://reactjs.org" target="_blank">
src={reactLogo} className="logo react" alt="React logo" />
Click on the Tauri, Vite, and React logos to learn more.
className="row">id="greet-input" onChange={(e) => setMarkdown(e.currentTarget.value)} />Enter fullscreen mode Exit fullscreen modeNow that we have a textbox we can write Markdown inside, let’s convert that to HTML to preview.
Creating a Tauri command
We’ll need to use Tauri commands to communicate between the frontend and backend - and vice versa (similar to the IPC layer in Electron).
Tauri comes with an example Tauri command called
greet()
already setup, so let’s use that and change it to parse Markdown. Open upsrc-tauri/src/main.rs
and change it to the following:
#![cfg_attr( all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows" )] // Import comrak use comrak::{markdown_to_html, ComrakOptions}; // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command #[tauri::command] fn greet(markdown: &str) -> String { // format!("Hello, {}! You've been greeted from Rust!", name) // Parse the markdown text to HTML let html = markdown_to_html(&markdown, &ComrakOptions::default()); println!("Markdown parsed into HTML \n"); println!("{html}"); // We return the HTML to the frontend (in Rust, we return by omitting the `;`) html } fn main() { tauri::Builder::default() // Here is where we add our Tauri commands to our app .invoke_handler(tauri::generate_handler![greet]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }
Enter fullscreen mode Exit fullscreen modeAnd in our frontend, let’s create a
we can press to run the Tauri command. We use the
invoke
function provided by Tauri that’ll call a Tauri command with the same name.
import { useState } from "react"; import reactLogo from "./assets/react.svg"; import { invoke } from "@tauri-apps/api/tauri"; import "./App.css"; function App() { const [html, setHtml] = useState(""); const [markdown, setMarkdown] = useState(""); async function greet() { // Learn more about Tauri commands at https://tauri.app/v1/guides/features/command setHtml(await invoke("greet", { markdown })); } return ( <div className="container"> <h1>Welcome to Tauri!h1> <div className="row"> <a href="https://vitejs.dev" target="_blank"> <img src="/vite.svg" className="logo vite" alt="Vite logo" /> a> <a href="https://tauri.app" target="_blank"> <img src="/tauri.svg" className="logo tauri" alt="Tauri logo" /> a> <a href="https://reactjs.org" target="_blank"> <img src={reactLogo} className="logo react" alt="React logo" /> a> div> <p>Click on the Tauri, Vite, and React logos to learn more.p> <div className="row"> <div> <textarea id="greet-input" onChange={(e) => setMarkdown(e.currentTarget.value)} /> <button type="button" onClick={() => greet()}> Convert to HTML button> div> div> <p>{html}p> div> ); } export default App;
Enter fullscreen mode Exit fullscreen modeIf you type some Markdown into the text box and click the button, it should print out raw HTML representing your Markdown. Here’s the commit on Github for reference.
But how do we preview the HTML?
If we wanted to preview the HTML, we could use React’s
dangerouslySetInnerHTML
to inject the HTML inside our app:
const createMarkdownMarkup = () => ({ __html: html }) <div dangerouslySetInnerHTML={createMarkdownMarkup()} />
Enter fullscreen mode Exit fullscreen modeAnd ideally, this isn’t as “dangerous” as it sounds, because Comrak sanitizes the Markdown output for any malicious code before converting to HTML 👍
We could also update the
onChange
function to run our conversion process, instead of waiting for a button press, so we “instantly” see a live preview. In my case, I do it in a useEffect with a refresh boolean — but it’s all good. Note, this is a little risky, since the user might be able to break the app, so in production it’d be best to create a cache of the last “working” preview just in case one fails.
import { useEffect, useRef, useState } from "react"; import reactLogo from "./assets/react.svg"; import { invoke } from "@tauri-apps/api/tauri"; import "./App.css"; function App() { const [html, setHtml] = useState(""); const [markdown, setMarkdown] = useState(""); const [refreshCheck, setRefreshCheck] = useState(false); async function greet() { setRefreshCheck(true); } useEffect(() => { const parseMarkdown = async () => { setHtml(await invoke("greet", { markdown })); setRefreshCheck(false); console.log("new markdown"); }; console.log("refreshed"); if (refreshCheck) { parseMarkdown(); console.log("parsing!"); } }, [refreshCheck]); const createMarkdownMarkup = () => ({ __html: html, }); const handleTextArea = (e) => { setMarkdown(e.currentTarget.value); setRefreshCheck(true); console.log("need new markdown!"); }; return ( <div> <div className="row"> <div> <textarea id="greet-input" onChange={handleTextArea} /> <button type="button" onClick={() => greet()}> Convert to HTML button> div> div> <div dangerouslySetInnerHTML={createMarkdownMarkup()} /> div> ); } export default App;
Enter fullscreen mode Exit fullscreen modeHere’s the commit on Github for reference.
The world is your Markdown
Now you can parse Markdown using Rust, there’s lots of cool stuff you can do! From CLIs to UI apps, you can make tools that help people use Markdown. And ideally, this will run faster than most other implementations (like Electron apps) because it’s running in Rust (unless you can write Markdown tooling in C or something).
I hope this helped you understand some Rust fundamentals and new techniques to use down the line.
As always, if you have any questions or make something using this guide, tag me on Twitter. I’d love to help or see what cool stuff you’re hacking on.
You can find the complete code for this post in my tauri-markdown-editor repo.
Stay regular!
Ryo -
-
Currently using https://github.com/euclio/vim-markdown-composer and am happy with it.
-
-
SonarQube
Static code analysis for 29 languages.. Your projects are multi-language. So is SonarQube analysis. Find Bugs, Vulnerabilities, Security Hotspots, and Code Smells so you can release quality code every time. Get started analyzing your projects today for free.
-
Project mention: Looking for an extensible markup language (aka Markdown, Asciidoc, ...) implemented in Rust. | reddit.com/r/rust | 2023-01-13
Have you considered markdown-rs?
-
Project mention: Obsidian Roundup: Demo Vaults, PKM History, & an editable graph view | reddit.com/r/ObsidianMD | 2022-05-28
-
Project mention: Contribute to the diagnostic translation effort! | Inside Rust Blog | reddit.com/r/rust | 2022-08-17
We already have them translated here ! My favorite is "Rustacean" being translated to "Rustacé".
-
Project mention: null-ls-embedded - Format embedded code using null-ls | reddit.com/r/neovim | 2022-12-02
https://github.com/lukas-reineke/cbfmt also exists as a standalone tool for this
-
tp-note
Minimalistic note taking: save and edit your clipboard content as a note file (Gitlab mirror)
-
-
Project mention: Is any Indian company doing something unique. Apart from building just basic CRUD apps? | reddit.com/r/bangalore | 2023-01-30
We have added function support in FTD as well. Not yet properly documented. Checkout this example: https://github.com/ftd-lang/ftd/blob/main/t/html/6-function.ftd
-
-
The complete is in Rodney Lab GitHub repo. As a next step you might consider publishing your WASM module to deno.land/x so other developers can easily use it. This is something I did with the parsedown module. It has code I use for the Newsletter and parses Markdown to HTML as well as generate email HTML and plaintext emails. Let me know if you would like to see a short video on publishing a Deno module.
-
-
-
Project mention: One Thing – Put a single task or goal in your menu bar | news.ycombinator.com | 2022-12-30
I made for myself something similar, for display in my shell prompt https://github.com/netgusto/tax
-
pup
A command-line tool that automatically uploads images from the markdown document to the GitHub repo and replaces the paths with the returned URL. (by SteveLauC)
The repo is [here](https://github.com/SteveLauC/pup), welcome to have some fun:)
-
orion
A static site generator written in Rust to create a simple blog from Markdown files (by adriantombu)
I also have a few ideas to improve my current very basic static site generator https://github.com/adriantombu/orion
-
Germ is released: A minimal dependency, Gemini-oriented library for all your Gemini needs: AST construction, format conversions (Gemtext to Markdown, HTML, etc.), request creation, and meta utilities.
-
SaaSHub
SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives
Rust Markdown related posts
- Tp-Note: Minimalistic note taking
- Deno Fresh WASM: Code Modules in Rust
- Looking for an extensible markup language (aka Markdown, Asciidoc, ...) implemented in Rust.
- What’s everyone working on this week (1/2023)?
- One Thing – Put a single task or goal in your menu bar
- Note-taking app for programmers/tech people?
- null-ls-embedded - Format embedded code using null-ls
-
A note from our sponsor - SonarQube
www.sonarqube.org | 28 Mar 2023
Index
What are some of the best open-source Markdown projects in Rust? This list will help you:
Project | Stars | |
---|---|---|
1 | gutenberg | 10,587 |
2 | dprint | 1,766 |
3 | mdcat | 1,582 |
4 | comrak | 843 |
5 | termimad | 671 |
6 | vim-markdown-composer | 601 |
7 | crowbook | 592 |
8 | markdown-rs | 294 |
9 | obsidian-extract-url | 156 |
10 | rust-book-fr | 136 |
11 | cbfmt | 121 |
12 | tp-note | 84 |
13 | marko-editor | 49 |
14 | fastn | 49 |
15 | gisture | 27 |
16 | parsedown | 16 |
17 | mini_markdown | 15 |
18 | criterion-table | 15 |
19 | tax | 13 |
20 | pup | 12 |
21 | orion | 9 |
22 | md-footer | 8 |
23 | germ | 7 |