d2dagrelayout: Fix regexp

See https://github.com/terrastruct/d2/pull/394#discussion_r1042504655
This commit is contained in:
Anmol Sethi 2022-12-07 19:21:56 -08:00
parent cb414e5382
commit d4d6c760e5
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA

View file

@ -261,7 +261,7 @@ func escapeID(id string) string {
// fixes \\
id = strings.ReplaceAll(id, "\\", `\\`)
// replaces \n with \\n whenever \n is not preceded by \ (does not replace \\n)
re := regexp.MustCompile(`[^\\](\n)`)
re := regexp.MustCompile(`[^\\]\n`)
id = re.ReplaceAllString(id, `\\n`)
// avoid an unescaped \r becoming a \n in the layout result
id = strings.ReplaceAll(id, "\r", `\r`)