1
2
Fork
You've already forked mandown
0
  • C 96.9%
  • Makefile 3.1%
2026年05月08日 18:24:15 +02:00
blender Restore some Macro for MacOS 2025年04月03日 01:26:14 -04:00
cli added support for the 'v' command in less mode. This forks a $EDITOR on the current file. 2026年05月06日 17:19:06 +02:00
parser fix bug where whitespace after a codespan would be ignored 2023年01月27日 16:44:08 -08:00
src added support for the 'v' command in less mode. This forks a $EDITOR on the current file. 2026年05月06日 17:19:06 +02:00
.gitattributes Initial commit 2020年04月08日 19:32:28 -04:00
.gitignore Fix Return Code on success 2025年02月21日 21:43:33 -05:00
blender_block_names.txt Moving project to Github 2020年04月08日 19:38:49 -04:00
LICENSE Update LICENSE 2021年09月29日 05:50:51 -05:00
Makefile use $DESTDIR env if provided 2025年04月03日 02:02:40 -04:00
README.md updated and expanded documentation in the README.md file 2026年05月08日 18:24:15 +02:00
sample.md Checking ncursesw on RPM & minor tweaks 2025年03月27日 20:15:00 -04:00
screenshot.png Add preprocessor for ncurses.h header issue 2020年05月10日 21:37:33 -04:00

mandown - mdn

Note: this repo was forked from: https://github.com/Titor8115/mandown

A man-page inspired Markdown pager written in C.

What is it

mandown (executable name: mdn) is a small (~250kB) self-contained markdown renderer and pager. It is designed to be an alternative to pagers like more(1) and less(1), although its functionality apart from the markdown support is a lot more limited.

What alternatives exist?

Standard less(1) can be configured with a preprocessor to handle rendering of markdown files into ANSI escape sequences which less can display. One suitable preprocessor is bat(1), which supports a more complete subset of markdown. Another option is pygmentize. Either of these may already be available via your distro's repos.

To do so create an executable ~/.config/lessfile similar to this example:

#!/usr/bin/env sh
#
case "1ドル" in
*.md|*.MD|*.markdown)
 bat --color always "1ドル" ;;
esac

Then set the environment variable LESSOPEN=|${HOME}/.config/lessfile %s and less will be able to display markdown files. Depending on your terminal settings it may be necessary to use the -R flag to colorize the output.

Configuration

mdn supports minimal user customization via the config file located in ~/.config/mdn/mdnrc. The file gets created via make install and looks like this:

# If you want Terminal Emulator handle mouse event
# turn off "use_mouse"
use_mouse = true;
# Indent controls where manual's content start for each line
indent = 7;
# Supported Keybinding: "mdn", "vim", "less"
control_scheme = "less";

Hint: if you want to be able to use the mouse inside the editor spawned via the v command you should set use_mouse = false in this file.

Sample Display

screenshot

Library dependency

Mandown requires libncurses(w), libxml2 and libconfig as compile-time dependencies.

Make sure you have them installed before compiling.

Debian

$ apt-get install libncursesw5-dev
$ apt-get install libxml2-dev
$ apt-get install libconfig-dev

Installation

Current version is still being developed for some HTML tags. However, it should work on most Markdown documents.

Homebrew

$ brew install mandown

The installed binary mdn would be at /usr/local/bin/

Local

$ git clone https://github.com/Titor8115/mandown.git
$ cd mandown
$ make install

To remove the binary, you can run the commands below, or remove manually.

$ cd mandown
$ make uninstall

If you just want to compile and test it.

$ cd mandown
$ make

Feel free to create an issue.

Usage

Check out the new sample

$ mdn sample.md

Mouse scrolling is supported! (if your terminal emulator allows)

Move Up: Up, k

Move Down: Down, j

Page Up: Space, PgUp, b

Page Down: Bksp, PgDn, f

Show href in hyperlink: Tab + Enter, or double click mouse 1

Edit current file in $EDITOR: v (currently only works in 'less'-mode)

Exit: q

To read detailed usage, run mdn -h

Embedding

Mandown can also be embedded in your own applications. To render a Markdown document in a C string:

#include "mandown.h"
char *str ="# Heading\n\nThis is some **BOLD** *italic* ***EMPHASIZED*** text.";
render_str(str, "md", "Test Title", NULL);

To render a Markdown document file:

#include "mandown.h"
FILE *fp = fopen("README.md", "r");
render_file(fp, "md", "Test file", NULL);

Static and shared libraries are available. Make sure you have installed the dependencies listed in Library dependency below, then assuming you installed Mandown under /usr/local:

# static build
gcc -o myprog -I/usr/local/include myprog.c /usr/local/lib/mandown.a -lncurses -lxml2 -lconfig
# shared build
gcc -o myprog -I/usr/local/include myprog.c -L/usr/local/lib -lmandown -lncurses -lxml2 -lconfig

tests

Known Limitations

  • the less control mode implementation is rudimentary
  • mdn is just not a very good pager, compared to less or bat
  • markdown support is limited and unlikely to be expanded
  • after editing a file mdn quits. It should instead re-read the changed file and return to paged output, like less does.