diff --git a/test/fixtures/readme-with-special-characters.md b/test/fixtures/readme-with-special-characters.md new file mode 100644 index 0000000..19c7f1d --- /dev/null +++ b/test/fixtures/readme-with-special-characters.md @@ -0,0 +1,62 @@ +## Title with backslash `\` +test + +## 4 § Toimielimet +Special char + +## Урок 8. Кроссплатформенность и виртуализация +text + +## Interface: SOME\_NAME<\> +method + +## Version 1.10.5 +bugs + +## Version 1.10.6 +features + +## `TEXT 1` + +- item 1 + +## `TEXT 2 ...` + +TEXT 2.1 ... + +## MikroTik hAP ac² + +The [hAP ac²](https://mikrotik.com/product/hap_ac2) is + +## acclk dac %d:[0,acclk_dac_max):dac +description + +## Övningsuppgifter +swedish + +## Sections +This readme causes an error `

` text `

` more text (`

`) + +## Тест +cyrillic + +## There's an error here +bad + +## Replace .gitlab-ci.yml +file name + +## `this identifier` +text + +## Header & noise +ampersand + +## CJK。 +CJK Symbols + +## ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿Latin 1 +Latin 1 + +## Instance properties inherited from [`EventEmitter`](http://nodejs.org/api/events.html) +Text \ No newline at end of file diff --git a/test/transform-weird-headers.js b/test/transform-weird-headers.js index 5154429..28f8563 100644 --- a/test/transform-weird-headers.js +++ b/test/transform-weird-headers.js @@ -80,3 +80,38 @@ test('\nformatted headers', function (t) { t.end() }) + +test('\nrandom md characters', function (t) { + var content = require('fs').readFileSync(__dirname + '/fixtures/readme-with-special-characters.md', 'utf8'); + var headers = transform(content); + + t.deepEqual( + headers.toc.split('\n') + , [ '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*', + '', + '- [Title with backslash `\\`](#title-with-backslash-)', + '- [4 § Toimielimet](#4-%C2%A7-toimielimet)', + '- [Урок 8. Кроссплатформенность и виртуализация](#%D1%83%D1%80%D0%BE%D0%BA-8-%D0%BA%D1%80%D0%BE%D1%81%D1%81%D0%BF%D0%BB%D0%B0%D1%82%D1%84%D0%BE%D1%80%D0%BC%D0%B5%D0%BD%D0%BD%D0%BE%D1%81%D1%82%D1%8C-%D0%B8-%D0%B2%D0%B8%D1%80%D1%82%D1%83%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D1%8F)', + '- [Interface: SOME\\_NAME<\\>](#interface-some_name)', + '- [Version 1.10.5](#version-1105)', + '- [Version 1.10.6](#version-1106)', + '- [`TEXT 1`](#text-1)', + '- [`TEXT 2 ...`](#text-2-)', + '- [MikroTik hAP ac²](#mikrotik-hap-ac)', + '- [acclk dac %d:[0,acclk_dac_max):dac](#acclk-dac-d0acclk_dac_maxdac)', + '- [Övningsuppgifter](#%C3%B6vningsuppgifter)', + '- [Sections](#sections)', + '- [Тест](#%D1%82%D0%B5%D1%81%D1%82)', + '- [There\'s an error here](#theres-an-error-here)', + '- [Replace .gitlab-ci.yml](#replace-gitlab-ciyml)', + '- [`this identifier`](#this-identifier)', + '- [Header & noise](#header--noise)', + '- [CJK。](#cjk)', + '- [¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿Latin 1](#%C2%AA%C2%B5%C2%BAlatin-1)', + '- [Instance properties inherited from `EventEmitter`](#instance-properties-inherited-from-eventemitter)', + '' ] + , 'generates a correct toc when readme has nameless table headers' + ) + + t.end() +}) diff --git a/test/transform.js b/test/transform.js index 3d8dfa6..658ce75 100644 --- a/test/transform.js +++ b/test/transform.js @@ -64,7 +64,7 @@ check( , 'some main usage here' ].join('\r\n') , [ '**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*\n\n' - , '- [My Module using \\r\\n line endings](#my-module-using-%5Cr%5Cn-line-endings)\n' + , '- [My Module using \\r\\n line endings](#my-module-using-rn-line-endings)\n' , ' - [API](#api)\n' , ' - [Method One](#method-one)\n' , ' - [Method Two](#method-two)\n'