From 2d6a59128d25a5f37a33289191f71a3388279291 Mon Sep 17 00:00:00 2001 From: amitaifrey Date: Thu, 29 Aug 2024 13:53:05 +0300 Subject: [PATCH] syntax_sugar: add Highlight() function In most Markdown processors, ==%s== is used to highlight text so that it will appear with a yellow background. See https://www.codecademy.com/resources/docs/markdown/highlight for more information and an example. --- syntax_sugar.go | 6 ++++++ syntax_sugar_test.go | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/syntax_sugar.go b/syntax_sugar.go index 81fbb04..f0d867a 100644 --- a/syntax_sugar.go +++ b/syntax_sugar.go @@ -45,3 +45,9 @@ func BoldItalic(text string) string { func Code(text string) string { return fmt.Sprintf("`%s`", text) } + +// Highlight return text with highlight format. +// If you set text "Hello", it will be converted to "==Hello==". +func Highlight(text string) string { + return fmt.Sprintf("==%s==", text) +} diff --git a/syntax_sugar_test.go b/syntax_sugar_test.go index 78b3bad..4fef2da 100644 --- a/syntax_sugar_test.go +++ b/syntax_sugar_test.go @@ -110,3 +110,18 @@ func TestCode(t *testing.T) { } }) } + +func TestHighlight(t *testing.T) { + t.Parallel() + + t.Run("success Highlight()", func(t *testing.T) { + t.Parallel() + + want := "==Hello==" + got := Highlight("Hello") + + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("value is mismatch (-want +got):\n%s", diff) + } + }) +}