2019-01-27 19:31:06 +00:00
|
|
|
package hyperlink
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type export string
|
|
|
|
|
|
|
|
var Export = export("hyperlink")
|
|
|
|
|
|
|
|
func (syn export) Regex() *regexp.Regexp {
|
2019-01-31 08:28:57 +00:00
|
|
|
return regexp.MustCompile(`(?m)(^|[^\x1b])\[([^(?:\]()]+)\]\(([^\)]+)\)`)
|
2019-01-27 19:31:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (syn export) Transform(args ...string) (string, error) {
|
|
|
|
// no arg, empty -> ignore
|
2019-01-31 08:28:57 +00:00
|
|
|
if len(args) < 2 || len(args[1]) < 1 {
|
2019-01-27 19:31:06 +00:00
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
2019-01-31 08:28:22 +00:00
|
|
|
linkstart := fmt.Sprintf("\x1b]8;;%s\x1b\\", args[2])
|
|
|
|
linkend := fmt.Sprintf("\x1b]8;;\x1b\\")
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s%s%s%s", args[0], linkstart, args[1], linkend), nil
|
2019-01-27 19:31:06 +00:00
|
|
|
}
|