mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-08 01:28:26 -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:
@@ -7,6 +7,7 @@ import TurndownService = require('turndown');
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import * as path from 'vs/base/common/path';
|
||||
import * as turndownPluginGfm from 'sql/workbench/contrib/notebook/browser/turndownPluginGfm';
|
||||
import { replaceInvalidLinkPath } from 'sql/workbench/contrib/notebook/common/utils';
|
||||
|
||||
// These replacements apply only to text. Here's how it's handled from Turndown:
|
||||
// if (node.nodeType === 3) {
|
||||
@@ -29,7 +30,6 @@ const markdownReplacements = [
|
||||
[/</g, '\\<'], // Added to ensure sample text like <hello> is escaped
|
||||
[/>/g, '\\>'], // Added to ensure sample text like <hello> is escaped
|
||||
];
|
||||
|
||||
export class HTMLMarkdownConverter {
|
||||
private turndownService: TurndownService;
|
||||
|
||||
@@ -310,6 +310,8 @@ export function findPathRelativeToContent(notebookFolder: string, contentPath: U
|
||||
let relativePath = contentPath.fragment ? path.relative(notebookFolder, contentPath.fsPath).concat('#', contentPath.fragment) : path.relative(notebookFolder, contentPath.fsPath);
|
||||
//if path contains whitespaces then it's not identified as a link
|
||||
relativePath = relativePath.replace(/\s/g, '%20');
|
||||
// if relativePath contains improper directory format due to marked js parsing returning an invalid path (ex. ....\) then we need to replace it to ensure the directories are formatted properly (ex. ..\..\)
|
||||
relativePath = replaceInvalidLinkPath(relativePath);
|
||||
if (relativePath.startsWith(path.join('..', path.sep) || path.join('.', path.sep))) {
|
||||
return relativePath;
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ import { defaultGenerator } from 'vs/base/common/idGenerator';
|
||||
import { revive } from 'vs/base/common/marshalling';
|
||||
import { ImageMimeTypes } from 'sql/workbench/services/notebook/common/contracts';
|
||||
import { IMarkdownStringWithCellAttachments, MarkdownRenderOptionsWithCellAttachments } from 'sql/workbench/contrib/notebook/browser/cellViews/interfaces';
|
||||
import { replaceInvalidLinkPath } from 'sql/workbench/contrib/notebook/common/utils';
|
||||
|
||||
// Based off of HtmlContentRenderer
|
||||
export class NotebookMarkdownRenderer {
|
||||
@@ -240,6 +241,10 @@ export class NotebookMarkdownRenderer {
|
||||
} else if (href.charAt(0) === '/') {
|
||||
return base.replace(/(:\/*[^/]*)[\s\S]*/, '$1') + href;
|
||||
} else if (href.slice(0, 2) === '..') {
|
||||
// we need to format invalid href formats (ex. ....\file to ..\..\file)
|
||||
// in order to resolve to an absolute link
|
||||
// Issue tracked here: https://github.com/markedjs/marked/issues/2135
|
||||
href = replaceInvalidLinkPath(href);
|
||||
return path.join(base, href);
|
||||
} else {
|
||||
return base + href;
|
||||
|
||||
Reference in New Issue
Block a user