├── .gitignore ├── test ├── fixtures │ ├── basic.html │ ├── tocminmax.html │ ├── anchorminmax.html │ ├── unique.html │ ├── basic-expected.html │ ├── unique-expected.html │ ├── tocminmax-expected.html │ └── anchorminmax-expected.html └── toc_test.js ├── .travis.yml ├── .jshintrc ├── package.json ├── LICENSE-MIT ├── Gruntfile.js ├── README.md └── lib └── toc.js /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | -------------------------------------------------------------------------------- /test/fixtures/basic.html: -------------------------------------------------------------------------------- 1 |

sample h1

2 |

sample h2

3 |

sample h3

4 |

sample h4

5 |
sample h5
6 |
sample h6
7 | sample h7 8 | -------------------------------------------------------------------------------- /test/fixtures/tocminmax.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

sample h1

4 |

sample h2

5 |

sample h3

6 |

sample h4

7 |
sample h5
8 |
sample h6
9 | -------------------------------------------------------------------------------- /test/fixtures/anchorminmax.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

sample h1

4 |

sample h2

5 |

sample h3

6 |

sample h4

7 |
sample h5
8 |
sample h6
9 | -------------------------------------------------------------------------------- /test/fixtures/unique.html: -------------------------------------------------------------------------------- 1 |

sample h1

2 | 3 |

sample h2

4 | 5 |

sample h3

6 |

sample h3

7 | 8 |

sample h2

9 | 10 |

sample h3

11 |

sample h3

12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.8" 4 | - "0.10" 5 | - "0.11" 6 | before_script: 7 | - npm install -g grunt-cli 8 | matrix: 9 | fast_finish: true 10 | allow_failures: 11 | - node_js: "0.11" 12 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": true, 11 | "boss": true, 12 | "eqnull": true, 13 | "node": true 14 | } 15 | -------------------------------------------------------------------------------- /test/fixtures/basic-expected.html: -------------------------------------------------------------------------------- 1 |

sample h1

2 |

sample h2

3 |

sample h3

4 |

sample h4

5 |
sample h5
6 |
sample h6
7 | sample h7 8 | -------------------------------------------------------------------------------- /test/fixtures/unique-expected.html: -------------------------------------------------------------------------------- 1 |

sample h1

2 | 3 |

sample h2

4 | 5 |

sample h3

6 |

sample h3

7 | 8 |

sample h2

9 | 10 |

sample h3

11 |

sample h3

12 | -------------------------------------------------------------------------------- /test/fixtures/tocminmax-expected.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

sample h1

4 |

sample h2

5 |

sample h3

6 |

sample h4

7 |
sample h5
8 |
sample h6
9 | -------------------------------------------------------------------------------- /test/fixtures/anchorminmax-expected.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |

sample h1

4 |

sample h2

5 |

sample h3

6 |

sample h4

