@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"errors"
5
+ "strings"
5
6
6
7
"github.com/xyproto/mode"
7
8
)
@@ -236,3 +237,63 @@ func (q *QuoteState) ParBraCount(line string) (int, int) {
236
237
qCopy .Process (line )
237
238
return qCopy .parCount , qCopy .braCount
238
239
}
240
+
241
+ // checkMultiLineString detects and updates the inCodeBlock state.
242
+ // For languages like Nim, Mojo, Python and Starlark.
243
+ func checkMultiLineString (trimmedLine string , inCodeBlock bool ) (bool , bool ) {
244
+ trimmedLine = strings .TrimPrefix (trimmedLine , "return " )
245
+ foundDocstringMarker := false
246
+ // Check for special syntax patterns that indicate the start of a multiline string
247
+ if trimmedLine == "\" \" \" " || trimmedLine == "'''" { // only 3 letters
248
+ inCodeBlock = ! inCodeBlock
249
+ foundDocstringMarker = true
250
+ } else if strings .HasSuffix (trimmedLine , " = \" \" \" " ) || strings .HasSuffix (trimmedLine , " = '''" ) {
251
+ inCodeBlock = true
252
+ foundDocstringMarker = true
253
+ } else if strings .HasPrefix (trimmedLine , "\" \" \" " ) && strings .HasSuffix (trimmedLine , "\" \" \" " ) { // this could be 6 letters
254
+ inCodeBlock = false
255
+ foundDocstringMarker = true
256
+ } else if strings .HasPrefix (trimmedLine , "'''" ) && strings .HasSuffix (trimmedLine , "'''" ) { // this could be 6 letters
257
+ inCodeBlock = false
258
+ foundDocstringMarker = true
259
+ } else if strings .HasPrefix (trimmedLine , "\" \" \" " ) || strings .HasPrefix (trimmedLine , "'''" ) { // this is more than 3 ts
260
+ inCodeBlock = ! inCodeBlock
261
+ if inCodeBlock {
262
+ foundDocstringMarker = true
263
+ }
264
+ } else if strings .HasSuffix (trimmedLine , "\" \" \" " ) || strings .HasSuffix (trimmedLine , "'''" ) { // this is more than 3 ts
265
+ if strings .Count (trimmedLine , "\" \" \" " )% 2 != 0 || strings .Count (trimmedLine , "'''" )% 2 != 0 {
266
+ inCodeBlock = ! inCodeBlock
267
+ }
268
+ if inCodeBlock {
269
+ foundDocstringMarker = true
270
+ }
271
+ }
272
+ return inCodeBlock , foundDocstringMarker
273
+ }
274
+
275
+ // checkMultiLineString2 detects and updates the inCodeBlock state.
276
+ // For languages like Nim, Mojo, Python and Starlark.
277
+ func checkMultiLineString2 (trimmedLine string , inCodeBlock bool ) (bool , bool ) {
278
+ foundDocstringMarker := false
279
+ if trimmedLine == "return \" \" \" " || trimmedLine == "return '''" {
280
+ inCodeBlock = true
281
+ foundDocstringMarker = false
282
+ } else if trimmedLine == "\" \" \" " || trimmedLine == "'''" { // only 3 letters
283
+ inCodeBlock = ! inCodeBlock
284
+ foundDocstringMarker = true
285
+ } else if strings .HasPrefix (trimmedLine , "\" \" \" " ) && strings .HasSuffix (trimmedLine , "\" \" \" " ) {
286
+ inCodeBlock = false
287
+ foundDocstringMarker = true
288
+ } else if strings .HasPrefix (trimmedLine , "'''" ) && strings .HasSuffix (trimmedLine , "'''" ) {
289
+ inCodeBlock = false
290
+ foundDocstringMarker = true
291
+ } else if strings .HasPrefix (trimmedLine , "\" \" \" " ) || strings .HasPrefix (trimmedLine , "'''" ) {
292
+ inCodeBlock = ! inCodeBlock
293
+ foundDocstringMarker = true
294
+ } else if strings .HasSuffix (trimmedLine , "\" \" \" " ) || strings .HasSuffix (trimmedLine , "'''" ) {
295
+ inCodeBlock = ! inCodeBlock
296
+ foundDocstringMarker = true
297
+ }
298
+ return inCodeBlock , foundDocstringMarker
299
+ }
0 commit comments