Skip to content

Commit

Permalink
fix for url
Browse files Browse the repository at this point in the history
  • Loading branch information
szktkfm committed Apr 7, 2024
1 parent f5174d5 commit c030d0f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
50 changes: 29 additions & 21 deletions element.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package mdtt

import (
"bytes"
"strings"

"github.com/charmbracelet/log"
east "github.com/yuin/goldmark-emoji/ast"
"github.com/yuin/goldmark/ast"
astext "github.com/yuin/goldmark/extension/ast"
Expand All @@ -19,23 +21,34 @@ func (tr *ModelBuilder) NewElement(node ast.Node, source []byte) Element {

switch node.Kind() {

// case ast.KindLink:
// return Element{}

// case ast.KindAutoLink:
// return Element{}
case ast.KindLink:
n := node.(*ast.Link)
log.Debug(n)
return Element{
Renderer: func(b *bytes.Buffer) {
b.WriteString("[")
},
Finisher: func(b *bytes.Buffer) {
b.WriteString("](")
b.WriteString(string(n.Destination))
b.WriteString(")")
},
}
case ast.KindAutoLink:
n := node.(*ast.AutoLink)
u := string(n.URL(source))
if n.AutoLinkType == ast.AutoLinkEmail && !strings.HasPrefix(strings.ToLower(u), "mailto:") {
u = "mailto:" + u
}

case ast.KindImage:
// n := node.(*ast.Image)
// text := string(n.Text(source))
// return Element{
// Renderer: &ImageElement{
// Text: text,
// BaseURL: ctx.options.BaseURL,
// URL: string(n.Destination),
// },
// }
return Element{}
return Element{
Renderer: func(b *bytes.Buffer) {
b.WriteString(u)
},
Finisher: func(b *bytes.Buffer) {
b.WriteString("")
},
}

case ast.KindCodeSpan:
return Element{
Expand Down Expand Up @@ -83,7 +96,6 @@ func (tr *ModelBuilder) NewElement(node ast.Node, source []byte) Element {
}

case ast.KindText:
// n := node.(*ast.CodeSpan)
return Element{
Renderer: func(b *bytes.Buffer) {
b.WriteString(string(node.Text(source)))
Expand All @@ -93,10 +105,6 @@ func (tr *ModelBuilder) NewElement(node ast.Node, source []byte) Element {
},
}

//
// case astext.KindTaskCheckBox:
// case ast.KindTextBlock:

case east.KindEmoji:
n := node.(*east.Emoji)
return Element{
Expand Down
6 changes: 0 additions & 6 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/charmbracelet/bubbles/viewport"
tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
"github.com/mattn/go-runewidth"
)

Expand Down Expand Up @@ -620,14 +619,12 @@ func (m *TableModel) MoveDown(n int) {
func (m *TableModel) MoveRight(n int) {
m.cursor.x = clamp(m.cursor.x+n, 0, len(m.cols)-1)
m.UpdateViewport()
//TODO viewport
}

// MoveRight moves the selection right by any number of rows.
func (m *TableModel) MoveLeft(n int) {
m.cursor.x = clamp(m.cursor.x-n, 0, len(m.cols)-1)
m.UpdateViewport()
//TODO viewport
}

// GotoTop moves the selection to the first row.
Expand Down Expand Up @@ -686,11 +683,8 @@ func (m *TableModel) renderRow(rowID int) string {
}

if isSelected {
log.Debug("selected", value)
renderedCell = m.styles.Selected.Render(style.Render(value))
log.Debug("renderd cell", renderedCell)
} else {
log.Debug("not selected", value)
renderedCell = m.styles.Cell.Render(style.Render(value))
}

Expand Down

0 comments on commit c030d0f

Please sign in to comment.