From c030d0f1bc5a233bad4720d1d30afa0ff6ec18dd Mon Sep 17 00:00:00 2001 From: szktkfm Date: Sun, 7 Apr 2024 16:45:20 +0900 Subject: [PATCH] fix for url --- element.go | 50 +++++++++++++++++++++++++++++--------------------- table.go | 6 ------ 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/element.go b/element.go index 0e15432..69785b6 100644 --- a/element.go +++ b/element.go @@ -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" @@ -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{ @@ -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))) @@ -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{ diff --git a/table.go b/table.go index 1e90d62..fc7b6ee 100644 --- a/table.go +++ b/table.go @@ -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" ) @@ -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. @@ -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)) }