Conversation
bwplotka
left a comment
There was a problem hiding this comment.
Amazing! Some suggestions, plus some test needed, otherwise LGTM!
pkg/mdformatter/mdgen/mdgen.go
Outdated
| case true: | ||
| val := strings.Split(linesToCopy, "-") | ||
| start, errStart := strconv.Atoi(val[0]) | ||
| if errStart != nil { |
There was a problem hiding this comment.
| if errStart != nil { | |
| if err != nil { |
Usually it's fine to shadow err variable if in short scope.
pkg/mdformatter/mdgen/mdgen.go
Outdated
|
|
||
| switch lineOk { | ||
| case true: | ||
| val := strings.Split(linesToCopy, "-") |
There was a problem hiding this comment.
I would propose the same semantics as Go slice, WDYT?
| val := strings.Split(linesToCopy, "-") | |
| val := strings.Split(linesToCopy, ":") |
There was a problem hiding this comment.
Sure! I think this would be better!
pkg/mdformatter/mdgen/mdgen.go
Outdated
| text = append(text, "\n"...) | ||
| } | ||
| line++ | ||
| } |
There was a problem hiding this comment.
Let's check scanner.Err() after this loop (same below)
pkg/mdformatter/mdgen/mdgen.go
Outdated
| } | ||
| line++ | ||
| } | ||
| case false: |
There was a problem hiding this comment.
Can we reuse the above, but just use start 0 and end = math.MaxInt64? (:
There was a problem hiding this comment.
Sure. Will make the necessary changes!
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
pkg/mdformatter/mdgen/mdgen.go
Outdated
| line++ | ||
| } | ||
| if err := scanner.Err(); err != nil { | ||
| return nil, errors.Errorf("scanner couldn't read: %v", err) |
There was a problem hiding this comment.
| return nil, errors.Errorf("scanner couldn't read: %v", err) | |
| return nil, errors.Wrap(err, "scanner read") |
| ) | ||
|
|
||
| func TestFormat_FormatSingle_CodeBlockTransformer(t *testing.T) { | ||
| f := mdformatter.New(context.Background(), mdformatter.WithCodeBlockTransformer(NewCodeBlockTransformer())) |
There was a problem hiding this comment.
Why not putting this in our e2e framework with input output markdown files? (:
Signed-off-by: Saswata Mukherjee <saswataminsta@yahoo.com>
bwplotka
left a comment
There was a problem hiding this comment.
Just noticed 🙈
To make sure we have one way of doing things... what's stops us without this PR to have mdox doing the same with:
```go mdox-gen-exec="sed -n '3,6p' main.go"
```
🤔
While this PR is great, I fear it would be best to decouple this logic and allow better tools sed to be used 🙈 WDYT?
IF you agree, we could add test case with sed to ensure this works instead of full code.
|
Sure! Will close this and open a new PR with the sed test case! |
This PR adds an
mdox-gen-fileoption which allows fetching code from local files into documentation like below. Addresses #18This results in the following when formatted,
If no line numbers are given like below, entire file is brought in by default (useful for blogs),