Skip to content

Commit

Permalink
add todo feature, update example image, improve readme
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishrb committed Oct 10, 2024
1 parent 4978007 commit 95cd0b5
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 12 deletions.
Binary file added .github/docs/example-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed .github/docs/examples.png
Binary file not shown.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
</p>
</div>

## ⚡️Features

* ⚡️Written in Go
* 📄 Render markdown to HTML and view it in your browser
* 📱 Dark and white mode
* 🎨 Syntax highlighting for code
* [x] Todo list like the one on GitHub

> [!TIP]
> Support of blockquotes (note, tip, important, warning and caution) [see here](https://github.com/orgs/community/discussions/16925)
## 🚀 Getting started

To install go-grip, simply:
Expand Down Expand Up @@ -58,14 +69,13 @@ To terminate the current server simply press `CTRL-C`.

## 📝 Examples

<img src="./.github/docs/examples.png" alt="examples" width="1000"/>
<img src="./.github/docs/example-1.png" alt="examples" width="1000"/>

## 🐛 Known TODOs / Bugs

* [ ] Checkboxes (like in this todo list)
* [ ] Tests and refactoring

* [ ] Make it possible to export the generated html

## 📌 Similar tools

This tool is, like the name already says, a reimplementation of [grip](https://github.com/joeyespo/grip) in go and without using the web API of GitHub.
This tool is a Go-based reimplementation of the original [grip](https://github.com/joeyespo/grip), offering the same functionality without relying on GitHub's web API.
59 changes: 51 additions & 8 deletions pkg/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func (client *Client) renderHook(w io.Writer, node ast.Node, entering bool) (ast
return renderHookBlockquote(w, node, entering)
case *ast.Text:
return renderHookText(w, node)
case *ast.ListItem:
return renderHookListItem(w, node, entering)
case *ast.CodeBlock:
return renderHookCodeBlock(w, node, client.Dark)
}
Expand Down Expand Up @@ -108,20 +110,61 @@ func renderHookText(w io.Writer, node ast.Node) (ast.WalkStatus, bool) {
}

_, ok = paragraph.GetParent().(*ast.BlockQuote)
if ok {
// Remove prefixes
for _, b := range blockquotes {
content, found := strings.CutPrefix(string(block.Literal), fmt.Sprintf("[!%s]", strings.ToUpper(b)))
if found {
io.WriteString(w, content)
return ast.GoToNext, true
}
}
}

_, ok = paragraph.GetParent().(*ast.ListItem)
if ok {
content, found := strings.CutPrefix(string(block.Literal), "[ ]")
content = `<input type="checkbox" disabled class="task-list-item-checkbox"> ` + content
if found {
io.WriteString(w, content)
return ast.GoToNext, true
}

content, found = strings.CutPrefix(string(block.Literal), "[x]")
content = `<input type="checkbox" disabled class="task-list-item-checkbox" checked> ` + content
if found {
io.WriteString(w, content)
return ast.GoToNext, true
}
}

return ast.GoToNext, false
}

func renderHookListItem(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
block := node.(*ast.ListItem)

paragraph, ok := (block.GetChildren()[0]).(*ast.Paragraph)
if !ok {
return ast.GoToNext, false
}

// Remove prefixes
for _, b := range blockquotes {
content, found := strings.CutPrefix(string(block.Literal), fmt.Sprintf("[!%s]", strings.ToUpper(b)))
if found {
io.WriteString(w, content)
return ast.GoToNext, true
}
t, ok := (paragraph.GetChildren()[0]).(*ast.Text)
if !ok {
return ast.GoToNext, false
}

return ast.GoToNext, false
if !(strings.HasPrefix(string(t.Literal), "[ ]") || strings.HasPrefix(string(t.Literal), "[x]")) {
return ast.GoToNext, false
}

if entering {
io.WriteString(w, "<li class=\"task-list-item\">")
} else {
io.WriteString(w, "</li>")
}

return ast.GoToNext, true
}

func createBlockquoteStart(alert string) (string, error) {
Expand Down

0 comments on commit 95cd0b5

Please sign in to comment.