Giter Club home page Giter Club logo

mdfmt's Introduction

Introduction

GitHub release Github All Releases docker pulls license Go Reference Coverage Status gitmoji

๐Ÿ’ก A Markdown formatter that follow the CommonMark. Like gofmt, but for Markdown.

Recently, I have frequently used Markdown to write documents, and it is difficult to manage the format when there are too many contents. I often see lumps of markdown contents crowded together, it caused my eyebrows to be crowded together.

Fortunately, the powerful structured Markdown engine lute, its support for Chinese context is also very good, so I developed this Markdown formatting command line tool mdfmt with the lute engine, welcome everyone to try ๐Ÿ‘๐Ÿป

๐Ÿ“œ๏ธ Language

English | ็ฎ€ไฝ“ไธญๆ–‡

โœจ Features

  • Support multiple inputs: standard input, file, directory and wildcard. The specified directory will recursively format all markdown files under the directory
  • Support Rewriting: write the results to (source) files instead of standard output
  • Support display difference: display the difference before and after markdown formatting, Instead of rewriting files
  • Support listing formatted files
  • Cross platform: Linux, windows, Mac
  • One-click installation: support one-click installation mdfmt through Homebrew, go install, etc.

๐Ÿ› ๏ธ Installation

Binary (Cross-platform: windows, linux, mac ...)

To get the binary just download the latest release for your OS/Arch from the release page and put the binary somewhere convenient.

Homebrew

The elliotxx/tap has macOS and GNU/Linux pre-built binaries available:

brew install elliotxx/tap/mdfmt

Build from Source

Starting with Go 1.17, you can install mdfmt from source using go install:

go install github.com/elliotxx/mdfmt/cmd/mdfmt@latest

NOTE: This will install mdfmt based on the latest available code base. Even though the goal is that the latest commit on the main branch should always be a stable and usable version, this is not the recommended way to install and use mdfmt. The version output will show mdfmt version (default-version) for go install based builds.

Docker

Docker users can use the following commands to pull the latest image of the mdfmt:

docker pull elliotxx/mdfmt

Verification:

$ docker run --rm elliotxx/mdfmt:latest mdfmt -h
...
$ docker run --rm elliotxx/mdfmt:latest mdfmt -V
...
$ docker run -v $PWD:$PWD --rm elliotxx/mdfmt:latest mdfmt -d /Users/yym/workspace/mdfmt/pkg/md/testdata/hello-more.md
diff -u /Users/yym/workspace/mdfmt/pkg/md/testdata/hello-more.md.orig /Users/yym/workspace/mdfmt/pkg/md/testdata/hello-more.md
--- /Users/yym/workspace/mdfmt/pkg/md/testdata/hello-more.md.orig
+++ /Users/yym/workspace/mdfmt/pkg/md/testdata/hello-more.md
@@ -1,6 +1,7 @@
 # hello
+
 > hello

-|name|age|
-|--|--|
-|Mike|18|
+| name | age |
+| ---- | --- |
+| Mike | 18  |

โšก Usage

$ mdfmt -h
A Markdown formatter that follow the CommonMark. Like gofmt, but for Markdown.

Usage:
  mdfmt [flags] [path ...]

Examples:
  # Format specified Markdown file, and write to stdout
  mdfmt README.md
  
  # Format and rewrite for specified Markdown file
  mdfmt -w README.md
  
  # Display diffs instead of rewriting Markdown files
  mdfmt -d README.md
  
  # List files whose formatting differs from mdfmt's
  mdfmt -l .
  
  # Format, rewrite, and display diffs for specified Markdown file
  mdfmt -d -w README.md
  
  # Format and rewrite all Markdown file in current directory
  mdfmt -w *.md
  
  # Recursive format and rewrite all Markdown file in current directory
  mdfmt -w .
  
  # Format and rewrite the specified Markdown file and directory
  mdfmt -w README.md testdir/
  
  # Format stdin to stdout
  cat README.md | mdfmt
  
  # Show version info
  mdfmt -V

Flags:
  -d, --diff      display diffs instead of rewriting files
  -h, --help      help for mdfmt
  -l, --list      list files whose formatting differs from mdfmt's
  -V, --version   show version info
  -w, --write     write result to (source) file instead of stdout

๐Ÿ™ Thanks

mdfmt's People

Contributors

elliotxx avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.