Skip to content

Commit

Permalink
🎨 使用新的 JSON 渲染方案 Fix #180
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Aug 8, 2022
1 parent c55f139 commit 915d625
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 1,306 deletions.
89 changes: 1 addition & 88 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,97 +321,10 @@ func main() {

![Vditor](https://b3logfile.com/file/2020/02/%E6%88%AA%E5%9B%BE%E4%B8%93%E7%94%A8-ef21ef12.png)

#### 关于 `lute.RenderJSON()` 的使用

```typescript
// JSONRenderer的类型
type JSONRendererType = Array<JSONRendererItemType>

// Flag节点
type FlagType = |
| "Paragraph"
| "Emphasis"
| "Strong"
| "Blockquote"
| "ListItem"
| "Strikethrough"
| "TableHead"
| "Table"
| "TableRow"
| "Mark"
| "Sub"
| "Sup"
| "Tag"
| "BlockRef"

// 非Flag节点
type NotFlagType = |
| "Heading"
| "ThematicBreak"
| "List"
| "HTMLBlock"
| "InlineHTML"
| "CodeBlock"
| "Text"
| "CodeSpan"
| "HardBreak"
| "SoftBreak"
| "Link"
| "Image"
| "HTMLEntity"
| "TaskListItemMarker"
| "TableCell"
| "EmojiUnicode"
| "EmojiImg"
| "MathBlock"
| "InlineMath"
| "YamlFrontMatter"
| "Backslash"
| "BlockEmbed"
| "BlockQueryEmbed"

interface JSONRendererItemType {
type?: string
value?: string
flag?: string
title?: string
language?: string
mindmap?: string
children?: Array<JSONRendererItemType>
}

// 节点分为四类:常规节点、flag节点、链接节点、代码块节点
interface NormalNodeType {
type: string
value: string
children?: Array<JSONRendererItemType>
}

interface FlagNodeType {
flag: string
children?: Array<JSONRendererItemType>
}

// 链接或者图片
interface LinkNodeType {
type: string
value: string
title: string
children?: Array<JSONRendererItemType>
}

interface CodeBlockType {
type: string
value: string
language: string
mindmap?: string // 如果language为mingmap
}
```

一些细节:

1. lute.js 没有内置语法高亮特性
2. lute.js 编译后大小为 ~2MB,通过 `brotli -o lute.min.js.br lute.min.js` 压缩后大小 ~200KB,常规 GZip 压缩后大小 ~300KB
2. lute.js 编译后大小为 ~3.5MB,GZip 压缩后大小 ~500KB

## 📜 文档

Expand Down
89 changes: 1 addition & 88 deletions README_en_US.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,94 +318,7 @@ For a simple example, please refer to the demo in the JavaScript directory. For
Some details:

1. lute.js has no built-in syntax highlighting feature
2. The size of lute.js after compilation is ~2MB, the size after compression through `brotli -o lute.min.js.br lute.min.js` is ~200KB, the size after regular GZip compression is ~300KB

#### How to use `lute.RenderJSON()`

```typescript
// Type of JSONRenderer
type JSONRendererType = Array<JSONRendererItemType>

// Flag Node
type FlagType = |
| "Paragraph"
| "Emphasis"
| "Strong"
| "Blockquote"
| "ListItem"
| "Strikethrough"
| "TableHead"
| "Table"
| "TableRow"
| "Mark"
| "Sub"
| "Sup"
| "Tag"
| "BlockRef"

// Non-Flag Node
type NotFlagType = |
| "Heading"
| "ThematicBreak"
| "List"
| "HTMLBlock"
| "InlineHTML"
| "CodeBlock"
| "Text"
| "CodeSpan"
| "HardBreak"
| "SoftBreak"
| "Link"
| "Image"
| "HTMLEntity"
| "TaskListItemMarker"
| "TableCell"
| "EmojiUnicode"
| "EmojiImg"
| "MathBlock"
| "InlineMath"
| "YamlFrontMatter"
| "Backslash"
| "BlockEmbed"
| "BlockQueryEmbed"

interface JSONRendererItemType {
type?: string
value?: string
flag?: string
title?: string
language?: string
mindmap?: string
children?: Array<JSONRendererItemType>
}

// Node has 4 types: Normal Node, Flag Node, Link Node, Codeblock Node
interface NormalNodeType {
type: string
value: string
children?: Array<JSONRendererItemType>
}

interface FlagNodeType {
flag: string
children?: Array<JSONRendererItemType>
}

// Link or Image
interface LinkNodeType {
type: string
value: string
title: string
children?: Array<JSONRendererItemType>
}

interface CodeBlockType {
type: string
value: string
language: string
mindmap?: string // if language is "mindmap"
}
```
2. The size of lute.js after compilation is ~3.5MB, the size after regular GZip compression is ~500KB

## 📜 Documentation

Expand Down
1 change: 1 addition & 0 deletions javascript/lute.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
document.getElementById('output').innerHTML = result;

console.log(lute.HTML2Md(result));
console.log(lute.RenderJSON(it.value));
}
</script>

Expand Down
44 changes: 30 additions & 14 deletions javascript/lute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/lute.min.js.map

Large diffs are not rendered by default.

0 comments on commit 915d625

Please sign in to comment.