mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 00:47:15 -04:00
Don't treat fragments as valid URLs
This commit is contained in:
+5
-3
@@ -2,6 +2,7 @@ package ansi
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"net/url"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A LinkElement is used to render hyperlinks.
|
// A LinkElement is used to render hyperlinks.
|
||||||
@@ -14,8 +15,7 @@ type LinkElement struct {
|
|||||||
|
|
||||||
func (e *LinkElement) Render(w io.Writer, ctx RenderContext) error {
|
func (e *LinkElement) Render(w io.Writer, ctx RenderContext) error {
|
||||||
var textRendered bool
|
var textRendered bool
|
||||||
if len(e.Text) > 0 &&
|
if len(e.Text) > 0 && e.Text != e.URL {
|
||||||
e.Text != e.URL {
|
|
||||||
textRendered = true
|
textRendered = true
|
||||||
|
|
||||||
el := &BaseElement{
|
el := &BaseElement{
|
||||||
@@ -52,7 +52,9 @@ func (e *LinkElement) Render(w io.Writer, ctx RenderContext) error {
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if len(e.URL) > 0 {
|
u, err := url.Parse(e.URL)
|
||||||
|
if err == nil &&
|
||||||
|
"#"+u.Fragment != e.URL { // if the URL only consists of an anchor, ignore it
|
||||||
pre := " "
|
pre := " "
|
||||||
style := ctx.options.Styles.Link
|
style := ctx.options.Styles.Link
|
||||||
if !textRendered {
|
if !textRendered {
|
||||||
|
|||||||
Reference in New Issue
Block a user