Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
jolheiser | 3d7e79031f | |
jolheiser | 476639ee9b | |
jolheiser | a47ce7b08d |
21
README.md
21
README.md
|
@ -4,14 +4,25 @@ 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 ./...`.
|
||||
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 (
|
||||
|
@ -36,6 +47,7 @@ func Example() {
|
|||
//func main() {
|
||||
// fmt.Println("Hello, world!")
|
||||
//}
|
||||
//
|
||||
// ```
|
||||
//<!-- /emdbed -->
|
||||
}
|
||||
|
@ -45,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
|
||||
|
||||
|
@ -85,6 +97,7 @@ func Example() {
|
|||
//func main() {
|
||||
// fmt.Println("Hello, world!")
|
||||
//}
|
||||
//
|
||||
// ```
|
||||
//<!-- /emdbed -->
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Package emdbed is for embedding "things" in your markdown
|
||||
package emdbed
|
||||
|
||||
import (
|
||||
|
|
10
io.go
10
io.go
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue