diff --git a/CHANGELOG.md b/CHANGELOG.md index 13ab6fb..2156f10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.8.7] - 2023-10-15 + +Updated [crossnote](https://github.com/shd101wyy/crossnote) to version [0.9.2](https://github.com/shd101wyy/crossnote/releases/tag/0.9.2) and version [0.9.3](https://github.com/shd101wyy/crossnote/releases/tag/0.9.3). + +### New features + +- Added `ID` button to copy the element id to clipboard: + + ![Screenshot from 2023-10-15 15-34-27](https://github.com/shd101wyy/crossnote/assets/1908863/ede91390-3cca-4b83-8e30-33027bf0a363) + +- Supported to import section of markdown by header id: + + ```markdown + @import "test.md#header-id" + + or + + ![](test.md#header-id) + + or + + ![[test#header-id]] + ``` + +### Bug fixes + +- URL fragments on image links do not load: https://github.com/shd101wyy/vscode-markdown-preview-enhanced/issues/1837 +- Supported matplotlib-type preview for other Python tools like `pipenv`: https://github.com/shd101wyy/crossnote/issues/332 +- Fixed jump to header from link like `[link](test.md#header-id)`. +- Better handling of source map for importing files. + ## [0.8.6] - 2023-10-14 This MPE version reduced the VS Code version requirement to 1.70.0 or above. diff --git a/package.json b/package.json index dccfb05..5109f86 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "markdown-preview-enhanced", "displayName": "%displayName%", - "version": "0.8.6", + "version": "0.8.7", "description": "%description%", "categories": [ "Other" @@ -674,7 +674,7 @@ "@types/crypto-js": "^4.1.2", "@types/vfile": "^3.0.2", "async-mutex": "^0.4.0", - "crossnote": "^0.9.1", + "crossnote": "^0.9.3", "crypto-js": "^4.1.1" }, "devDependencies": { diff --git a/src/extension-common.ts b/src/extension-common.ts index fb11eee..eb669c9 100644 --- a/src/extension-common.ts +++ b/src/extension-common.ts @@ -1,5 +1,5 @@ // For both node.js and browser environments -import { PreviewMode, utility } from 'crossnote'; +import { HeadingIdGenerator, PreviewMode, utility } from 'crossnote'; import { SHA256 } from 'crypto-js'; import * as vscode from 'vscode'; import { PreviewColorScheme, getMPEConfig, updateMPEConfig } from './config'; @@ -581,7 +581,9 @@ export async function initExtensionCommon(context: vscode.ExtensionContext) { }); } else { // Open fileUri - const editor = await vscode.window.showTextDocument(document, col); + const editor = await vscode.window.showTextDocument(document, { + viewColumn: col, + }); // if there was line fragment, jump to line if (line >= 0) { let viewPos = vscode.TextEditorRevealType.InCenter; @@ -591,6 +593,32 @@ export async function initExtensionCommon(context: vscode.ExtensionContext) { const sel = new vscode.Selection(line, 0, line, 0); editor.selection = sel; editor.revealRange(sel, viewPos); + } else if (fileUri.fragment) { + // Normal fragment + // Find heading with this id + const headingIdGenerator = new HeadingIdGenerator(); + const text = editor.document.getText(); + const lines = text.split('\n'); + let i = 0; + for (i = 0; i < lines.length; i++) { + const line = lines[i]; + if (line.match(/^#+\s+/)) { + const heading = line.replace(/^#+\s+/, ''); + const headingId = headingIdGenerator.generateId(heading); + if (headingId === fileUri.fragment) { + // Reveal editor line + let viewPos = vscode.TextEditorRevealType.InCenter; + if (editor.selection.active.line === i) { + viewPos = + vscode.TextEditorRevealType.InCenterIfOutsideViewport; + } + const sel = new vscode.Selection(i, 0, i, 0); + editor.selection = sel; + editor.revealRange(sel, viewPos); + break; + } + } + } } } } else { diff --git a/yarn.lock b/yarn.lock index 9fcdc6c..b2dec68 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1920,10 +1920,10 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3: shebang-command "^2.0.0" which "^2.0.1" -crossnote@^0.9.1: - version "0.9.1" - resolved "https://registry.yarnpkg.com/crossnote/-/crossnote-0.9.1.tgz#337501353c0d9f756aca3f692437ec98a7f3b2e3" - integrity sha512-KITHY/6RQSun5qSZBVbpIYUme0af0bb74pd75gSRuKBVmrgJooOC1AFpdRfREVqIboHXfmXvtRM84xtRk0Y0ow== +crossnote@^0.9.3: + version "0.9.3" + resolved "https://registry.yarnpkg.com/crossnote/-/crossnote-0.9.3.tgz#b8bb76eea4042839520ed764bd28155023b2b2b3" + integrity sha512-j1JIoswsKPYmEpqQ3iZoA/EnCaWNRmzhgnRIJR+2xfvqAvLif4beYHGwktJo9kDIqxQhCrK+QjSvDoAgk3cTOQ== dependencies: "@headlessui/react" "^1.7.17" "@heroicons/react" "^2.0.18"