Skip to content

michaelnetbiz/parse-smcl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PARSE-SMCL | Parse SMCL Help Files into Markdown and HTML

This project contains a Python script that converts Stata help files in SMCL format (usually with the .sthlp or .hlp extensions) into proper HTML5 files.

It has multiple advantages to the current best alternative, log2html, such as:

  • Instead of copying the text in monospaced font and forgetting about most of the structure and meaning of the document, it preserves it.
  • Links, anchors, headings, etc. are preserved and tagged, so it's very easy to change their look with CSS files.
  • Tables are automatically generated (standard tables as well as syntax tables).
  • Navigation menus ("see also" and "jump to") are preserved.
  • When possible, fragments that contain enumerations are translated into actual or ordered/unordered lists. Similarly, code samples are translated into pre tags.
  • Because it uses CSS, you can change the styles freely, and for instance add/remove heading numeration, add syntax coloring for code samples, etc.
  • It uses responsive CSS so it's easier to read on tablets, large screens, etc. Similarly, it's easier to print.

Sample Output

Some examples include:

(Note: I do not own the copyright of the original files, they are used merely as an example of the use case)

Usage

To use this script, just run smcl2html.py:

> smcl2html
usage: smcl2html.py [-h] [--output OUTPUT] [--adopath ADOPATH] [--standalone]
                    [--view] [--xml]
                    filename

The arguments and flags are:

  • filename: the name of the file with .sthlp or .hlp extension.
  • output: (optional) the name of the output file. If not given, same as filename but with a .html extension.
  • adopath: the path of the stata/ado/base folder. Needed to replace the INCLUDE xyz directives.
  • standalone instead of outputting a simple
    -contained file, it will wrap the output with full html tags, including CSS and font links. Always use this option unless you want to embed the results into another page.
  • view: opens the resulting file in the browser.
  • xml: outputs an intermediate file, only for debug purposes.
  • help: shows this information

A typical command line would be:

smcl2html.py somehelpfile.sthlp --adopath=C:\Stata13\ado\base --view --standalone

Installation

  1. Download the latest Python 3.x: https://www.python.org/downloads/
  2. Install the lxml library: http://lxml.de/installation.html (or http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml for Windows; read this if you get stuck).

Missing Features

Since this is work-in-progress, there are still a few limitations:

  • The existing CSS is a proof-of-concept, and can be improved a lot more
  • Some SMCL directives are not supported. For instance, {c} and {space}. However, these are relatively minor and easy to implement.
  • Some advanced directives such as {findalias} are still not supported, but implementing them is quite doable

About

Parse SMCL Help Files into Markdown and HTML

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 78.8%
  • CSS 21.2%