Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/samwho/anchorify

A simple Ruby script for automatically creating anchored headings and tables of contents in HTML documents.
https://github.com/samwho/anchorify

Last synced: about 2 months ago
JSON representation

A simple Ruby script for automatically creating anchored headings and tables of contents in HTML documents.

Awesome Lists containing this project

README

        

# Anchorify

Anchorify is a simple script written in Ruby that parses an HTML
document to produce anchored headings and an optional table of contents.

The script parses the input HTML document and searches for `` tags ("n" being a number from 1 to 6). It replaces these tags with an "anchored" version, like so:

```html

Hello, everybody!

# This gets changed to the following line

Hello, everybody!


```

And the table of contents that goes with that would look like this:

```html
Hello, everybody!
```

# Nested headings

For each new header level (`

`, `

` etc.), a new indented level is used
in the table of contents. For example:

```html

Foo


Bar


Baz


Chunky Bacon


```

Would generate a table of contents that looks like this:

```
Foo
Bar
Baz
Chunky Bacon
```

# Installing

First of all, you need to make sure that you have Ruby and git installed
on your machine. To do this in Ubuntu, execute the following command:

```
sudo apt-get install ruby git
```

Then, nagivate to a directory you want to download the script to and
clone the git repo and make the script executable:

```
git clone git://github.com/samwho/anchorify.git
cd anchorify
chmod +x anchorify
```

# Usage

Using the script is easy. The only prerequisite is having ruby installed
on your system, then you just execute:

```
anchorify example.html
```

Where example.html is an HTML document. The output is printed to the
screen so if you want to save to another file you would do the following:

```
anchorify example.html >> anchorified.html
```

# Adding a table of contents

Adding a table of contents to your document is easy, simply put the pseudo
tag `` somewhere in your HTML document and the script will replace that
with the table of contents in the resulting HTML.