emdbed

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 26, 2021 License: MIT Imports: 7 Imported by: 0

README

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 --> 

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, 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 is for embedding "things" in your markdown
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

Package 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

Documentation

Overview

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 -->

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Convert

func Convert(dir string, file io.Reader) (string, error)

Convert converts an io.Reader with respect to a base directory

func ConvertFile

func ConvertFile(path string) (string, error)

ConvertFile is a helper for converting a file on disk

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL