An open API service indexing awesome lists of open source software.

https://github.com/gitbookio/brightml

Smart utility rendering markdown-ready HTML
https://github.com/gitbookio/brightml

Last synced: 9 months ago
JSON representation

Smart utility rendering markdown-ready HTML

Awesome Lists containing this project

README

          

# Brightml

Smart utility rendering markdown-ready HTML.

## Install

```Shell
$ npm install brightml
```

## Use

Clean all HTML at once :

```JavaScript
var brightml = require('brightml');

var HTMLString = 'Title 1Title 2Data 1Data 2';

var cleanHTML = brightml.clean(HTMLString);
// cleanHTML is :
//
//
//
// Title 1
// Title 2
//
//
//
//
// Data 1
// Data 2
//
//
//
```

Or use the module's functions as required :

```JavaScript
var brightml = require('brightml');

var HTMLString = 'Title 1Title 2Data 1Data 2';

brightml.parse(HTMLString);
brightml.formatTables();
var cleanHTML = brightml.render();
// cleanHTML is :
//
//
//
// Title 1
// Title 2
//
//
//
//
// Data 1
// Data 2
//
//
//
```

## What it does

Using `brightml.clean(html)` performs the following operations in order.

#### brightml.parse(HTMLString)

Convert HTML to DOM using [cheerio](https://github.com/cheeriojs/cheerio).

#### brightml.retrieveFootNotes()

For cross-referenced links, handle retrieving the foot/endnotes before the next `

` tag to keep notes within a chapter section.

The footnotes are then formatted as follow:

```HTML

Footnotes



See how to properly format a footnote1.



Footnotes are in a paragraph and a sup tag. Link to go back to reference is at the end of the footnote.



```

#### brightml.setAnchorsId()

Try to set `` tags `id` attribute on their direct parent if possible.

#### brightml.cleanElements()

* Remove empty tags.
* Remove forbidden HTML tags and place their HTML content in a `

` instead.
* Remove forbidden HTML attributes.
* Remove unallowed links schema in HTML attributes.

This operation uses the `rules.js` file to determine which tags/attributes/schemes are allowed.

#### brightml.cleanImagesInTitles()

Move `` tags in titles right after the concerned `` tag.

#### brightml.normalizeTitlesId()

Set an `id` attribute on each `` tag. The `id` is based on the title tag content.

Each reference to this `id` will be modified in consequence.

```HTML

A great title


Back to a great title
```
will become:
```HTML

A great title


Back to a great title
```

#### brightml.removeNestedTables()

Replace nested `` tags by a warning message followed by their content in a simple `` tag.

#### brightml.formatTables()

Ensure every `` elements look the same.

Used schema :

```HTML




Title 1
Title 2





Row 1 - Data 1
Row 1 - Data 2


Row 2 - Data 1
Row 2 - Data 2

```

#### brightml.cleanTableCells()

Ensure every `` and `` tags don't contain a `

` tag to prevent line breaking.

#### brightml.render()

Returns the current state of `HTMLString` passed to `brightml.parse(HTMLString)`.