From 11a57ad6ff3db7dbcf6aad6a339481e9eac5de0b Mon Sep 17 00:00:00 2001 From: Coen de Meijer Date: Wed, 7 Dec 2016 13:51:49 +0100 Subject: [PATCH 1/2] Comments surrounding the TOC are displayed in my BitBucket repo. * Replaced html comments with link labels --- lib/Toc.coffee | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/Toc.coffee b/lib/Toc.coffee index db89079..a00cfab 100644 --- a/lib/Toc.coffee +++ b/lib/Toc.coffee @@ -71,11 +71,11 @@ class Toc for i of @lines line = @lines[i] if @open is false - if line.match /^$/g + if line.match /^\[\/\/\]: # \(TOC(.*)\)$/g @open = parseInt i options = line else - if line.match /^$/g + if line.match /^\[\/\/\]: # \(\/TOC(.*)\)$/g @close = parseInt i break @@ -87,16 +87,16 @@ class Toc # embed list with the open and close comment: - # [list] + # [//]: # TOC) [list] [//]: # /TOC) _createToc: () -> @__updateList() if Object.keys(@list).length > 0 text = [] - text.push "\n" + text.push "[//]: # (TOC depthFrom:"+@options.depthFrom+" depthTo:"+@options.depthTo+" withLinks:"+@options.withLinks+" updateOnSave:"+@options.updateOnSave+" orderedList:"+@options.orderedList+")\n" list = @__createList() if list isnt false Array.prototype.push.apply text, list - text.push "\n" + text.push "\n[//]: # (/TOC)" return text.join "\n" return "" From 4e26f4e73c418f482260e9d6bbf4e54bb69d5003 Mon Sep 17 00:00:00 2001 From: Coen de Meijer Date: Wed, 7 Dec 2016 14:03:35 +0100 Subject: [PATCH 2/2] TOC does not work with BitBucket repo. * Added `headerPrefix` configuration parameter to allow for a custom prefix for TOC elements --- lib/Toc.coffee | 3 ++- lib/markdown-toc.coffee | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Toc.coffee b/lib/Toc.coffee index a00cfab..92d68b8 100644 --- a/lib/Toc.coffee +++ b/lib/Toc.coffee @@ -5,6 +5,7 @@ class Toc constructor: (@editor) -> @lines = [] @list = [] + @headerPrefix = atom.config.get 'markdown-toc.headerPrefix' @options = depthFrom: 1 # depthFrom depthTo: 6 # depthTo @@ -210,7 +211,7 @@ class Toc link = [] link.push "[" link.push name - link.push "](#" + link.push "](##{@headerPrefix}" link.push hash link.push ")" return link.join "" diff --git a/lib/markdown-toc.coffee b/lib/markdown-toc.coffee index aa30d5d..11feaf9 100644 --- a/lib/markdown-toc.coffee +++ b/lib/markdown-toc.coffee @@ -1,6 +1,11 @@ Toc = require './Toc' module.exports = + config: + headerPrefix: + default: '' + title: 'Markdown header prefix (for BitBucket markdown set this to: \'markdown-header-\')' + type: 'string' activate: (state) -> atom.commands.add 'atom-workspace', 'markdown-toc:create': =>