Giter Club home page Giter Club logo

anchorify's Introduction

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 <hn> tags ("n" being a number from 1 to 6). It replaces these tags with an "anchored" version, like so:

  <h1>Hello, everybody!<h1> # This gets changed to the following line
  <h1 id="hello,-everybody!">Hello, everybody!</h1>

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

  <a href="#hello,-everybody!">Hello, everybody!</a>

Nested headings

For each new header level (<h1>, <h2> etc.), a new indented level is used in the table of contents. For example:

  <h1>Foo</h1>
  <h2>Bar</h2>
  <h2>Baz</h2>
  <h3>Chunky Bacon</h3>

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 <toc> somewhere in your HTML document and the script will replace that with the table of contents in the resulting HTML.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.