Original indention and text delimiter style retained when rendering #106

Now the original indention is captured and string delimiters are retained when rendering out documents.

Signed-off-by: Dave Shanley <dave@quobix.com>

# fixes 106
This commit is contained in:
Dave Shanley
2023-06-16 09:50:27 -04:00
committed by quobix
parent 5b128c098a
commit e1f0f69650
8 changed files with 172 additions and 52 deletions

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"net/url"
"regexp"
"sort"
"strconv"
"strings"
@@ -674,3 +675,19 @@ func CheckEnumForDuplicates(seq []*yaml.Node) []*yaml.Node {
}
return res
}
// DetermineWhitespaceLength will determine the length of the whitespace for a JSON or YAML file.
func DetermineWhitespaceLength(input string) int {
exp := regexp.MustCompile(`\n( +)`)
whiteSpace := exp.FindAllStringSubmatch(input, -1)
var filtered []string
for i := range whiteSpace {
filtered = append(filtered, whiteSpace[i][1])
}
sort.Strings(filtered)
if len(filtered) > 0 {
return len(filtered[0])
} else {
return 0
}
}