Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/Toc.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Toc
constructor: (@editor) ->
@lines = []
@list = []
@headerPrefix = atom.config.get 'markdown-toc.headerPrefix'
@options =
depthFrom: 1 # depthFrom
depthTo: 6 # depthTo
Expand Down Expand Up @@ -71,11 +72,11 @@ class Toc
for i of @lines
line = @lines[i]
if @open is false
if line.match /^<!--(.*)TOC(.*)-->$/g
if line.match /^\[\/\/\]: # \(TOC(.*)\)$/g
@open = parseInt i
options = line
else
if line.match /^<!--(.*)\/TOC(.*)-->$/g
if line.match /^\[\/\/\]: # \(\/TOC(.*)\)$/g
@close = parseInt i
break

Expand All @@ -87,16 +88,16 @@ class Toc


# embed list with the open and close comment:
# <!-- TOC --> [list] <!-- /TOC -->
# [//]: # TOC) [list] [//]: # /TOC)
_createToc: () ->
@__updateList()
if Object.keys(@list).length > 0
text = []
text.push "<!-- TOC depthFrom:"+@options.depthFrom+" depthTo:"+@options.depthTo+" withLinks:"+@options.withLinks+" updateOnSave:"+@options.updateOnSave+" orderedList:"+@options.orderedList+" -->\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<!-- /TOC -->"
text.push "\n[//]: # (/TOC)"
return text.join "\n"
return ""

Expand Down Expand Up @@ -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 ""
5 changes: 5 additions & 0 deletions lib/markdown-toc.coffee
Original file line number Diff line number Diff line change
@@ -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': =>
Expand Down