Lexor Documentation¶
Lexor is a document converter implemented in Python.
Basic Usage¶
What is Lexor?¶
Lexor provides a platform where we can specify how a document is parsed, converted and written. It is an expandable Python package which aims to provide functionality to deal with any text file.
Motivation¶
Lexor started as a simple HTML file parser which later evolved into a markdown parser. The first versions took inspiration on Python-Markdown. However, the need to modify and extend the functionality let us to find Pandoc.
Today, lexor aims to behave similary to Pandoc, in the sense that it converts documents but it does so to meet the users preferences. For instance, we may want to write an HTML file in a minified form, that is, seeing as spaces and new lines do not matter in almost all HTML tags we could write an HTML in a single line, provided that there are no script or other special tags. Or perhaps we want to let Lexor write it in a different style. Lexor attempts to emulate Pandoc in Python. We should note that Pandoc is written in Haskell and although Pandoc already has lots of document converters, Lexor brings potential for Python users to create their own tools for processing files in a simplified manner.
Installing Lexor¶
Pip or Manual Installation¶
The easiest way to install lexor is to use pip. If you wish to perform a global installation and you have admin rights then do
sudo pip install lexor
or to install in some directory under your user account
pip install --user lexor
Or if you prefer to do do a manual installation then you may do the following from the command line (where x.y is the version number):
wget https://pypi.python.org/packages/source/l/lexor/lexor-x.y.tar.gz
tar xvzf lexor-x.y.tar.gz
cd lexor-x.y/
sudo python setup.py install
The last command can be replaced by python setup.py install --user. See PyPI for all available versions.
Lexor Languages¶
The basic lexor installation does not provide any parsers, converters or writers. You must install them manually using the install lexor command.
lexor install <language>
To see the available languages see http://jmlopez-rod.github.io/lexor-lang/.
Getting Started¶
As a simple example we will use the HTML language:
lexor install html
Consider the file example.html
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<p>
This is an example
</p>
</body>
</html>
Now we can rewrite this file into three different versions:
lexor example.html html~plain,min,_~ -wn
The -w option writes the output to a file by appending the specified style. The -n suppress the output in the terminal.
The following are the files written:
example.default.html:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<p> This is an example </p>
</body>
</html>
example.plain.html:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
<p>
This is an example
</p>
</body>
example.min.html:
<!DOCTYPE html><html><head><title>Example</title></head><body><h1>Example</h1><p> This is an example </p></body></html>
For more information on how to transform files see the lexor command to.
Lexor API¶
API¶
This is the Lexor API documentation, autogenerated from the source code.