update editor funcs

This commit is contained in:
2025-12-07 22:50:42 +07:00
parent ad248e3041
commit 468256b908
6 changed files with 197 additions and 40 deletions
+26 -1
View File
@@ -1,6 +1,7 @@
package story_service
import (
"bufio"
"context"
"encoding/json"
"fmt"
@@ -110,7 +111,7 @@ func (s *StoryService) UpdatePlace(node *GraphNode) error {
s.story.Places[i] = &Place{
Code: s.story.Places[i].Code,
Name: node.Name,
Text: node.Text,
Text: formatText(node.Text),
Applications: applications,
}
break
@@ -181,3 +182,27 @@ func (s *StoryService) GetGraph(ctx context.Context) *Graph {
Edges: edges,
}
}
func formatText(text string) string {
scanner := bufio.NewScanner(strings.NewReader(text))
scanner.Split(bufio.ScanLines)
lines := []string{}
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
res := ""
for i, line := range lines {
l := strings.TrimSpace(line)
if i > 0 {
res += "\n"
if len(l) > 0 {
res += " "
}
}
res += l
}
return res
}