Fix line embedding

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main v0.0.2
jolheiser 2021-12-25 22:53:20 -06:00
parent 476639ee9b
commit 3d7e79031f
Signed by: jolheiser
GPG Key ID: B853ADA5DA7BBF7A
3 changed files with 14 additions and 4 deletions

View File

@ -22,6 +22,7 @@ An entire file:
<!-- emdbed: emdbed_example_test.go --> <!-- emdbed: emdbed_example_test.go -->
```go ```go
// Package emdbed is for embedding "things" in your markdown
package emdbed package emdbed
import ( import (
@ -56,15 +57,15 @@ func Example() {
Just the package: Just the package:
<!-- emdbed: emdbed_example_test.go L1 L1 --> <!-- emdbed: emdbed_example_test.go L2 L2 -->
```go ```go
package emdbed package emdbed
``` ```
<!-- /emdbed --> <!-- /emdbed -->
First line until the end of imports: Package line until the end of imports:
<!-- emdbed: emdbed_example_test.go L1 /\)/ --> <!-- emdbed: emdbed_example_test.go L2 /\)/ -->
```go ```go
package emdbed package emdbed

View File

@ -1,3 +1,4 @@
// Package emdbed is for embedding "things" in your markdown
package emdbed package emdbed
import ( import (

10
io.go
View File

@ -25,7 +25,15 @@ func (e emdbed) line(line int, end bool) (int, error) {
if len(indexes) < line { if len(indexes) < line {
return 0, fmt.Errorf("file %q has no line %d", e.name, line) return 0, fmt.Errorf("file %q has no line %d", e.name, line)
} }
return indexes[line-1][0], nil dec := 1
if !end {
dec++
}
var inc int
if !end {
inc++
}
return indexes[line-dec][0] + inc, nil
} }
func (e emdbed) regex(pattern string, end bool) (int, error) { func (e emdbed) regex(pattern string, end bool) (int, error) {