Compare commits

..

No commits in common. "main" and "v0.0.1" have entirely different histories.
main ... v0.0.1

3 changed files with 5 additions and 27 deletions

View File

@ -4,25 +4,14 @@ Embed "things" in your markdown files.
Given the same input, `emdbed` should give idempotent results.
To create an `emdbed` section, use a header and footer as follows
```text
<!-- emdbed: <file> [~<language>] [L<start-line>|/<start-regex>/] [L<end-line>|/<end-regex>/]
<!-- /emdbed -->
```
**NOTE:** The above snippet has an extra space at the end in order to keep it from recognizing the footer when generating this README.
The regex is [Go flavored](https://golang.org/s/re2syntax), which you can test on [regex101](https://regex101.com/).
## Examples
The following are generated using [readme.go](readme.go) and `go generate ./...`.
Check the raw markdown for the header selectors used.
An entire file:
<!-- emdbed: emdbed_example_test.go -->
```go
// Package emdbed is for embedding "things" in your markdown
package emdbed
import (
@ -47,7 +36,6 @@ func Example() {
//func main() {
// fmt.Println("Hello, world!")
//}
//
// ```
//<!-- /emdbed -->
}
@ -57,15 +45,15 @@ func Example() {
Just the package:
<!-- emdbed: emdbed_example_test.go L2 L2 -->
<!-- emdbed: emdbed_example_test.go L1 L1 -->
```go
package emdbed
```
<!-- /emdbed -->
Package line until the end of imports:
First line until the end of imports:
<!-- emdbed: emdbed_example_test.go L2 /\)/ -->
<!-- emdbed: emdbed_example_test.go L1 /\)/ -->
```go
package emdbed
@ -97,7 +85,6 @@ func Example() {
//func main() {
// fmt.Println("Hello, world!")
//}
//
// ```
//<!-- /emdbed -->
}

View File

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

10
io.go
View File

@ -25,15 +25,7 @@ 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)
}
dec := 1
if !end {
dec++
}
var inc int
if !end {
inc++
}
return indexes[line-dec][0] + inc, nil
return indexes[line-1][0], nil
}
func (e emdbed) regex(pattern string, end bool) (int, error) {