• Stars
    star
    767
  • Rank 59,242 (Top 2 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

embedmd: embed code into markdown and keep everything in sync

Build Status Go Report Card

embedmd

Are you tired of copy pasting your code into your README.md file, just to forget about it later on and have unsynced copies? Or even worse, code that does not even compile?

Then embedmd is for you!

embedmd embeds files or fractions of files into Markdown files. It does so by searching embedmd commands, which are a subset of the Markdown syntax for comments. This means they are invisible when Markdown is rendered, so they can be kept in the file as pointers to the origin of the embedded text.

The command receives a list of Markdown files. If no list is given, the command reads from the standard input.

The format of an embedmd command is:

[embedmd]:# (pathOrURL language /start regexp/ /end regexp/)

The embedded code will be extracted from the file at pathOrURL, which can either be a relative path to a file in the local file system (using always forward slashes as directory separator) or a URL starting with http:// or https://. If the pathOrURL is a URL the tool will fetch the content in that URL. The embedded content starts at the first line that matches /start regexp/ and finishes at the first line matching /end regexp/.

Omitting the the second regular expression will embed only the piece of text that matches /regexp/:

[embedmd]:# (pathOrURL language /regexp/)

To embed the whole line matching a regular expression you can use:

[embedmd]:# (pathOrURL language /.*regexp.*/)

To embed from a point to the end you should use:

[embedmd]:# (pathOrURL language /start regexp/ $)

To embed a whole file, omit both regular expressions:

[embedmd]:# (pathOrURL language)

You can omit the language in any of the previous commands, and the extension of the file will be used for the snippet syntax highlighting.

This works when the file extensions matches the name of the language (like Go files, since .go matches go). However, this will fail with other files like .md whose language name is markdown.

[embedmd]:# (file.ext)

Installation

You can install Go by following these instructions.

embedmd is written in Go, so if you have Go installed you can install it with go get:

go get github.com/campoy/embedmd

This will download the code, compile it, and leave an embedmd binary in $GOPATH/bin.

Eventually, and if there's enough interest, I will provide binaries for every OS and architecture out there ... eventually.

Usage:

Given the two files in sample:

hello.go:

// Copyright 2016 Google Inc. All rights reserved.
// Use of this source code is governed by the Apache 2.0
// license that can be found in the LICENSE file.

package main

import (
	"fmt"
	"time"
)

func main() {
	fmt.Println("Hello, there, it is", time.Now())
}

docs.md:

# A hello world in Go

Go is very simple, here you can see a whole "hello, world" program.

[embedmd]:# (hello.go)

We can try to embed a file from a directory.

[embedmd]:# (test/hello.go /func main/ $)

You always start with a `package` statement like:

[embedmd]:# (hello.go /package.*/)

Followed by an `import` statement:

[embedmd]:# (hello.go /import/ /\)/)

You can also see how to get the current time:

[embedmd]:# (hello.go /time\.[^)]*\)/)

Flags

  • -w: Executing embedmd -w docs.md will modify docs.md and add the corresponding code snippets, as shown in sample/result.md.

  • -d: Executing embedmd -d docs.md will display the difference between the contents of docs.md and the output of embedmd docs.md.

Disclaimer

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

More Repositories

1

go-tooling-workshop

A workshop covering all the tools gophers use in their day to day life
Go
2,792
star
2

justforfunc

The repository for the YouTube series JustForFunc
Go
1,474
star
3

todo

A task manager written in Go using TDD techniques, each commit should represent a step in the application development.
Go
569
star
4

go-web-workshop

Build Web Applications with Go on App Engine
Go
534
star
5

jsonenums

This tool is similar to golang.org/x/tools/cmd/stringer but generates MarshalJSON and UnmarshalJSON methods.
Go
490
star
6

golang-plugins

A simple demo of hot code swapping with Go 1.8 and its plugins feature.
Go
249
star
7

tools

List of tools
Go
109
star
8

flappy-gopher

The code for the Flappy Gopher episodes of #justforfunc
Go
105
star
9

golang-groups

List of Go user groups, meetups, and similar.
JavaScript
102
star
10

unique

Package unique provides primitives for sorting slices removing repeated elements.
Go
94
star
11

chat

A good demonstration of Go composition of types and processes.
Go
85
star
12

apiai

A simple framework for api.ai fulfillment backends
Go
72
star
13

whispering-gophers

Whispering Gophers is a Go workshop
Go
71
star
14

podcast-to-youtube

Post any podcast episode from a RSS feed to YouTube
Go
55
star
15

mandelbrot

Go
42
star
16

apicheck

A tool to compare different versions of an API and find incompatibilities.
Go
40
star
17

links

Working on stuff
Go
38
star
18

csvql

cvsql: a SQL server for CSV files
Go
35
star
19

goml

Machine Learning Adventures in Go
Go
34
star
20

mat

A simple to use, not ready for production, matrix package
Go
30
star
21

podcasts

A list of podcasts that I listen to or I've been told I should listen to
30
star
22

svg-badge

Code for https://svg-badge.appspot.com
Go
30
star
23

advent-of-code-2018

My solutions for advent of code 2018
Go
27
star
24

audio

Audio experiments in Go
Go
26
star
25

groto

A protocol buffer file definition parser written in Go
Go
20
star
26

httplog

Easy and flexible logging of HTTP requests
Go
18
star
27

pokegraph

Serving poke-api on Dgraph
Go
17
star
28

gaesave

Helper tool to save objects to the datastore offering pre and post save hooks. Inspired by http://www.mrvdot.com/all/creating-a-universal-save-method-in-go-on-gae.
Go
14
star
29

leap

Go API for Leap Motion devices
Go
13
star
30

code-as-graphs

Source code is a graph, so why wouldn't we store it in Dgraph?
Go
10
star
31

sortslice

Sorting slices with less lines
Go
10
star
32

chromegodoc

A Chrome extension opening the current tab in godoc.
JavaScript
9
star
33

goodgopher

A GitHub bot for Good Gophers
9
star
34

blog

A blog system written in Go and running on App Engine
Go
7
star
35

abc

ABC music notation parser
Go
7
star
36

badger-migrations

A repository to experiment with badger and all its versions
Go
6
star
37

mandarin

my notes while learning Mandarin
6
star
38

learning-from-context

Implementing the context package step by step for a talk
Go
6
star
39

campoy.cat

Generic personal webpage with a list of links to other resources.
CSS
6
star
40

golang-driver

a bblfsh go driver
Go
5
star
41

singing-gophers

Singing gophers
Go
5
star
42

docker-go1.3

Docker images providing different versions of Go
Shell
5
star
43

github-reminder

Source for GitHub reminder app
4
star
44

goconf

Conference manager on the cloud using Go and Google Cloud
Go
4
star
45

advent-of-code-2019

Advent of Code 2019
Go
4
star
46

ObjectOrientedAndConcurrent

Source for the talk "Go: object oriented and concurrent"
Go
4
star
47

riff

Encoder decoder for RIFF (Resource Interchange File Format) files based on the wikipedia format explanation (http://en.wikipedia.org/wiki/Resource_Interchange_File_Format)
Go
4
star
48

wav

Support for WAV format audio files on Go
Go
3
star
49

ci-cd-workshop

CSS
2
star
50

jsparser

A javascript parser written in Go
2
star
51

wordiction

A simple example showing how to write a word prediction algorithm, similar to t9, in Go.
2
star
52

cooltool

Dummy repository to demonstrate pull requests with Go
Go
2
star
53

go4java

Go for Javaneros, talk and code
Go
1
star
54

gameoflife

Conway's Game of Life
1
star
55

lookout-test

Testing stuff
JavaScript
1
star
56

gio

Interpreter of io language in Go
1
star
57

gosamples

Simple samples of Go code
Go
1
star