Skip to content

using underline with a different fg color breaks it #206

@Yakiyo

Description

@Yakiyo

I'm trying to pretty print a markdown file. The file uses {{ some-text }} in it for indicating variables, im removing the {{/}} and underline the inner text, and i'm also making the entire line cyan. But it seems, cyan get's removed after the first occurrence of the underlined word.
An example image:
image

The part of the code is somewhat like this

var underline = color.New(color.Underline).Sprint

line = highLightVariable(line)
line = color.CyanString(line)
fmt.Println(line)

func highLightVariable(line string) string {
	lines := strings.Split(line, "}}")
	lines = lo.Map(lines, func(line string, _ int) string {
		l := strings.Split(line, "{{")
		if len(l) > 1 {
			l[1] = underline(l[1])
		}
		return strings.Join(l, "{{")
	})
	line = strings.Join(lines, "}}")
	line = strings.ReplaceAll(line, "{{", "")
	line = strings.ReplaceAll(line, "}}", "")
	return line
}

the cyan colors stops after the first underlined word, even tho consequent words to have underlines.

In case, the full code is needed, check this

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions