An open API service indexing awesome lists of open source software.

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

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)
![Image as this](https://img.com/test-image)
|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



  1. Ordered List

  2. How about it


- Insert some thing Others


  1. Oh my gosh!I think it did not work!


    1. 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使用