Skip to content

Commit

Permalink
add emphsis parser
Browse files Browse the repository at this point in the history
  • Loading branch information
szktkfm committed Mar 10, 2024
1 parent 9b6bbd7 commit a1bbcd2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

Expand Down
34 changes: 32 additions & 2 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a1bbcd2

Please sign in to comment.