summaryrefslogtreecommitdiff
path: root/internal/showcase/code_extractor.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/showcase/code_extractor.go')
-rw-r--r--internal/showcase/code_extractor.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/internal/showcase/code_extractor.go b/internal/showcase/code_extractor.go
index 3b0e8bc..92ee1e4 100644
--- a/internal/showcase/code_extractor.go
+++ b/internal/showcase/code_extractor.go
@@ -482,10 +482,7 @@ func stripComments(code string) string {
if trimmed == "" {
// Keep empty lines for readability
result = append(result, line)
- } else if strings.HasPrefix(trimmed, "//") ||
- strings.HasPrefix(trimmed, "#") && !strings.HasPrefix(trimmed, "#include") && !strings.HasPrefix(trimmed, "#define") ||
- strings.HasPrefix(trimmed, "<!--") ||
- strings.HasPrefix(trimmed, "*") && len(trimmed) > 1 && trimmed[1] == ' ' {
+ } else if isCommentLine(trimmed) {
// Skip comment lines
continue
} else if strings.HasPrefix(trimmed, "\"\"\"") || strings.HasPrefix(trimmed, "'''") {
@@ -522,6 +519,13 @@ func stripComments(code string) string {
return strings.Join(result, "\n")
}
+func isCommentLine(trimmed string) bool {
+ return strings.HasPrefix(trimmed, "//") ||
+ (strings.HasPrefix(trimmed, "#") && !strings.HasPrefix(trimmed, "#include") && !strings.HasPrefix(trimmed, "#define")) ||
+ strings.HasPrefix(trimmed, "<!--") ||
+ (strings.HasPrefix(trimmed, "*") && len(trimmed) > 1 && trimmed[1] == ' ')
+}
+
// removeCommonIndentation removes common leading whitespace from all lines
func removeCommonIndentation(lines []string) []string {
if len(lines) == 0 {