Sidebar LogoHomeInstallationUsageIndexIndexGitHub </> Back Next Usage

Usage


About this section

This section describes running the program and configuring writing projects. Content writing, formatting, and structuring are described in the other sections.


Cross-platform

The Java and the Python executables are platform-independent, so they should work in all environments where the corresponding runtimes are installed. The program was tested on:

The examples in this documentation are mostly given for Windows, but they may be easily adapted for Unix-like platforms. Some Unix-specific notes are provided when required.


Command line syntax

A simple usage example for the Python version is:

>python %MD2HTML_HOME%/python/md2html.py -i test.txt

and for the Java version is:

>java -jar %MD2HTML_HOME%/java/target/md2html-bin.jar -i test.txt

Both commands will convert file test.txt into file test.html using default parameters.

Note

The above commands illustrate the main idea of the program usage, but more convenient ways are described below in this section.

The program has many more command line options that are listed and described on the reference page.

There are two ways to use the program:


Using command line arguments

This mode accepts all required parameters in the command line and allows processing one document per run (unless the GLOB argument is used). It's selected when the --argument-file argument is not specified.


Using argument file

The --argument-file argument defines the argument file that will be used for processing. Here's the example that executes the argument file with name md2html_args.json:

>python %MD2HTML_HOME%/python/md2html.py --argument-file md2html_args.json

The argument file allows defining:

Here is a very simple example of an argument file:

{
    "documents": [
        { "input": "index.txt", "title": "Home" },
        { "input": "about.txt", "output": "about.html", "title": "About" }
    ]
}

It's similar to using command line arguments, except it defines several documents to process.

A more complex example and the argument file structure are described in the reference page.

Note

The command line and the argument file may specify different values for the parameters that mean the same (sometimes they have different names). In this case the command line arguments will override the corresponding parameters in the argument file.


Command scripts

The program versions (Python and Java) are supposed to work independently and require only their corresponding runtime. For example, the Java version should work even if there's no Python in the environment where it runs. For different auxiliary purposes, command scripts for Windows and Unix-like platforms are used. Here are the scripts that run the program:

For Windows For Unix-like Description
generate_doc_py.bat generate_doc_py Uses the Python version
generate_doc_java.bat generate_doc_java Uses the Java version

The Windows versions may be run by double-clicking in Windows Explorer. The Linux Bash script versions may need special environment adjustments (depending on the Linux distribution) to behave the same way. In Ubuntu these scripts were tested only in the command line terminal.

These scripts execute the argument file md2html_args.json in the current working directory. When double-clicked in Windows, they will open a command window and close it when they successfully complete. If there are errors, the command window will stay open with the information and error messages displayed.

These scripts are very small and intended to be copied to a project's directory where they will process the project's argument file (see the recommended project structure).


Windows Explorer context menu integration

The program may be integrated into the Windows Explorer context menu:

WINDOWS_EXPOLORER_CONTEXT_MENU

This may be a quick and convenient way to convert single documents.

The "no prompt" version generates HTML from the selected file with default options. It leaves the command window open only in case of errors. The other version opens a command line window and allows redefining some options. Just pressing Enter will start generation with the default options.

To add these context menu items, open the Windows Registry editor (press Win+R, type regedit and press Enter) and add the following keys and values:

[HKEY_CURRENT_USER\Software\Classes\*\shell\md2html]
@="Markdown to HTML..."
"icon"="\"X:\\path\\to\\md2html\\bin\\context_menu\\icon.ico"

[HKEY_CURRENT_USER\Software\Classes\*\shell\md2html\command]
@="\"\"X:\\path\\to\\md2html\\bin\\context_menu\\md2html_prompt.bat\" -i \"%1\""

[HKEY_CURRENT_USER\Software\Classes\*\shell\md2html_fast]
@="Markdown to HTML (no prompt)"
"icon"="\"X:\\path\\to\\md2html\\bin\\context_menu\\icon.ico"

[HKEY_CURRENT_USER\Software\Classes\*\shell\md2html_fast\command]
@="\"X:\\path\\to\\md2html\\bin\\context_menu\\md2html_prompt_fast.bat\" -i \"%1\""

Here @ stands for (Default) value name. py or java may be added before -i argument. The quotes must be set like this:

There is a Windows command line script that automates this operation. Open a Windows console and execute:

>%MD2HTML_HOME%\bin\context_menu\generate_reg_file.bat
The output file is: C:\Users\user1\md2html_context_menu_integration.reg

Find the generated file in the user's profile directory, check and execute it (by double-click). Read the pop-up message and confirm the operation.

Note

There's no such integration for Linux and macOS.


Typical project structure

The program doesn't impose restrictions on the writing project structure. The following structure is just a suggested approach that is used in this documentation.

Note that there's the quick start script that automatically creates a small project with a structure like this. The following description may be used for manual project setup.

$ tree -L 2 --charset=ascii --dirsfirst
.
|-- doc
|   |-- content
|   |   |-- doc1.html
|   |   `-- doc2.html
|   |-- layout
|   |   `-- <...>
|   |-- pict
|   |   |-- image1.png
|   |   `-- image2.png
|   |-- themes
|   |   `-- light
|   |       `-- <...>
|   |-- favicon.png
|   `-- custom.css
|-- doc_src
|   |-- templates
|   |   `-- multipage.html
|   |-- doc1.txt
|   `-- doc2.txt
|-- doc0.html
|-- doc0.txt
|-- generate_doc_py.bat
`-- md2html_args.json

Layout manipulation

By layout we mean the whole set of artifacts used for generating the writing project results and not belonging to the user-created content. Applying to the recommended project structure the layout artifacts are:

The layout is a relatively independent part of the M2H project. Currently, newer versions of the program work well with older versions of the layout.

The quick start script copies the layout artifacts from the M2H home directory to the new writing project. This approach keeps the users' projects independent of the changes made in the M2H project. When a newer version of M2H provides desired layout changes or fixes, the writing project's layout may be updated manually. Here are the suggested steps for that:

 


Back Next