Compare commits
No commits in common. "main" and "v0.0.1" have entirely different histories.
21
README.md
21
README.md
|
@ -4,25 +4,14 @@ Embed "things" in your markdown files.
|
||||||
|
|
||||||
Given the same input, `emdbed` should give idempotent results.
|
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
|
## 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:
|
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 (
|
||||||
|
@ -47,7 +36,6 @@ func Example() {
|
||||||
//func main() {
|
//func main() {
|
||||||
// fmt.Println("Hello, world!")
|
// fmt.Println("Hello, world!")
|
||||||
//}
|
//}
|
||||||
//
|
|
||||||
// ```
|
// ```
|
||||||
//<!-- /emdbed -->
|
//<!-- /emdbed -->
|
||||||
}
|
}
|
||||||
|
@ -57,15 +45,15 @@ func Example() {
|
||||||
|
|
||||||
Just the package:
|
Just the package:
|
||||||
|
|
||||||
<!-- emdbed: emdbed_example_test.go L2 L2 -->
|
<!-- emdbed: emdbed_example_test.go L1 L1 -->
|
||||||
```go
|
```go
|
||||||
package emdbed
|
package emdbed
|
||||||
```
|
```
|
||||||
<!-- /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
|
```go
|
||||||
package emdbed
|
package emdbed
|
||||||
|
|
||||||
|
@ -97,7 +85,6 @@ func Example() {
|
||||||
//func main() {
|
//func main() {
|
||||||
// fmt.Println("Hello, world!")
|
// fmt.Println("Hello, world!")
|
||||||
//}
|
//}
|
||||||
//
|
|
||||||
// ```
|
// ```
|
||||||
//<!-- /emdbed -->
|
//<!-- /emdbed -->
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// Package emdbed is for embedding "things" in your markdown
|
|
||||||
package emdbed
|
package emdbed
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
10
io.go
10
io.go
|
@ -25,15 +25,7 @@ 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)
|
||||||
}
|
}
|
||||||
dec := 1
|
return indexes[line-1][0], nil
|
||||||
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) {
|
||||||
|
|
Loading…
Reference in New Issue