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 -->
```go
// Package emdbed is for embedding "things" in your markdown
package emdbed
import (
@ -56,15 +57,15 @@ func Example() {
Just the package:
<!-- emdbed: emdbed_example_test.go L1 L1 -->
<!-- emdbed: emdbed_example_test.go L2 L2 -->
```go
package 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
package emdbed

View File

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

10
io.go
View File

@ -25,7 +25,15 @@ func (e emdbed) line(line int, end bool) (int, error) {
if len(indexes) < 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) {