mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-09 01:32:34 -05:00
Fix Windows WYSIWYG linking issue (switching to splitview and resolving links in WYSIWYG) (#16133)
* fix relative links not correctly formatted due to marked js * logic in one place
This commit is contained in:
26
src/sql/workbench/contrib/notebook/common/utils.ts
Normal file
26
src/sql/workbench/contrib/notebook/common/utils.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { isWindows } from 'vs/base/common/platform';
|
||||
|
||||
/**
|
||||
* Due to marked js parsing returning an invalid path (ex. ....\) we must format the path to ensure directories are formatted properly (ex. ..\..\).
|
||||
* Issue tracked here: https://github.com/markedjs/marked/issues/2135
|
||||
* The function only formats the path for Windows platform (in which the invalid form occurs) and checks to see if the path is invalid based on the leading periods.
|
||||
* We use the first slash of path and create a relative path format (..\) string based on amount of leading periods
|
||||
* and then concatenate the relative path format string to rest of path after slash
|
||||
* @param href is the relative path
|
||||
* @returns properly formatted relative path
|
||||
*/
|
||||
export function replaceInvalidLinkPath(href: string): string {
|
||||
if (isWindows && href.startsWith('...')) {
|
||||
let slashIndex = href.indexOf('\\');
|
||||
href = '..\\'.repeat(slashIndex / 2) + href.substring(slashIndex + 1);
|
||||
return href;
|
||||
} else {
|
||||
// returns original path since it is valid
|
||||
return href;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user