Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix parsing CRLF files, part 2 #4

Merged
merged 1 commit into from
Sep 24, 2021
Merged
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
8 changes: 4 additions & 4 deletions read.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ func Parse(data []byte) (*Document, error) {
var expectCodeBlock bool
var codeBlockOffset int
hunkInProgress := DocHunk{LineStart: -1}
for i, line := range doc.Lines {
for i, origLine := range doc.Lines {
// Support CRLF line endings, for Windows.
line = bytes.TrimSuffix(line, sigilCarriageReturn)
line := bytes.TrimSuffix(origLine, sigilCarriageReturn)

// Check for transition in or out of codeblock.
if bytes.HasPrefix(line, sigilCodeBlock) {
switch inCodeBlock {
case false: // starting a block
if expectCodeBlock {
hunkInProgress.BlockTag = string(line[len(sigilCodeBlock):])
codeBlockOffset = offset + len(line) + 1
codeBlockOffset = offset + len(origLine) + 1
}
expectCodeBlock = false
case true: // ending a block
Expand Down Expand Up @@ -120,7 +120,7 @@ func Parse(data []byte) (*Document, error) {
next:
// Track total offset, so we can use it to subslice out document hunks.
// Mind: this is going to be off by one at the very end of the file... but that turns out never to matter to us.
offset += len(line) + 1
offset += len(origLine) + 1
}
return &doc, nil
}