From 4c69aafbc0588ffb723c561680a38b621fc4b424 Mon Sep 17 00:00:00 2001 From: Pat Hermens Date: Wed, 2 Jan 2019 20:49:20 +0100 Subject: [PATCH 1/2] Add check for Files>EOL ==="auto" and set it to "\n" --- src/extension.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 03a12bc..ab39735 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -267,7 +267,13 @@ class MarkdownTocTools { let lineEnding = workspace.getConfiguration("files").get("eol"); let tabSize = workspace.getConfiguration("[markdown]")["editor.tabSize"]; let insertSpaces = workspace.getConfiguration("[markdown]")["editor.insertSpaces"]; - + + if(lineEnding === undefined || lineEnding === null || lineEnding === "auto") { + // Default back to "\n" in case of VSCode update 1.29.0, + // where `Files > EOL` was set to the string value "auto". + // See https://github.com/AlanWalk/markdown-toc/issues/65 + lineEnding = "\n"; + } if(tabSize === undefined || tabSize === null) { tabSize = workspace.getConfiguration("editor").get("tabSize"); } From abf026b07c0f7153e32c9cae650213a62d871190 Mon Sep 17 00:00:00 2001 From: Pat Hermens Date: Mon, 7 Jan 2019 11:03:57 +0100 Subject: [PATCH 2/2] Updated to use OS defaults --- package.json | 46 ++++++++++++++++++++++++---------------------- src/extension.ts | 6 +++--- tsconfig.json | 6 +++++- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index a7f22d4..5151c7d 100644 --- a/package.json +++ b/package.json @@ -35,22 +35,23 @@ "main": "./out/src/extension", "contributes": { "commands": [ - { - "command": "extension.updateMarkdownToc", - "title": "Markdown TOC: Insert/Update" - }, - { - "command": "extension.deleteMarkdownToc", - "title": "Markdown TOC: Delete" - }, - { - "command": "extension.updateMarkdownSections", - "title": "Markdown Sections: Insert/Update" - }, - { - "command": "extension.deleteMarkdownSections", - "title": "Markdown Sections: Delete" - }], + { + "command": "extension.updateMarkdownToc", + "title": "Markdown TOC: Insert/Update" + }, + { + "command": "extension.deleteMarkdownToc", + "title": "Markdown TOC: Delete" + }, + { + "command": "extension.updateMarkdownSections", + "title": "Markdown Sections: Insert/Update" + }, + { + "command": "extension.deleteMarkdownSections", + "title": "Markdown Sections: Delete" + } + ], "menus": { "editor/context": [ { @@ -71,7 +72,7 @@ } ] }, - "keybindings":[ + "keybindings": [ { "command": "extension.updateMarkdownToc", "key": "ctrl+m t" @@ -119,12 +120,12 @@ "type": "string", "default": "github.com", "description": "anchor mode.", - "enum": [ - "github.com", - "bitbucket.org", - "ghost.org", + "enum": [ + "github.com", + "bitbucket.org", + "ghost.org", "gitlab.com" - ] + ] } } } @@ -135,6 +136,7 @@ "postinstall": "node ./node_modules/vscode/bin/install" }, "dependencies": { + "@types/node": "^10.12.18", "anchor-markdown-header": "^0.5.7" }, "devDependencies": { diff --git a/src/extension.ts b/src/extension.ts index ab39735..813606f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -269,10 +269,10 @@ class MarkdownTocTools { let insertSpaces = workspace.getConfiguration("[markdown]")["editor.insertSpaces"]; if(lineEnding === undefined || lineEnding === null || lineEnding === "auto") { - // Default back to "\n" in case of VSCode update 1.29.0, - // where `Files > EOL` was set to the string value "auto". + // Use OS default line-endings where `Files > EOL` was set to the string value "auto". + // "eol=auto" was introduced in VSCode update 1.29.0. // See https://github.com/AlanWalk/markdown-toc/issues/65 - lineEnding = "\n"; + lineEnding = require('os').EOL; } if(tabSize === undefined || tabSize === null) { tabSize = workspace.getConfiguration("editor").get("tabSize"); diff --git a/tsconfig.json b/tsconfig.json index e5187e7..b9e5ded 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,11 @@ "outDir": "out", "noLib": true, "sourceMap": true, - "rootDir": "." + "rootDir": ".", + "moduleResolution": "node", + "types": [ + "node" + ] }, "exclude": [ "node_modules"