Skip to content

Commit

Permalink
add markdown link feature
Browse files Browse the repository at this point in the history
  • Loading branch information
mebitek committed Jun 9, 2023
1 parent d34c8d5 commit 06c823a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ___
* italic
* bold + italic
* inline code
* links

# planned features

Expand Down
19 changes: 19 additions & 0 deletions deck_markdown/deck_markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ func GetMarkDownDescription(text string, configuration utils.Configuration) stri
} else {
line = fmt.Sprintf("[-:-:-]%s\n", strings.ReplaceAll(line, "```", ""))
}
} else if len(checkLink(line)) > 0 {
result := checkLink(line)
for _, r := range result {
rTmp := strings.ReplaceAll(r[1], "[", "")
r[1] = strings.ReplaceAll(rTmp, "]", "")
line = fmt.Sprintf("%s", strings.ReplaceAll(line, r[0], fmt.Sprintf("[#00ffaf]%s [#5f5fff:-:u]%s[-:-:-]", strings.ReplaceAll(r[1], "[", ""), r[2])))
}
} else {
line = fmt.Sprintf("%s\n", tview.Escape(line))
}

// bold + italic
result := getStringInBetween(line, "\\*\\*\\*", "\\*\\*\\*")
if len(result) > 0 {
Expand Down Expand Up @@ -71,6 +79,7 @@ func GetMarkDownDescription(text string, configuration utils.Configuration) stri
}
line = fmt.Sprintf("%s", strings.ReplaceAll(line, "`", ""))
}

lineContainer = lineContainer + fmt.Sprintf("%s", line)
}

Expand All @@ -86,3 +95,13 @@ func getStringInBetween(str string, start string, end string) (result [][]string
return
}
}

func checkLink(str string) (result [][]string) {
re := regexp.MustCompile(`(\[[^][]+])\((https?:\/\/[^()]+)\)`)
match := re.FindAllStringSubmatch(str, -1)
if len(match) > 0 {
return match
} else {
return
}
}
2 changes: 1 addition & 1 deletion deck_ui/deck_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"tui-deck/utils"
)

const VERSION = "v0.5.7"
const VERSION = "v0.5.8"

var FullFlex = tview.NewFlex()
var MainFlex = tview.NewFlex()
Expand Down

0 comments on commit 06c823a

Please sign in to comment.