https://github.com/oxeu/markdown
A markdown parser based on Regex and XML decoder for Kotlin Multiplatform Mobile
https://github.com/oxeu/markdown
Last synced: over 1 year ago
JSON representation
A markdown parser based on Regex and XML decoder for Kotlin Multiplatform Mobile
- Host: GitHub
- URL: https://github.com/oxeu/markdown
- Owner: OXeu
- Created: 2023-02-28T06:49:50.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-24T04:11:14.000Z (about 3 years ago)
- Last Synced: 2025-02-14T20:57:23.232Z (over 1 year ago)
- Language: Kotlin
- Size: 281 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Markdown 解析器
## 实现
### 1. Markdown to XML
使用正则表达式将Markdown替换为XML格式的文件,可根据实际使用需求更改生成的
XML格式
具体实现文件 `MarkdownParser.kt`
#### Example
```markdown
## Heading Atx 2
### Heading Atx 3
#### Heading Atx 4
##### Heading Atx 5
###### Heading Atx 6
####### Heading Atx 7
**Divider**
-----
__Bold___Italic_***BoldItalic***
[This is a link](https://this.is.a.link)

|Table | Hello | Test|
| --- | ----- | ----|
| Android| iOS | Windows |
| Flyme | MIUI | HarmonyOS |
| Linux | macOS| Windows 10 |
========
> This is a quote
> > Quote in quote
> **Bold Quote***Italic* And `code` Test
```CodeFence
Just for fun ! Don't worry `Hello` *Italic*
===============
/```
- List Test
- Okay
- Sub List
- Sub List 2
- Unnormal List
- [ ] Check Box
- I'm Back
1. Ordered List
2. How about it
- Insert some thing Others
3. Oh my gosh!I think it did not work!
4. Just for test,don't worry!
Any else?
seems nothing!
Okay, **Run it!**
```
```xml
Heading Atx 2
Heading Atx 3
Heading Atx 4
Heading Atx 5
Heading Atx 6
Heading Atx 7
Divider
BoldItalicBoldItalic
https://fast.link/test
This is a link
Image as this
Table
Hello
Test
Android
iOS
Windows
Flyme
MIUI
HarmonyOS
Linux
macOS
Windows 10
This is a quote
Quote in quote
Bold QuoteItalic And code Test
Just for fun ! Don't worry `Hello` *Italic*
===============
- List Test
- Okay
- Sub List
- Sub List 2
- Unnormal List
- Check Box
- I'm Back
- Ordered List
- How about it
- Insert some thing Others
- Oh my gosh!I think it did not work!
- Just for test,don't worry!
Any else?
seems nothing!
Okay, Run it!
```
### 2. XML to AST Tree
使用有限状态机将XML解析为可遍历的AST Tree结构
实现文件:`AstParser.kt`
#### Feature
- 支持忽略异常闭合标签
- 兼容未关闭标签
- 支持属性
- 支持无值属性,如 ``
- 支持自闭合标签
#### Example
```xml
你好
Hello
```
```text
root(){
center(){},
unclosed-tag(){
h1(class => 1, attr => Hello, checked => ){
text(你好),
p(){
text(Hello)
}
}
}
}
```
## Js使用