MXVM 1.8.1
Virtual Machine, Compiler, and Pascal Frontend
Loading...
Searching...
No Matches
html.cpp File Reference

mxvm-html command-line tool — converts MXVM source to syntax-highlighted HTML More...

#include "mxvm/html_gen.hpp"
#include "argz.hpp"
#include <cctype>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
Include dependency graph for html.cpp:

Go to the source code of this file.

Functions

static std::string readFile (const std::string &path)
static bool endsWith (const std::string &s, const std::string &suffix)
static std::string dirOf (const std::string &path)
static bool fileExists (const std::string &path)
static void ensureCss (const std::string &outPath)
static void writeHtml (const std::string &src, const std::string &inPath, const std::string &outPath, const std::string &cssHref="")
static std::string extractDeclName (const std::string &src)
int main (int argc, char **argv)

Detailed Description

mxvm-html command-line tool — converts MXVM source to syntax-highlighted HTML

Author
Jared Bruni

Usage: mxvm-html -i input.mxvm [-o output.html] [-s style.css] mxvm-html -i input.pas [-o output.html] [-s style.css] mxvm-html -c file1.mxvm file2.pas ... [-s style.css] mxvm-html -h

For .pas input the output is Pascal-syntax-highlighted using PasHTMLGen. An external stylesheet is linked from the HTML so you can change the look without recompiling. By default mxvm-highlight.css is written to the same directory as the first output file (only when the file does not exist yet). Use -s to point to an existing stylesheet instead.

Output filenames are auto-derived from the program/unit/object declaration in the source unless -o is supplied.

Definition in file html.cpp.

Function Documentation

◆ dirOf()

std::string dirOf ( const std::string & path)
static

Return the directory portion of a path, including the trailing slash.

Definition at line 47 of file html.cpp.

References pos().

Referenced by ensureCss().

◆ endsWith()

bool endsWith ( const std::string & s,
const std::string & suffix )
static

Definition at line 41 of file html.cpp.

Referenced by writeHtml().

◆ ensureCss()

void ensureCss ( const std::string & outPath)
static

Write mxvm-highlight.css next to outPath if it does not already exist.

Definition at line 58 of file html.cpp.

References mxvm::PasHTMLGen::defaultCss(), dirOf(), and fileExists().

Referenced by writeHtml().

◆ extractDeclName()

std::string extractDeclName ( const std::string & src)
static

Scan source for the first "program|unit|object <Identifier>" and return the identifier. Skips //-line comments, MXVM #-comments, Pascal {}-comments, and Pascal (*)-comments.

Definition at line 98 of file html.cpp.

References pos().

Referenced by main().

◆ fileExists()

bool fileExists ( const std::string & path)
static

Definition at line 52 of file html.cpp.

Referenced by ensureCss().

◆ main()

◆ readFile()

std::string readFile ( const std::string & path)
static

Definition at line 30 of file html.cpp.

Referenced by main().

◆ writeHtml()

void writeHtml ( const std::string & src,
const std::string & inPath,
const std::string & outPath,
const std::string & cssHref = "" )
static

Render src to outPath. For .pas input PasHTMLGen is used and the HTML links to cssHref; if cssHref is empty the default stylesheet is written alongside the output.

Definition at line 74 of file html.cpp.

References endsWith(), ensureCss(), mxvm::HTMLGen::output(), and mxvm::PasHTMLGen::output().

Referenced by main().