Created a Markdown Desktop App with Tauri
Published: 2023-08-26 08:36:33


## Introduction

Hello everyone.

Last year, I developed a WeChat formatting editor called MDX Editor. It allows customization of components, styles, generates QR codes, provides code diff highlighting, and supports exporting to Markdown and PDF, among other functionalities. However, as a WeChat formatting editor, its audience is relatively limited and not suitable for everyone. Therefore, based on this editor, I developed the MDX Editor desktop version, which supports Mac, Windows, and Linux. It is lightweight, with the entire application being only 7MB in size. Now, the MDX Editor desktop version has become my primary tool for writing. If you're interested in it, you can find it at the end of the document.

## Demo screenshot

<table>
<tr>
    <td><img src="https://user-images.githubusercontent.com/9312044/262275142-ce7f3e70-cbad-449e-999e-4cba33f75000.png"/></td>
    <td><img src="https://user-images.githubusercontent.com/9312044/262275149-3310abc1-5a6d-45cb-aa9a-3359381ec429.png"/></td>
</tr> 
<tr>
    <td><a href="https://editor.runjs.cool/64b51328337a9f4db79fe677" >Subtle Green Card</a></td>
    <td><a href="https://editor.runjs.cool/64c0fca121821b2af589cf6e">Early Summer Style</a></td>
</tr> 
<tr>
  <td><img src="https://user-images.githubusercontent.com/9312044/262275160-41c30692-b554-4da6-bcc7-3fb00169ed5d.png"/></td>
  <td><img src="https://user-images.githubusercontent.com/9312044/262275117-fdf35fe4-0b70-45ad-995d-b6622586c6d8.png"/></td>
</tr>
<tr>
  <td><a href="https://editor.runjs.cool/624688ccb6fe2900015728ac">Resume Template</a></td>
  <td><a href="https://editor.runjs.cool/625550658cc5730001809f0c">Exquisite Code Diff Highlights</a></td>
</tr>
<tr>
    <td><img src="https://user-images.githubusercontent.com/9312044/262275165-766ff817-7c09-4288-b8dd-55d7424c2fd6.png"/></td>
    <td><img src="https://user-images.githubusercontent.com/9312044/262275168-6dd4b05c-a604-4ab1-abe3-b2d2dc759d8e.png"/></td>
</tr> 
<tr>
    <td><a href="https://editor.runjs.cool/6492ae0109e298c79055dfab">Generate Captivating QR Codes</a></td>
    <td><a href="https://editor.runjs.cool/6492aa37f5cf3a54f14493a8">Travel Itinerary</a></td>
</tr> 
</table>

## Technology Stack

For developing the MDX Editor desktop app, I utilized the following core technology stack:

- React (Next.js)
- Tauri — A framework for building cross-platform desktop applications
- Tailwind CSS — An atomic class-based styling framework that supports dark mode
- Ant Design v5 — Utilized the "Tree" component for managing the document tree

## Features and Implementation

### 1. MDX Custom Components

MDX combines the advantages of Markdown and JSX, allowing you to directly use React components in Markdown documents to build complex interactive content. If you're familiar with React, you can customize your components in the "Config" tab. If you're not a programmer, you can also create content based on existing templates. For example, the "Gallery" component in the template is essentially a "flex" layout.

**Code**

```jsx
function Gallery({ children }) {
    return <div className="flex gallery">{children}</div>;
}
```


### 2. Dark Mode

Dark mode has become an essential part of note-taking software. MDX Editor implements dark mode using `Tailwind CSS`.

![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/61bac318e79d4e698c96b98424625590~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp)

### 3. Multiple Themes

The editor comes with 10+ document and code themes. You can switch between them by clicking the settings button in the upper right corner.

![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c26b16c40b9a4a6ebf8847e25f1c1dcd~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp)

### 4. Local File Management

The desktop app also supports local file management. You can choose a directory or drag your document workspace into the editor to manage documents in real time.

![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/830e28ae574e4a44bd53d03654b8f099~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp)

Before implementing this feature, I was concerned about not being familiar with Rust and not being able to complete it. However, after becoming acquainted with the Tauri documentation, I found it to be quite simple. Tauri provides file operation APIs, eliminating the need to write Rust code. Instead, we can achieve file management by calling Tauri APIs.

```js
import { readTextFile, BaseDirectory } from '@tauri-apps/api/fs';
// Read the text file at the path `$APPCONFIG/app.conf`
const contents = await readTextFile('app.conf', { dir: BaseDirectory.AppConfig });
```

The document tree uses Ant Design's Tree component, with custom styling to maintain consistency with the overall theme, greatly reducing the coding workload.

### 5. Document Formatting

During the document writing process, formatting can often interrupt your creative flow. Although Markdown has done away with formatting operations, sometimes you still need to pay attention to details like spaces between Chinese and English, and blank lines between paragraphs. MDX Editor uses [prettier](https://prettier.io/) to format documents. Just press `command+s` to automatically format the document.

![](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/333d527b57194ebda5d246e15cc54ab1~tplv-k3u1fbpfcp-zoom-in-crop-mark:1512:0:0:0.awebp)

## Conclusion

If you're interested in this editor, you can download the desktop version from [Github](https://github.com/maqi1520/mdx-editor) to try it out. If you're curious about the implementation process, you can also directly view the source code. If you have any suggestions, feel free to raise issues on the repository.