Go to file
jolheiser a47ce7b08d
Add README examples
Signed-off-by: jolheiser <john.olheiser@gmail.com>
2021-12-23 22:13:10 -06:00
cmd/emdbed Initial Commit 2021-12-22 23:48:19 -06:00
testdata Initial Commit 2021-12-22 23:48:19 -06:00
.gitignore Initial Commit 2021-12-22 23:48:19 -06:00
.woodpecker.yml Final polish 2021-12-23 22:03:34 -06:00
LICENSE Initial Commit 2021-12-22 23:48:19 -06:00
README.md Add README examples 2021-12-23 22:13:10 -06:00
emdbed.go Final polish 2021-12-23 22:03:34 -06:00
emdbed_example_test.go Final polish 2021-12-23 22:03:34 -06:00
emdbed_test.go Initial Commit 2021-12-22 23:48:19 -06:00
go.mod Initial Commit 2021-12-22 23:48:19 -06:00
go.sum Initial Commit 2021-12-22 23:48:19 -06:00
io.go Initial Commit 2021-12-22 23:48:19 -06:00
readme.go Initial Commit 2021-12-22 23:48:19 -06:00

README.md

emdbed

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

<!-- emdbed: <file> [~<language>] [L<start-line>|/<start-regex>/] [L<end-line>|/<end-regex>/]
<!-- /emdbed -->

The regex is Go flavored, which you can test on regex101.

Examples

The following are generated using readme.go and go generate ./....
Check the raw markdown for the header selectors used.

An entire file:

package emdbed

import (
	"fmt"
)

func Example() {
	fi, err := testdata.Open("testdata/main.md")
	defer fi.Close()
	out, err := Convert("testdata", fi)
	if err != nil {
		panic(err)
	}
	fmt.Println(out)
	// Output:
	//<!-- emdbed: main.go -->
	//```go
	//package main
	//
	//import "fmt"
	//
	//func main() {
	//	fmt.Println("Hello, world!")
	//}
	// ```
	//<!-- /emdbed -->
}

Just the package:

package emdbed

First line until the end of imports:

package emdbed

import (
	"fmt"
)

Only the example func

func Example() {
	fi, err := testdata.Open("testdata/main.md")
	defer fi.Close()
	out, err := Convert("testdata", fi)
	if err != nil {
		panic(err)
	}
	fmt.Println(out)
	// Output:
	//<!-- emdbed: main.go -->
	//```go
	//package main
	//
	//import "fmt"
	//
	//func main() {
	//	fmt.Println("Hello, world!")
	//}
	// ```
	//<!-- /emdbed -->
}

A file in another directory (choosing/overriding the language)

package main

import "fmt"

func main() {
	fmt.Println("This file has no extension")
}

License

MIT