diff --git a/src/extension.ts b/src/extension.ts index 03a12bc..92c7e38 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -126,9 +126,9 @@ class MarkdownTocTools { let tocRange = this.getTocRange(); this.updateOptions(tocRange); let headerList = this.getHeaderList(); - + window.activeTextEditor.edit(function(editBuilder) { - headerList.forEach(element => { + headerList.forEach(element => { let newHeader = element.header + " " + element.orderedList + " " + element.baseTitle editBuilder.replace(element.range, newHeader); }); @@ -203,7 +203,7 @@ class MarkdownTocTools { let optionsText = window.activeTextEditor.document.lineAt(tocRange.start.line).text; let options = optionsText.match(REGEXP_TOC_CONFIG); if (options == null) return; - + options.forEach(element => { let pair = REGEXP_TOC_CONFIG_ITEM.exec(element) let key = pair[1].toLocaleLowerCase(); @@ -265,9 +265,12 @@ class MarkdownTocTools { private createToc(editBuilder : TextEditorEdit, headerList : any[], insertPosition : Position) { let lineEnding = workspace.getConfiguration("files").get("eol"); + if (lineEnding === "auto") { + lineEnding = "\n"; + } let tabSize = workspace.getConfiguration("[markdown]")["editor.tabSize"]; let insertSpaces = workspace.getConfiguration("[markdown]")["editor.insertSpaces"]; - + if(tabSize === undefined || tabSize === null) { tabSize = workspace.getConfiguration("editor").get("tabSize"); } @@ -278,7 +281,7 @@ class MarkdownTocTools { let tab = '\t'; if (insertSpaces && tabSize > 0) { tab = " ".repeat(tabSize); - } + } let optionsText = []; optionsText.push('