Project Home

rst-literals

Abstract

Extracts literal blocks from a ReST document and save them out to files.

Table of Contents

Description

Extracts literal blocks from a ReST document and save them out to files.

Each literal block can be typed by placing a string like #!<type> on the first line of the literal block. This can be done, for example, #to mark some literal blocks as SQL code. Literal blocks that are not typed are #associated to the type 'generic'.

If you only want to output a specific type of literal block, you can decide which one to output by using the -t option. By default, only the generic blocks are output.

Note

The author uses for multiple purposes, in a way that reminds him of literate programming. For example, when designing a database schema, an interesting use case is to include the schema in a document that describes the entities in detail, with their intended purpose. The code itself goes in the literal blocks. You can them easily extract the SQL string that contains all the SQL data definitions to setup your database schema.

Here is an example:

#!sql
CREATE TABLE price (

  id SERIAL,
  asset_id INTEGER REFERENCES asset(id),
  date TIMESTAMP WITHOUT TIME ZONE,
  price NUMERIC(16, 6),

  PRIMARY KEY (id)
);

If you run rst-literals on this text you will get only the literal block under #!sql.

Blocks may also be named. If you mark it up like this:

#!sql price-table.sql
CREATE TABLE price (

you can use the `` --save-named-blocks `` option to have the blocks extracted to corresponding files. Note that you may just use the name if you like:

#! example1.sql
CREATE TABLE price (

Please Donate!

Important

This computer program or library is provided for free. I am aware that some of the programs that I provide for free allow people to get their work done faster or better, save them time and money. If you are using this program for benefit, especially if you are using it within a commercial environment and it saves you time or work, please consider making a donation by sending me a book from my Amazon Wishlist or by a direct donation to my company's PayPal account by clicking on the link below.

Download

Download program here.