Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkg/convert/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,24 @@ tar -czvf {{path/to/archive.tar.gz}} {{path/to/directory}}
}
}

func TestConvertTldrBareFencePreservesMultilineCommandAndFollowingExample(t *testing.T) {
input := "# echo\n\n" +
"- Print two greetings:\n\n```\necho hello\necho world\n```\n\n" +
"- Print farewell:\n\n`echo goodbye`\n"

converted, err := ConvertTldr(input, "echo.md")
if err != nil {
t.Fatalf("ConvertTldr failed: %v", err)
}

want := "# Converted TLDR for Echo\n\n" +
"## Print two greetings\n\n```sh\necho hello\necho world\n```\n\n" +
"## Print farewell\n\n```sh\necho goodbye\n```\n\n"
if converted != want {
t.Errorf("ConvertTldr output mismatch\ngot:\n%s\nwant:\n%s", converted, want)
}
}

// ============================================================================
// TLDR placeholder-shape tests
// ============================================================================
Expand Down
6 changes: 3 additions & 3 deletions pkg/convert/tldr.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ func (p *tldrParser) parseLine(lines []string, index int) int {
// `\`\`\`sh ... \`\`\“ form (used by some real-world pages).
func readCommand(lines []string, index int) (cmd string, consumed int) {
line := strings.TrimSpace(lines[index])
if strings.HasPrefix(line, "`") && strings.HasSuffix(line, "`") && len(line) >= 2 {
return line[1 : len(line)-1], index
}
if strings.HasPrefix(line, "```") {
body, end := consumeCodeBlock(lines, index+1)
return body, end
}
if strings.HasPrefix(line, "`") && strings.HasSuffix(line, "`") && len(line) >= 2 {
return line[1 : len(line)-1], index
}
return "", index
}

Expand Down
Loading