Skip to content

Commit

Permalink
✨ 支持 kramdown 行级属性列表 #89
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Sep 12, 2020
1 parent 4c62140 commit 51b905e
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
1 change: 1 addition & 0 deletions lute.go
Expand Up @@ -100,6 +100,7 @@ func NewOptions() *parse.Options {
YamlFrontMatter: true,
BlockRef: false,
Mark: false,
KramdownIAL: false,
}
}

Expand Down
2 changes: 1 addition & 1 deletion parse/code_block.go
Expand Up @@ -51,7 +51,7 @@ func CodeBlockContinue(codeBlock *ast.Node, context *Context) int {
return 0
}

func codeBlockFinalize(codeBlock *ast.Node) {
func (context *Context) codeBlockFinalize(codeBlock *ast.Node) {
if codeBlock.IsFencedCodeBlock {
content := codeBlock.Tokens
length := len(content)
Expand Down
2 changes: 1 addition & 1 deletion parse/html_block.go
Expand Up @@ -24,7 +24,7 @@ func HtmlBlockContinue(html *ast.Node, context *Context) int {
return 0
}

func htmlBlockFinalize(html *ast.Node) {
func (context *Context) htmlBlockFinalize(html *ast.Node) {
_, html.Tokens = lex.TrimRight(lex.ReplaceNewlineSpace(html.Tokens))
}

Expand Down
25 changes: 25 additions & 0 deletions parse/inline_attribute_list.go
@@ -0,0 +1,25 @@
// Lute - 一款对中文语境优化的 Markdown 引擎,支持 Go 和 JavaScript
// Copyright (c) 2019-present, b3log.org
//
// Lute is licensed under Mulan PSL v2.
// You can use this software according to the terms and conditions of the Mulan PSL v2.
// You may obtain a copy of Mulan PSL v2 at:
// http://license.coscl.org.cn/MulanPSL2
// THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
// See the Mulan PSL v2 for more details.

package parse

import "github.com/88250/lute/ast"

func (context *Context) parseKramdownIAL(block *ast.Node) {
if !context.Option.KramdownIAL {
return
}


switch block.Type {
case ast.NodeParagraph:

}
}
2 changes: 1 addition & 1 deletion parse/list.go
Expand Up @@ -18,7 +18,7 @@ import (
"strconv"
)

func listFinalize(list *ast.Node) {
func (context *Context) listFinalize(list *ast.Node) {
item := list.FirstChild

// 检查子列表项之间是否包含空行,包含的话说明该列表是非紧凑的,即松散的
Expand Down
2 changes: 2 additions & 0 deletions parse/paragraph.go
Expand Up @@ -91,9 +91,11 @@ func paragraphFinalize(p *ast.Node, context *Context) (insertTable bool) {
if nil != paragraph {
p.Tokens = paragraph.Tokens
p.InsertAfter(table)
context.parseKramdownIAL(p)
// 设置末梢及其状态
table.Close = true
context.Tip = table
context.parseKramdownIAL(table)
return true
} else {
// 将该段落节点转成表节点
Expand Down
9 changes: 6 additions & 3 deletions parse/parse.go
Expand Up @@ -155,9 +155,9 @@ func (context *Context) finalize(block *ast.Node, lineNum int) {
// 节点最终化处理。比如围栏代码块提取 info 部分;HTML 代码块剔除结尾空格;段落需要解析链接引用定义等。
switch block.Type {
case ast.NodeCodeBlock:
codeBlockFinalize(block)
context.codeBlockFinalize(block)
case ast.NodeHTMLBlock:
htmlBlockFinalize(block)
context.htmlBlockFinalize(block)
case ast.NodeParagraph:
insertTable := paragraphFinalize(block, context)
if insertTable {
Expand All @@ -168,9 +168,10 @@ func (context *Context) finalize(block *ast.Node, lineNum int) {
case ast.NodeYamlFrontMatter:
context.yamlFrontMatterFinalize(block)
case ast.NodeList:
listFinalize(block)
context.listFinalize(block)
}

context.parseKramdownIAL(block)
context.Tip = parent
}

Expand Down Expand Up @@ -295,6 +296,8 @@ type Options struct {
BlockRef bool
// Mark 设置是否打开“==标记==”支持。
Mark bool
// KramdownIAL 设置是否打开 kramdown 行级属性列表支持。 https://kramdown.gettalong.org/syntax.html#inline-attribute-lists
KramdownIAL bool
}

func (context *Context) ParentTip() {
Expand Down

0 comments on commit 51b905e

Please sign in to comment.