7 |
sample h5
8 |
sample h6
9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "toc", 3 | "description": "Linkify HTML headers and generate a TOC.", 4 | "version": "0.4.0", 5 | "homepage": "https://github.com/cowboy/node-toc", 6 | "author": { 7 | "name": "\"Cowboy\" Ben Alman", 8 | "url": "http://benalman.com/" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/cowboy/node-toc.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/cowboy/node-toc/issues" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "https://github.com/cowboy/node-toc/blob/master/LICENSE-MIT" 21 | } 22 | ], 23 | "main": "lib/toc", 24 | "engines": { 25 | "node": ">= 0.8.0" 26 | }, 27 | "scripts": { 28 | "test": "grunt test" 29 | }, 30 | "devDependencies": { 31 | "grunt-contrib-jshint": "~0.8.0", 32 | "grunt-contrib-nodeunit": "~0.3.0", 33 | "grunt-contrib-watch": "~0.5.3", 34 | "grunt": "~0.4.2" 35 | }, 36 | "keywords": [], 37 | "dependencies": { 38 | "slug": "~0.4.2", 39 | "entities": "~0.5.0", 40 | "lodash": "~2.4.1" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 "Cowboy" Ben Alman 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(grunt) { 4 | 5 | // Project configuration. 6 | grunt.initConfig({ 7 | nodeunit: { 8 | files: ['test/**/*_test.js'], 9 | }, 10 | jshint: { 11 | options: { 12 | jshintrc: '.jshintrc' 13 | }, 14 | gruntfile: { 15 | src: 'Gruntfile.js' 16 | }, 17 | lib: { 18 | src: ['lib/**/*.js'] 19 | }, 20 | test: { 21 | src: ['test/**/*.js'] 22 | }, 23 | }, 24 | watch: { 25 | gruntfile: { 26 | files: '<%= jshint.gruntfile.src %>', 27 | tasks: ['jshint:gruntfile'] 28 | }, 29 | lib: { 30 | files: ['<%= jshint.lib.src %>'], 31 | tasks: ['jshint:lib', 'nodeunit'] 32 | }, 33 | test: { 34 | files: ['<%= jshint.test.src %>', 'test/fixtures/*.html'], 35 | tasks: ['jshint:test', 'nodeunit'] 36 | }, 37 | }, 38 | }); 39 | 40 | // These plugins provide necessary tasks. 41 | grunt.loadNpmTasks('grunt-contrib-nodeunit'); 42 | grunt.loadNpmTasks('grunt-contrib-jshint'); 43 | grunt.loadNpmTasks('grunt-contrib-watch'); 44 | 45 | grunt.registerTask('test', ['jshint', 'nodeunit']); 46 | grunt.registerTask('default', ['test']); 47 | 48 | }; 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # toc [![Build Status](https://secure.travis-ci.org/cowboy/node-toc.png?branch=master)](http://travis-ci.org/cowboy/node-toc) 2 | 3 | Linkify HTML headers and generate a TOC. 4 | 5 | ## Getting Started 6 | Install the module with: `npm install toc` 7 | 8 | ```js 9 | var toc = require('toc'); 10 | ``` 11 | 12 | ## Documentation 13 | 14 | ### toc.untag 15 | Strip HTML tags from a string. 16 | 17 | ```js 18 | var stripped = toc.untag(html); 19 | ``` 20 | 21 | ### toc.anchor 22 | Convert a string of text into something URL-friendly and not too fugly. 23 | 24 | ```js 25 | var anchor = toc.anchor(arbitraryText); 26 | ``` 27 | 28 | 29 | ### toc.unique 30 | Get a unique name and store the returned name in names for future unique-name-gettingness. 31 | 32 | ```js 33 | var names = {}; 34 | var guaranteedUniqueAnchor1 = toc.unique(names, toc.anchor(arbitraryText)); 35 | var guaranteedUniqueAnchor2 = toc.unique(names, toc.anchor(arbitraryText)); 36 | ``` 37 | 38 | 39 | ### toc.process 40 | Anchorize all headers and inline a generated TOC, returning processed HTML. 41 | 42 | ```js 43 | var htmlWithAnchorsAndTOC = toc.process(html [, options]); 44 | ``` 45 | 46 | #### options 47 | 48 | * **placeholder** - `RegExp` - Used to match TOC placeholder. Defaults to `//gi`. 49 | * _Because this method calls the `toc.anchorize` and `toc.toc` methods internally, their options may be specified as well._ 50 | 51 | 52 | ### toc.anchorize 53 | Parse HTML, returning an array of header objects and anchorized HTML. 54 | 55 | ```js 56 | var obj = toc.anchorize(html [, options]); 57 | ``` 58 | 59 | #### options 60 | 61 | * **headers** - `RegExp` - Used to match HTML headers. Defaults to `/]*)>([\s\S]+?)<\/h\1>/gi`. 62 | * **tocMin** - `Number` - Min header level to add to TOC. Defaults to `2`. 63 | * **tocMax** - `Number` - Max header level to add to TOC. Defaults to `6`. 64 | * **anchorMin** - `Number` - Min header level to anchorize. Defaults to `2`. 65 | * **anchorMax** - `Number` - Max header level to anchorize. Defaults to `6`. 66 | * **header** - `String` | `Function` - Lodash template string or function used to anchorize a header. 67 | 68 | 69 | ### toc.toc 70 | Generate TOC HTML from an array of header objects. 71 | 72 | ```js 73 | var obj = toc.toc(headers [, options]); 74 | ``` 75 | 76 | #### options 77 | 78 | * **openUL** - `String` | `Function` - Lodash template string or function used to generate the TOC. 79 | * **closeUL** - `String` | `Function` - Lodash template string or function used to generate the TOC. 80 | * **openLI** - `String` | `Function` - Lodash template string or function used to generate the TOC. 81 | * **closeLI** - `String` | `Function` - Lodash template string or function used to generate the TOC. 82 | * **TOC** - `String` | `Function` - Lodash template string or function used to wrap the generated TOC. 83 | 84 | 85 | ## Examples 86 | 87 | The default HTML is pretty awesome, but you can customize the hell out of the generated HTML, eg. 88 | 89 | ```js 90 | var processedHTML = toc.process(unprocessedHTML, { 91 | header: '<%= attrs %> id="<%= anchor %>"><%= header %>>', 92 | TOC: '
<%= toc %>
', 93 | openUL: '', 95 | openLI: '
  • <%= text %>', 96 | closeLI: '
  • ', 97 | }); 98 | ``` 99 | 100 | ## Contributing 101 | In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/). 102 | 103 | ## Release History 104 | 2014-02-28 - v0.4.0 - Updated a bunch of dependencies. Functionality shouldn't change, and all test pass, but YMMV. 105 | 2013-03-08 - v0.3.0 - Separated `.process` method internals into `.anchorize` and `.toc` methods. Renamed `toc` template option to `TOC`. 106 | 2013-03-07 - v0.2.0 - Second official release. Minor changes. 107 | 2013-03-07 - v0.1.0 - First official release. 108 | -------------------------------------------------------------------------------- /lib/toc.js: -------------------------------------------------------------------------------- 1 | /* 2 | * toc 3 | * https://github.com/cowboy/node-toc 4 | * 5 | * Copyright (c) 2013 "Cowboy" Ben Alman 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | var _ = require('lodash'); 12 | 13 | var toc = exports; 14 | 15 | // Default options. 16 | toc.defaults = { 17 | // DEFAULTS FOR toc.process() 18 | // 19 | // RegExp to replace with generated TOC. 20 | placeholder: //gi, 21 | 22 | // DEFAULTS FOR toc.anchorize() 23 | // 24 | // Match H? headers and all their contents. 25 | headers: /]*)>([\s\S]+?)<\/h\1>/gi, 26 | // Min and max headers to add to TOC. 27 | tocMin: 2, 28 | tocMax: 6, 29 | // Min and max headers to anchorize. 30 | anchorMin: 2, 31 | anchorMax: 6, 32 | // Anchorized header template. 33 | header: '<%= attrs %>><%= header %>>', 34 | 35 | // DEFAULTS FOR toc.toc() 36 | // 37 | // TOC part templates. 38 | openUL: '', 40 | openLI: '
  • <%= text %>', 41 | // openLI: '
  • <%= text %> (<%= depth %> / H<%= level %>)', 42 | closeLI: '
  • ', 43 | // Main TOC template. 44 | TOC: '
    <%= toc %>
    ', 45 | }; 46 | 47 | // Strip HTML tags from a string. 48 | toc.untag = function(s) { 49 | return s.replace(/<[^>]*>/g, ''); 50 | }; 51 | 52 | // Convert a string of text into something URL-friendly and not too fugly. 53 | toc.anchor = function(s) { 54 | var slug = require('slug'); 55 | var entities = require('entities'); 56 | 57 | s = toc.untag(s); 58 | s = s.toLowerCase(); 59 | s = entities.decode(s); 60 | s = s.replace(/['"!]|[\.]+$/g, ''); 61 | s = slug(s); 62 | s = s.replace(/[:\(\)]+/gi, '-'); 63 | s = s.replace(/[\s\-]*([\.])[\s\-]*/g, '$1'); 64 | s = s.replace(/-+/g, '-'); 65 | s = s.replace(/^-+|-+$/g, ''); 66 | return s; 67 | }; 68 | 69 | // Get a unique name and store the returned name in names for future 70 | // unique-name-gettingness. 71 | toc.unique = function(names, name) { 72 | var result = name; 73 | var count = 0; 74 | while (names[result]) { 75 | result = name + (--count); 76 | } 77 | names[result] = true; 78 | return result; 79 | }; 80 | 81 | // Compile specified lodash string template properties into functions. 82 | function normalize(options, templates) { 83 | // Options override defaults and toc methods. 84 | var result = _.defaults({}, options, toc, toc.defaults); 85 | // Remove "core" methods from result object. 86 | ['defaults', 'process', 'anchorize', 'toc'].forEach(function(prop) { 87 | delete result[prop]; 88 | }); 89 | // Compile Lodash string templates into functions. 90 | (templates || []).forEach(function(tmpl) { 91 | if (typeof result[tmpl] === 'string') { 92 | result[tmpl] = _.template(result[tmpl]); 93 | } 94 | }); 95 | return result; 96 | } 97 | 98 | // Anchorize all headers and inline a generated TOC, returning processed HTML. 99 | toc.process = function(src, options) { 100 | // Get anchorized HTML and headers array. 101 | var anchorized = toc.anchorize(src, options); 102 | // Generate TOC from headers array. 103 | var tocHtml = toc.toc(anchorized.headers, options); 104 | // Insert the generated TOC into the anchorized HTML. 105 | return anchorized.html.replace(normalize(options).placeholder, tocHtml); 106 | }; 107 | 108 | // Parse HTML, returning an array of header objects and anchorized HTML. 109 | toc.anchorize = function(src, options) { 110 | // Normalize options and compile template(s). 111 | options = normalize(options, ['header']); 112 | // Process HTML, "anchorizing" headers as-specified. 113 | var headers = []; 114 | var names = {}; 115 | var html = src.replace(options.headers, function(all, level, attrs, header) { 116 | level = Number(level); 117 | var tocLevel = level >= options.tocMin && level <= options.tocMax; 118 | var anchorLevel = level >= options.anchorMin && level <= options.anchorMax; 119 | var data; 120 | if (tocLevel || anchorLevel) { 121 | // This data is passed into the specified "header" template function. 122 | data = { 123 | // The header level number in ... 124 | level: level, 125 | // Any attributes in the open H? tag. 126 | attrs: attrs, 127 | // Header HTML contents. 128 | header: header, 129 | // Un-tagged header HTML contents. 130 | text: options.untag(header), 131 | // Unique anchor name for this header. 132 | anchor: options.unique(names, options.anchor(header)), 133 | // All HTML (including tags) matched by the "headers" RegExp. 134 | all: all, 135 | }; 136 | } 137 | if (tocLevel) { 138 | headers.push(data); 139 | } 140 | return anchorLevel ? options.header(data) : all; 141 | }); 142 | 143 | return { 144 | src: src, 145 | html: html, 146 | headers: headers, 147 | }; 148 | }; 149 | 150 | // Generate TOC HTML from an array of header objects. 151 | toc.toc = function(headers, options) { 152 | // Normalize options and compile template(s). 153 | options = normalize(options, ['TOC', 'openUL', 'closeUL', 'openLI', 'closeLI']); 154 | 155 | // Build TOC. 156 | var cursor = 0; 157 | var levels = []; 158 | var tocs = ['']; 159 | headers.forEach(function(header) { 160 | while (header.level < levels[0]) { 161 | levels.shift(); 162 | cursor++; 163 | } 164 | if (levels.length === 0 || header.level > levels[0]) { 165 | levels.unshift(header.level); 166 | header.depth = levels.length; 167 | tocs[cursor] += options.openUL(header); 168 | tocs.push(options.closeLI(header) + options.closeUL(header)); 169 | } else { 170 | header.depth = levels.length; 171 | tocs[cursor] += options.closeLI(header); 172 | } 173 | tocs[cursor] += options.openLI(header); 174 | }); 175 | 176 | return options.TOC({toc: tocs.join('')}); 177 | }; 178 | -------------------------------------------------------------------------------- /test/toc_test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var toc = require('../lib/toc.js'); 4 | var fs = require('fs'); 5 | var path = require('path'); 6 | 7 | function fixture(name) { 8 | var htmlfile = path.join(__dirname, 'fixtures', name + '.html'); 9 | return fs.readFileSync(htmlfile).toString(); 10 | } 11 | 12 | /* 13 | ======== A Handy Little Nodeunit Reference ======== 14 | https://github.com/caolan/nodeunit 15 | 16 | Test methods: 17 | test.expect(numAssertions) 18 | test.done() 19 | Test assertions: 20 | test.ok(value, [message]) 21 | test.equal(actual, expected, [message]) 22 | test.notEqual(actual, expected, [message]) 23 | test.deepEqual(actual, expected, [message]) 24 | test.notDeepEqual(actual, expected, [message]) 25 | test.strictEqual(actual, expected, [message]) 26 | test.notStrictEqual(actual, expected, [message]) 27 | test.throws(block, [error], [message]) 28 | test.doesNotThrow(block, [error], [message]) 29 | test.ifError(value) 30 | */ 31 | 32 | exports['untag'] = function(test) { 33 | test.expect(6); 34 | test.equal(toc.untag('foo'), 'foo', 'no tags to strip'); 35 | test.equal(toc.untag('foo'), 'foo', 'should strip tags'); 36 | test.equal(toc.untag('foo'), 'foo', 'should strip tags'); 37 | test.equal(toc.untag('foo'), 'foo', 'should strip tags'); 38 | test.equal(toc.untag('foo bar'), 'foo bar', 'should strip tags'); 39 | test.equal(toc.untag('foo&bar'), 'foo&bar', 'should not strip entities'); 40 | test.done(); 41 | }; 42 | 43 | exports['anchor'] = function(test) { 44 | test.expect(10); 45 | test.equal(toc.anchor('foo'), 'foo', 'anchor is already lovely.'); 46 | test.equal(toc.anchor('foo bar baz'), 'foo-bar-baz', 'spaces get converted to -'); 47 | test.equal(toc.anchor(' foo bar '), 'foo-bar', 'leading / trailing spaces get stripped'); 48 | test.equal(toc.anchor('foo----bar-----baz'), 'foo-bar-baz', 'multiple - get converted to -'); 49 | test.equal(toc.anchor('-----foo bar-----'), 'foo-bar', 'leading / trailing - get stripped'); 50 | test.equal(toc.anchor('i can\'t "go" for that'), 'i-cant-go-for-that', 'quotes get stripped'); 51 | test.equal(toc.anchor('obj / obj.method(this, [that])'), 'obj-obj.method-this-that', 'some other chars get stripped, yay'); 52 | test.equal(toc.anchor('obj.method ( this, [ that ] )'), 'obj.method-this-that', 'remove unnecessary - chars'); 53 | test.equal(toc.anchor('this: that :: the other'), 'this-that-the-other', 'replace : with - chars'); 54 | test.equal(toc.anchor('фøó & βåρ ♥ Бäž'), 'foo-and-bar-love-baz', 'entities and utf characters should be made happy'); 55 | test.done(); 56 | }; 57 | 58 | exports['unique'] = function(test) { 59 | test.expect(6); 60 | var names = {}; 61 | test.equal(toc.unique(names, 'foo'), 'foo', 'should be unique.'); 62 | test.equal(toc.unique(names, 'foo'), 'foo-1', 'no longer unique.'); 63 | test.equal(toc.unique(names, 'foo'), 'foo-2', 'no longer unique.'); 64 | test.equal(toc.unique(names, 'bar'), 'bar', 'should be unique.'); 65 | test.equal(toc.unique(names, 'foo-1'), 'foo-1-1', 'not unique.'); 66 | test.equal(toc.unique(names, 'foo-2'), 'foo-2-1', 'not unique.'); 67 | test.done(); 68 | }; 69 | 70 | exports['anchorize'] = { 71 | 'basic': function(test) { 72 | test.expect(3); 73 | var src = '

    H1 Header

    \n

    H2 Header

    \n

    H3 Header

    '; 74 | var expected = '

    H1 Header

    \n

    H2 Header

    \n

    H3 Header

    '; 75 | var actual = toc.anchorize(src); 76 | test.equal(actual.src, src, 'should return unprocessed src.'); 77 | test.equal(actual.html, expected, 'should return processed html.'); 78 | test.deepEqual(actual.headers, [ 79 | { 80 | level: 2, 81 | attrs: ' a=1', 82 | header: 'H2 Header', 83 | text: 'H2 Header', 84 | anchor: 'h2-header', 85 | all: '

    H2 Header

    ', 86 | }, 87 | { 88 | level: 3, 89 | attrs: ' b=2 c=3', 90 | header: 'H3 Header', 91 | text: 'H3 Header', 92 | anchor: 'h3-header', 93 | all: '

    H3 Header

    ', 94 | }, 95 | ], 'should return array of header objects.'); 96 | test.done(); 97 | }, 98 | // more tests welcome 99 | }; 100 | 101 | exports['toc'] = { 102 | 'basic': function(test) { 103 | test.expect(1); 104 | var headers = [ 105 | { 106 | level: 2, 107 | attrs: ' a=1', 108 | header: 'H2 Header', 109 | text: 'H2 Header', 110 | anchor: 'h2-header', 111 | all: '

    H2 Header

    ', 112 | }, 113 | { 114 | level: 3, 115 | attrs: ' b=2 c=3', 116 | header: 'H3 Header', 117 | text: 'H3 Header', 118 | anchor: 'h3-header', 119 | all: '

    H3 Header

    ', 120 | }, 121 | ]; 122 | var actual = toc.toc(headers); 123 | var expected = ''; 124 | test.equal(actual, expected, 'should return generated TOC html.'); 125 | test.done(); 126 | }, 127 | // more tests welcome 128 | }; 129 | 130 | exports['process'] = { 131 | 'defaults': function(test) { 132 | test.expect(1); 133 | var actual = toc.process(fixture('basic')); 134 | test.equal(actual, fixture('basic-expected'), 'should process using default options.'); 135 | test.done(); 136 | }, 137 | 'unique anchors': function(test) { 138 | test.expect(1); 139 | var actual = toc.process(fixture('unique')); 140 | test.equal(actual, fixture('unique-expected'), 'anchors should be unique.'); 141 | test.done(); 142 | }, 143 | 'anchorMin, anchorMax': function(test) { 144 | test.expect(1); 145 | var actual = toc.process(fixture('anchorminmax'), {anchorMin: 3, anchorMax: 5}); 146 | test.equal(actual, fixture('anchorminmax-expected'), 'the correct headers should be anchorized.'); 147 | test.done(); 148 | }, 149 | 'tocMin, tocMax': function(test) { 150 | test.expect(1); 151 | var actual = toc.process(fixture('tocminmax'), {tocMin: 3, tocMax: 5}); 152 | test.equal(actual, fixture('tocminmax-expected'), 'TOC should only contain the correct anchors.'); 153 | test.done(); 154 | }, 155 | // more tests welcome 156 | }; 157 | --------------------------------------------------------------------------------