Skip to content

hymkor/example-into-readme

Repository files navigation

example-into-readme

Go Test License Go Reference

Overview

example-into-readme automatically inserts example files or command outputs into your README.md. It helps you keep your documentation up-to-date — without manually copying and pasting code or results.

This tool is meant to be used locally as a CLI helper, not as a GitHub Action.

Before running

```go.mod
```

After running

```go.mod
module github.com/hymkor/example-into-readme

go 1.20

require golang.org/x/text v0.8.0
```

The program finds code blocks whose info-string contains a filename, then replaces the block’s content with the actual file content.

$ example-into-readme
Convert from README.md to README.tmp
Include go.mod
Rename README.md to README.md~
Rename README.tmp to README.md

When the filename ends with *.go, it skips lines before package to ignore //go:build directives.

Usage examples

Include a file

```go.mod
```

→ replaced with the actual contents of go.mod.

Include command output

```go run example.go |
```

→ replaced with the result of running the command.

Include another markdown file

<!-- example.md -->
<!-- -->

→ replaced with the contents of example.md.

Specify the language for code blocks

Some file extensions are not automatically recognized by GitHub’s syntax highlighting. You can specify the language name explicitly before the filename:

```rust foo.rs
```

Quoting the output of commands

To embed command results, write the command followed by a |:

```COMMANDNAME ARGS ... |
```

Outline generator

You can insert a markdown outline between these markers:

<!-- outline -->
<!-- -->

Include other markdown files

<!-- filename.md -->
<!-- -->

Include command output

<!-- COMMANDNAME ARGS ... | -->
<!-- -->

Install

Download the binary from Releases and extract the executable.

Use go install

go install github.com/hymkor/example-into-readme@latest

Use the scoop-installer

scoop install https://raw.githubusercontent.com/hymkor/example-into-readme/master/example-into-readme.json

or

scoop bucket add hymkor https://github.com/hymkor/scoop-bucket
scoop install example-into-readme

About

Insert example-files into `README.md` at the code block in the current directory.

Resources

License

Stars

Watchers

Forks