Skip to content

Commit

Permalink
add code span parser
Browse files Browse the repository at this point in the history
  • Loading branch information
szktkfm committed Mar 10, 2024
1 parent f5d2e4c commit 9b6bbd7
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 274 deletions.
114 changes: 1 addition & 113 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,3 @@
# 🥾 walk

<p align="center">
<br>
<img src=".github/images/demo.gif" width="600" alt="walk demo">
<br>
</p>

**Walk** — a terminal navigator.

Why another terminal navigator? I wanted something simple and minimalistic.
Something to help me with faster navigation in the filesystem; a `cd` and `ls`
replacement. So I build **walk**. It allows for quick navigation with fuzzy
searching, `cd` integration is quite simple. And you can open `vim` right from
the walk. That's it.

## Install

```
brew install walk
```

```
pkg_add walk
```

```
pacman -S walk
```

```
go install github.com/antonmedv/walk@latest
```

Or download [prebuild binaries](https://github.com/antonmedv/walk/releases).

Put the next function into the **.bashrc** or a similar config:

<table>
<tr>
<th> Bash/Zsh </th>
<th> Fish </th>
<th> PowerShell </th>
</tr>
<tr>
<td>

```bash
function lk {
cd "$(walk "$@")"
}
```

</td>
<td>

```fish
function lk
set loc (walk $argv); and cd $loc;
end
```

</td>
<td>

```powershell
function lk() {
cd $(walk $args)
}
```

</td>
</tr>
</table>


Now use `lk` command to start walking.

## Usage

Expand All @@ -84,7 +7,7 @@ Now use `lk` command to start walking.
| `Enter` | 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 |
| `dd` | Delete file or dir |
Expand All @@ -93,38 +16,3 @@ Now use `lk` command to start walking.
The `EDITOR` or `WALK_EDITOR` environment variable used for opening files from
the walk.

```bash
export EDITOR=vim
```

### Preview mode

Press `Space` to toggle preview mode.

<img src=".github/images/preview-mode.gif" width="600" alt="Walk Preview Mode">

### Delete file or directory

Press `dd` to delete file or directory. Press `u` to undo.

<img src=".github/images/rm-demo.gif" width="600" alt="Walk Deletes a File">

### Display icons

Install [Nerd Fonts](https://www.nerdfonts.com) and add `--icons` flag.

<img src=".github/images/demo-icons.gif" width="600" alt="Walk Icons Support">

### Image preview

No additional setup is required.

<img src=".github/images/images-mode.gif" width="600" alt="Walk Image Preview">

## Become a sponsor

Every line of code in my repositories 📖 signifies my unwavering commitment to open source 💡. Your support 🤝 ensures these projects keep thriving, innovating, and benefiting all 💼. If my work has ever resonated 🎵 or helped you, kindly consider showing love ❤️ by sponsoring. [**🚀 Sponsor Me Today! 🚀**](https://github.com/sponsors/antonmedv)

## License

[MIT](LICENSE)
203 changes: 61 additions & 142 deletions element.go
Original file line number Diff line number Diff line change
@@ -1,83 +1,31 @@
package mdtt

import (
"fmt"
"bytes"

east "github.com/yuin/goldmark-emoji/ast"
"github.com/yuin/goldmark/ast"
astext "github.com/yuin/goldmark/extension/ast"
)

type Element struct {
Entering string
Exiting string
Renderer func()
Finisher func()
Renderer func(b *bytes.Buffer)
Finisher func(b *bytes.Buffer)
}

// NewElement returns the appropriate render Element for a given node.
func (tr *ModelBuilder) NewElement(node ast.Node, source []byte) Element {
// ctx := tr.context
// fmt.Print(strings.Repeat(" ", ctx.blockStack.Len()), node.Type(), node.Kind())
// defer fmt.Println()

switch node.Kind() {
// // Document
// case ast.KindDocument:
// // Heading
// case ast.KindHeading:
// // Paragraph
// case ast.KindParagraph:
// // Blockquote
// case ast.KindBlockquote:
// // Lists
// case ast.KindList:

// case ast.KindListItem:
// // Text Elements
// case ast.KindText:

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

// case astext.KindStrikethrough:
case ast.KindThematicBreak:
// return Element{
// Entering: "",
// Exiting: "",
// Renderer: &BaseElement{
// Style: ctx.options.Styles.HorizontalRule,
// },
// }
// case ast.KindLink:
// return Element{}

// Links
case ast.KindLink:
//TODO
// n := node.(*ast.Link)
// return Element{
// Renderer: &LinkElement{
// Text: textFromChildren(node, source),
// BaseURL: ctx.options.BaseURL,
// URL: string(n.Destination),
// },
// }
// case ast.KindAutoLink:
// return Element{}

case ast.KindAutoLink:
// n := node.(*ast.AutoLink)
// u := string(n.URL(source))
// label := string(n.Label(source))
// if n.AutoLinkType == ast.AutoLinkEmail && !strings.HasPrefix(strings.ToLower(u), "mailto:") {
// u = "mailto:" + u
// }

// return Element{
// Renderer: &LinkElement{
// Text: label,
// BaseURL: ctx.options.BaseURL,
// URL: u,
// },
// }

// Images
case ast.KindImage:
// n := node.(*ast.Image)
// text := string(n.Text(source))
Expand All @@ -88,96 +36,67 @@ func (tr *ModelBuilder) NewElement(node ast.Node, source []byte) Element {
// URL: string(n.Destination),
// },
// }
return Element{}

case ast.KindCodeSpan:
// // n := node.(*ast.CodeSpan)
// e := &BlockElement{
// Block: &bytes.Buffer{},
// Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.options.Styles.Code, false),
// }
// return Element{
// Renderer: e,
// Finisher: e,
// }

// Tables
case astext.KindTable:
// te := &TableElement{}
// return Element{
// Entering: "\n",
// Renderer: te,
// Finisher: te,
// }
// n := node.(*ast.CodeSpan)
return Element{
Renderer: func(b *bytes.Buffer) {
b.WriteString("`")
},
Finisher: func(b *bytes.Buffer) {
b.WriteString("`")
},
}

case astext.KindTableCell:
// s := ""
// n := node.FirstChild()
// for n != nil {
// switch t := n.(type) {
// case *ast.AutoLink:
// s += string(t.Label(source))
// default:
// s += string(n.Text(source))
// }
return Element{
Renderer: func(b *bytes.Buffer) {
},
Finisher: func(b *bytes.Buffer) {
},
}

// n = n.NextSibling()
// }

// return Element{
// Renderer: &TableCellElement{
// Text: s,
// Head: node.Parent().Kind() == astext.KindTableHeader,
// },
// }

case astext.KindTableHeader:
// return Element{
// Finisher: &TableHeadElement{},
// }
case astext.KindTableRow:
// return Element{
// Finisher: &TableRowElement{},
// }

// HTML Elements
case ast.KindHTMLBlock:
// n := node.(*ast.HTMLBlock)
// return Element{
// Renderer: &BaseElement{
// Token: ctx.SanitizeHTML(string(n.Text(source)), true),
// Style: ctx.options.Styles.HTMLBlock.StylePrimitive,
// },
// }
// case ast.KindRawHTML:
// n := node.(*ast.RawHTML)
// return Element{
// Renderer: &BaseElement{
// Token: ctx.SanitizeHTML(string(n.Text(source)), true),
// Style: ctx.options.Styles.HTMLSpan.StylePrimitive,
// },
// }

// Definition Lists

// Handled by parents
case astext.KindTaskCheckBox:
// // handled by KindListItem
// return Element{}
case ast.KindTextBlock:
// return Element{}

case east.KindEmoji:
// n := node.(*east.Emoji)
// return Element{
// Renderer: &BaseElement{
// Token: string(n.Value.Unicode),
// },
// }
return Element{
Renderer: func(b *bytes.Buffer) {
},
Finisher: func(b *bytes.Buffer) {
},
}

case ast.KindText:
// n := node.(*ast.CodeSpan)
return Element{
Renderer: func(b *bytes.Buffer) {
b.WriteString(string(node.Text(source)))
},
Finisher: func(b *bytes.Buffer) {
b.WriteString("")
},
}

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

// case east.KindEmoji:
// n := node.(*east.Emoji)
// return Element{
// Renderer: &BaseElement{
// Token: string(n.Value.Unicode),
// },
// }
// return Element{}

// Unknown case
default:
fmt.Println("Warning: unhandled element", node.Kind().String())
return Element{}
return Element{
Renderer: func(b *bytes.Buffer) {
},
Finisher: func(b *bytes.Buffer) {
},
}
}
return Element{}
// return Element{}
}
Loading

0 comments on commit 9b6bbd7

Please sign in to comment.