From a1bbcd27c8ac3f5500cff309662c9926977083cd Mon Sep 17 00:00:00 2001 From: szktkfm Date: Sun, 10 Mar 2024 17:44:36 +0900 Subject: [PATCH] add emphsis parser --- README.md | 7 ++++--- element.go | 34 ++++++++++++++++++++++++++++++++-- parser.go | 2 +- table.go | 2 +- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a1363d8..c1d3119 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,13 @@ | Key binding | Description | |------------------|--------------------| | `Arrows`, `hjkl` | Move cursor | -| `Enter` | Enter directory | +| `Enter` :100: | Enter directory | | `Backspace` | Exit directory | | `Space` | Toggle preview | -| `Esc`, _q_ | Exit with cd | +| **Esc**, _q_ | Exit with cd | | `Ctrl+c` | Exit without cd | -| `/` | Fuzzy search | +| `/` hdidfj| Fuzzy search | +|djdfjfj` hdidfj| Fuzzy search | | `dd` | Delete file or dir | | `y` | yank current dir | diff --git a/element.go b/element.go index 2ae78c4..ab7229c 100644 --- a/element.go +++ b/element.go @@ -3,6 +3,7 @@ package mdtt import ( "bytes" + east "github.com/yuin/goldmark-emoji/ast" "github.com/yuin/goldmark/ast" astext "github.com/yuin/goldmark/extension/ast" ) @@ -49,6 +50,26 @@ func (tr *ModelBuilder) NewElement(node ast.Node, source []byte) Element { }, } + case ast.KindEmphasis: + // n := node.(*ast.CodeSpan) + n := node.(*ast.Emphasis) + return Element{ + Renderer: func(b *bytes.Buffer) { + if n.Level == 2 { + b.WriteString("**") + return + } + b.WriteString("_") + }, + Finisher: func(b *bytes.Buffer) { + if n.Level == 2 { + b.WriteString("**") + return + } + b.WriteString("_") + }, + } + case astext.KindTableCell: return Element{ Renderer: func(b *bytes.Buffer) { @@ -80,8 +101,17 @@ func (tr *ModelBuilder) NewElement(node ast.Node, source []byte) Element { // case astext.KindTaskCheckBox: // case ast.KindTextBlock: - // case east.KindEmoji: - // n := node.(*east.Emoji) + case east.KindEmoji: + n := node.(*east.Emoji) + return Element{ + Renderer: func(b *bytes.Buffer) { + b.WriteString(string(n.Value.Unicode)) + }, + Finisher: func(b *bytes.Buffer) { + b.WriteString("") + }, + } + // return Element{ // Renderer: &BaseElement{ // Token: string(n.Value.Unicode), diff --git a/parser.go b/parser.go index 834cfb2..cc83718 100644 --- a/parser.go +++ b/parser.go @@ -20,6 +20,7 @@ var highPriority = 100 func parse(file string) Model { f, _ := os.Open(file) + defer f.Close() s, _ := io.ReadAll(f) md := goldmark.New( @@ -155,7 +156,6 @@ func (r *ModelBuilder) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) { func (r *ModelBuilder) renderNode(w util.BufWriter, source []byte, node ast.Node, entering bool) (ast.WalkStatus, error) { if entering { log.Debugf(">Start %v = %v", node.Kind().String(), string(node.Text(source))) - // TODO: inline系の処理を追加する if node.Kind() == astext.KindTable { r.inTable = true diff --git a/table.go b/table.go index c099d7f..d9c89cf 100644 --- a/table.go +++ b/table.go @@ -503,8 +503,8 @@ func (m *TableModel) Del() tea.Cmd { func (m *TableModel) AddColumn() { var rows []Row - cell := NewCell("") for i := range m.rows { + cell := NewCell("") rows = append(rows, insertCell(m.rows[i], m.cursor.x+1, cell)) } m.SetRows(rows)