From ba044d55b6dadb0486ac41f8f810785f4252a102 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Mon, 23 May 2022 09:53:26 -0700 Subject: [PATCH 1/5] Removing leading NL, compatible with Python textwrap.dedent("""\. If an extra newline is desired, it can be --- dedent.go | 2 ++ dedent_test.go | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dedent.go b/dedent.go index 9d5bfba..2819631 100644 --- a/dedent.go +++ b/dedent.go @@ -6,6 +6,7 @@ import ( ) var ( + leadingNewline = regexp.MustCompile("^[\n]") whitespaceOnly = regexp.MustCompile("(?m)^[ \t]+$") leadingWhitespace = regexp.MustCompile("(?m)(^[ \t]*)(?:[^ \t\n])") ) @@ -18,6 +19,7 @@ var ( func Dedent(text string) string { var margin string + text = leadingNewline.ReplaceAllString(text, "") text = whitespaceOnly.ReplaceAllString(text, "") indents := leadingWhitespace.FindAllStringSubmatch(text, -1) diff --git a/dedent_test.go b/dedent_test.go index ab3299e..8a1281a 100644 --- a/dedent_test.go +++ b/dedent_test.go @@ -65,8 +65,7 @@ func TestDedentUneven(t *testing.T) { while 1: return foo `, - expect: ` -def foo(): + expect: `def foo(): while 1: return foo `, @@ -153,10 +152,12 @@ func ExampleDedent() { consectetur adipiscing elit. Curabitur justo tellus, facilisis nec efficitur dictum, fermentum vitae ligula. Sed eu convallis sapien.` + fmt.Println("-------------") fmt.Println(Dedent(s)) fmt.Println("-------------") fmt.Println(s) // Output: + // ------------- // Lorem ipsum dolor sit amet, // consectetur adipiscing elit. // Curabitur justo tellus, facilisis nec efficitur dictum, From 4a428592122b09e62a78b47217f1b4529d7f29ea Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Thu, 26 May 2022 22:00:39 -0700 Subject: [PATCH 2/5] bumping module version to v2.0 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 9468fd1..30db09f 100644 --- a/go.mod +++ b/go.mod @@ -1 +1 @@ -module github.com/lithammer/dedent +module github.com/marhar/dedent/v2.0 From 1dc36d297db3c8b6fd6ef2f096618f7a58b9b168 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Thu, 26 May 2022 22:04:10 -0700 Subject: [PATCH 3/5] adding retract --- go.mod | 2 ++ 1 file changed, 2 insertions(+) diff --git a/go.mod b/go.mod index 30db09f..f0c71d3 100644 --- a/go.mod +++ b/go.mod @@ -1 +1,3 @@ module github.com/marhar/dedent/v2.0 + +retract v1.0.0 // Accidental publication. From 74a1ee70c46a809d6d34b1b38c1424bbfaf930d0 Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Thu, 26 May 2022 22:07:24 -0700 Subject: [PATCH 4/5] adding retract for v1.1.0 --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index f0c71d3..7fea93c 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/marhar/dedent/v2.0 -retract v1.0.0 // Accidental publication. +retract v1.1.0 // Accidental publication. From 33fb4211a91444402bf211a14b084c74867e254d Mon Sep 17 00:00:00 2001 From: Mark Harrison Date: Fri, 27 May 2022 10:57:35 -0700 Subject: [PATCH 5/5] resetting module path --- go.mod | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7fea93c..9468fd1 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1 @@ -module github.com/marhar/dedent/v2.0 - -retract v1.1.0 // Accidental publication. +module github.com/lithammer/dedent