From d5a2aa6d6d8ab0434cd29da4a4b294e4c1839ae2 Mon Sep 17 00:00:00 2001 From: Baptiste Augrain Date: Sat, 15 Dec 2018 10:41:47 +0100 Subject: [PATCH] fix missing bullets --- browser/lib/markdown-toc-generator.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/browser/lib/markdown-toc-generator.js b/browser/lib/markdown-toc-generator.js index a7bc79f3..7a97f800 100644 --- a/browser/lib/markdown-toc-generator.js +++ b/browser/lib/markdown-toc-generator.js @@ -2,14 +2,13 @@ * @fileoverview Markdown table of contents generator */ +import { EOL } from 'os' import toc from 'markdown-toc' import diacritics from 'diacritics-map' import stripColor from 'strip-color' import mdlink from 'markdown-link' import slugify from './slugify' -const EOL = require('os').EOL - const hasProp = Object.prototype.hasOwnProperty /** @@ -23,6 +22,11 @@ function uniqueSlug (slug, slugs, opts) { return uniq } +function linkify (token) { + token.content = mdlink(token.content, '#' + token.slug) + return token +} + const TOC_MARKER_START = '' const TOC_MARKER_END = '' @@ -70,14 +74,16 @@ export function generate (markdownText) { uniqueSlugStartIndex: 1 } - const tokens = toc(markdownText, { + const result = toc(markdownText, { slugify: title => { return uniqueSlug(slugify(title), slugs, opts) }, linkify: false }) - const md = tokens.json.map(token => mdlink(token.content, '#' + token.slug)).join(EOL) + const md = toc.bullets(result.json.map(linkify), { + highest: result.highest + }) return TOC_MARKER_START + EOL + EOL + md + EOL + EOL + TOC_MARKER_END }