Refactor Notebook Link Handling (#16473)

* add keep absolute paths instead convert setting

* update tests/config

* refactor links in NotebookLinkHandler
This commit is contained in:
Vasu Bhog
2021-07-30 19:20:38 -07:00
committed by GitHub
parent a7c1bcaf93
commit 179678b495
9 changed files with 427 additions and 200 deletions

View File

@@ -108,6 +108,8 @@ export class NotebookMarkdownRenderer {
return '<img ' + attributes.join(' ') + '>';
};
renderer.link = (href: string, title: string, text: string): string => {
// check for isAbsolute prior to escaping and replacement
let hrefAbsolute: boolean = path.isAbsolute(href);
href = this.cleanUrl(!markdown.isTrusted, notebookFolder, href);
if (href === null) {
return text;
@@ -120,7 +122,7 @@ export class NotebookMarkdownRenderer {
// only remove markdown escapes if it's a hyperlink, filepath usually can start with .{}_
// and the below function escapes them if it encounters in the path.
// dev note: using path.isAbsolute instead of isPathLocal since the latter accepts resolver (IRenderMime.IResolver) to check isLocal
if (!path.isAbsolute(href)) {
if (!hrefAbsolute) {
href = removeMarkdownEscapes(href);
}
if (
@@ -143,7 +145,7 @@ export class NotebookMarkdownRenderer {
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
return `<a href=${href} data-href="${href}" title="${title || href}">${text}</a>`;
return `<a href=${href} data-href="${href}" title="${title || href}" is-absolute=${hrefAbsolute}>${text}</a>`;
}
};
renderer.paragraph = (text): string => {