All Projects → campoy → Embedmd

campoy / Embedmd

Licence: apache-2.0
embedmd: embed code into markdown and keep everything in sync

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Embedmd

Backslide
💦 CLI tool for making HTML presentations with Remark.js using Markdown
Stars: ✭ 679 (-4.9%)
Mutual labels:  utility, markdown
Electron Markdownify
📕 A minimal Markdown editor desktop app
Stars: ✭ 700 (-1.96%)
Mutual labels:  markdown
Thor
Switch the right application ASAP.
Stars: ✭ 660 (-7.56%)
Mutual labels:  utility
Htmly
Simple and fast databaseless PHP blogging platform, and Flat-File CMS
Stars: ✭ 689 (-3.5%)
Mutual labels:  markdown
Wysiwyg.css
A tiny CSS for generated HTML or Markdown content
Stars: ✭ 665 (-6.86%)
Mutual labels:  markdown
Rich
Rich is a Python library for rich text and beautiful formatting in the terminal.
Stars: ✭ 31,664 (+4334.73%)
Mutual labels:  markdown
Tinacms
Open source editor that brings visual editing into React websites. A developer-centric CMS to build contextual and intuitive editing experience without sacrificing code quality.
Stars: ✭ 6,804 (+852.94%)
Mutual labels:  markdown
Notepad
[iOS] A fully themeable markdown editor with live syntax highlighting.
Stars: ✭ 705 (-1.26%)
Mutual labels:  markdown
Goto
Alias and navigate to directories with tab completion in Linux
Stars: ✭ 698 (-2.24%)
Mutual labels:  utility
Ngx Markdown
Angular markdown component/directive/pipe/service to parse static, dynamic or remote content to HTML with syntax highlight
Stars: ✭ 687 (-3.78%)
Mutual labels:  markdown
Ok Mdx
Browser-based MDX editor
Stars: ✭ 681 (-4.62%)
Mutual labels:  markdown
Bytemd
A hackable Markdown editor component built with Svelte
Stars: ✭ 656 (-8.12%)
Mutual labels:  markdown
Marked
A markdown parser and compiler. Built for speed.
Stars: ✭ 26,556 (+3619.33%)
Mutual labels:  markdown
Lint Md
📚 检查中文 markdown 编写格式规范的命令行工具,基于 AST,方便集成 ci,写博客 / 文档必备。支持 API 调用!
Stars: ✭ 662 (-7.28%)
Mutual labels:  markdown
Gatsby Gitbook Starter
Generate GitBook style modern docs/tutorial websites using Gatsby + MDX
Stars: ✭ 700 (-1.96%)
Mutual labels:  markdown
Basscss
Low-level CSS Toolkit – the original Functional/Utility/Atomic CSS library
Stars: ✭ 5,669 (+693.98%)
Mutual labels:  utility
Shiba
Rich markdown live preview app with linter
Stars: ✭ 691 (-3.22%)
Mutual labels:  markdown
Mdx Util
Utilities for working with MDX
Stars: ✭ 709 (-0.7%)
Mutual labels:  markdown
Vscode Markdown Preview Enhanced
One of the "BEST" markdown preview extensions for Visual Studio Code
Stars: ✭ 701 (-1.82%)
Mutual labels:  markdown
Recipes
Django application for managing recipes
Stars: ✭ 695 (-2.66%)
Mutual labels:  markdown

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].