diff --git a/lib/Toc.coffee b/lib/Toc.coffee index db89079..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 @@ -71,11 +72,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 +88,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 "" @@ -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': =>