65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
package dingtalk
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type cardContentShape struct {
|
|
bytes int
|
|
lines int
|
|
pipeLines int
|
|
leadingPipeLines int
|
|
delimiterLines int
|
|
confirmedTable bool
|
|
confirmedTablePos int
|
|
}
|
|
|
|
func inspectCardContent(content string) cardContentShape {
|
|
shape := cardContentShape{
|
|
bytes: len(content),
|
|
confirmedTablePos: -1,
|
|
}
|
|
if content == "" {
|
|
return shape
|
|
}
|
|
shape.lines = strings.Count(content, "\n") + 1
|
|
|
|
lines := splitMarkdownStreamLines(content)
|
|
for i, line := range lines {
|
|
if strings.Contains(line.text, "|") {
|
|
shape.pipeLines++
|
|
}
|
|
if isTableHeaderCandidate(line.text) {
|
|
shape.leadingPipeLines++
|
|
}
|
|
if !line.inFence && isCompleteTableDelimiter(line.text) {
|
|
shape.delimiterLines++
|
|
}
|
|
if shape.confirmedTable || i == 0 || line.inFence || lines[i-1].inFence {
|
|
continue
|
|
}
|
|
if isTableHeaderCandidate(lines[i-1].text) && isCompleteTableDelimiter(line.text) {
|
|
shape.confirmedTable = true
|
|
shape.confirmedTablePos = lines[i-1].start
|
|
}
|
|
}
|
|
return shape
|
|
}
|
|
|
|
func formatCardUpdateDiagnostic(content string, isFinalize, isError bool) string {
|
|
shape := inspectCardContent(content)
|
|
return fmt.Sprintf(
|
|
"DingTalk card update shape: finalize=%t error=%t bytes=%d lines=%d pipe_lines=%d leading_pipe_lines=%d delimiter_lines=%d confirmed_table=%t table_start=%d",
|
|
isFinalize,
|
|
isError,
|
|
shape.bytes,
|
|
shape.lines,
|
|
shape.pipeLines,
|
|
shape.leadingPipeLines,
|
|
shape.delimiterLines,
|
|
shape.confirmedTable,
|
|
shape.confirmedTablePos,
|
|
)
|
|
}
|