Skip to main content

Simple markdown language and processor for write and render document similar to man pages, from command line or from Python

Project description

HMD

Simple WYSIWYG markdown language for write and render man pages, from command line or from Python.

WHY

The goal of the HMD language is to provide a simple language that permit to render an .hmd man page directly from a Python application.

This allow you to write your own man page and render it in a cross platform manner (since does not depends on the external man command).

INSTALLATION

pip install hmd

or

git clone https://github.com/Docheinstein/hmd

USAGE

Run with

hmd

or

python -m hmd
usage: __main__.py [-h] [-t] [-n] [-c COLUMNS] [input]

Render documents written in hmd (Help MarkDown) with the default pager. Reads from 'input' or from stdin if it is not given.

positional arguments:
  input                 Help MarkDown file to process and render

optional arguments:
  -h, --help            show this help message and exit
  -t, --text            Output text, without ANSI style
  -n, --no-pager        Just print, without using the pager
  -c COLUMNS, --columns COLUMNS
                        Override columns number (by default it depends on the terminal size)

EXAMPLES

Usage from command line

Renders ls.hmd with the default pager

hmd ls.hmd

Prints ls.hmd, without the pager

hmd -n ls.hmd

Prints ls.hmd, without the pager and without style using 60 columns

hmd -n -t -c 60 ls.hmd

Usage from Python

See _main__.py or demos.

For example

demo1.py

from hmd import HMD

HMD_EXAMPLE = \
"""\
. This is a comment, keep calm
**NAME**
    ls - list local directory content
    
**SYNOPSIS**
    **ls** [*OPTION*]... [*DIR*]

**DESCRIPTION**
    List content of the local *DIR* or the current local directory if \
    no *DIR* is specified.

**OPTIONS**
    **-a**, **--all**
        Show hidden files too

    **-l**
        Show more details"""


if __name__ == "__main__":
    # Renders with less the processed .hmd
    HMD().render(HMD_EXAMPLE)

HMD LANGUAGE

The HMD language is really simple and is thought for contain the minimal stuff for render a well formatted man page (ANSI formatting, automatic break respecting indent, align overriding, ...).

In the spirit of a WYSIWYG language, you will get almost what your write, and differently from canonical markdown, a new line in the source will be translated to a new line in the output (no ugly double space at end of line!)

See the examples folder for examples of .hmd files.

Here an example of a .hmd file from the examples folder

**COMMAND**
    ls - list local directory content

**SYNOPSIS**
    **ls** [*OPTION*]... [*DIR*]

**DESCRIPTION**
    List content of the local *DIR* or the current local directory if \
    no *DIR* is specified.

**OPTIONS**
    **-a**, **--all**
        Show hidden files too

    **-g**, **--group**
        Group by file type

    **-l**
        Show more details

    **-r**, **--reverse**
        Reverse sort order

    **-S**
        Show files size

    **-s**, **--sort-size**
        Sort by size

Indent

The indentation of each paragraph is equal to the number of left spaces in the source file.
If a line is longer the the number of available columns, the line will be broken and the remaining part will be indented automatically by the same amount.

Format

Bold

Same as markdown: **NAME** => NAME

Italic (underline)

Same as markdown: *DIR* => DIR

Escaping

Backslash (\) can be use for escape the next character.
You can use it for render characters that would be interpreted otherwise.
For example:

  • \* => *
  • \\ => \

Directives

Each line starting with a . is a directive.

Comment

An unknown directive is an inline comment, so you can use: . My long comment...

Alignment

The are cases in which you want the text to break to an alignment different from the indentation of the paragraph (e.g. lists). The alignment directive graphically helps you to do so.

To override the alignment for a part of the document, wrap it between .A and ./A.

For example:

.A     .
    1. I want this text to wrap below the 'I', not below the 1, if the length
    of the line is greater than the number of lines
./A

As you see, the trailing . in the .A directive specify graphically where to wrap.

Misc

Long lines

If you have long lines in your source file, you could add a trailing \ at the end of the line for join it with the consecutive line (in the output). Use the same indent of the first line even for consecutive lines.

For example:

**DESCRIPTION**
    This is my really really long hmd line that would exceed my strict rule of \
    maximum 80 columns, but fortunalety hmd supports the trailing backslash, \
    this make me really happy.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hmd-0.7.tar.gz (9.0 kB view details)

Uploaded Source

File details

Details for the file hmd-0.7.tar.gz.

File metadata

  • Download URL: hmd-0.7.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.5

File hashes

Hashes for hmd-0.7.tar.gz
Algorithm Hash digest
SHA256 fa746f88755178581a1fa59c9c4a28a73444c2122cb4f823b2550d291544e4c4
MD5 72a45c4e8663eabe077fddce0d07ef8b
BLAKE2b-256 e2bdf6403e168246eacb2aae0dfd13f4d584a24104ec4c3852467b2ace36d63a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page