grim/youtrack-import

Fully (?) support code blocks. Fixes YI-28
draft
2020-07-29, Gary Kramlich
3fbb1caeed04
Parents 05e3584f22bf
Children 6e41a2be36b1
Fully (?) support code blocks. Fixes YI-28
--- a/trac/tickets.go Tue Jul 28 22:11:55 2020 -0500
+++ b/trac/tickets.go Wed Jul 29 01:35:22 2020 -0500
@@ -96,6 +96,11 @@
// trac comments that are replies specify usernames which we can't/don't
// want to put in our resulting comments.
commentReplyingRegex = regexp.MustCompile(`^(?:(?:\> )*Replying to (?:[^]]+)\]:\r\n)+`)
+
+ // trac's comments use {{{ and }}} for code blocks. We need to convert them.
+ // Also, you can have a code block in a block quote which is why we have
+ // (?:\> )* to make sure that'll be supported.
+ commentCodeBlockRegex = regexp.MustCompile(`(?s)((?:^|\r\n)(?:\> )*)(?:\s*{{{\s*)(\r\n.*?)(?: *}}}\s*?)(\r\n|$)`)
)
func (tc *ticketChange) cleanNewValue() string {
@@ -105,6 +110,10 @@
newComment = commentReplyingRegex.ReplaceAllString(newComment, "")
}
+ if strings.Contains(newComment, "{{{") {
+ newComment = commentCodeBlockRegex.ReplaceAllString(newComment, "$1```$2```$3")
+ }
+
return newComment
}