mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Fix WYSIWYG text + image paste (#13542)
* Fix WYSIWYG text + image paste * add test for a link and text
This commit is contained in:
@@ -101,10 +101,11 @@ export class HTMLMarkdownConverter {
|
|||||||
const notebookFolder = this.notebookUri ? path.join(path.dirname(this.notebookUri.fsPath), path.sep) : '';
|
const notebookFolder = this.notebookUri ? path.join(path.dirname(this.notebookUri.fsPath), path.sep) : '';
|
||||||
let relativePath = findPathRelativeToContent(notebookFolder, notebookLink);
|
let relativePath = findPathRelativeToContent(notebookFolder, notebookLink);
|
||||||
node.innerText = escapeAngleBrackets(node.innerText);
|
node.innerText = escapeAngleBrackets(node.innerText);
|
||||||
|
content = escapeAngleBrackets(content);
|
||||||
if (relativePath) {
|
if (relativePath) {
|
||||||
return `[${node.innerText}](${relativePath})`;
|
return `[${node.innerText}](${relativePath})`;
|
||||||
}
|
}
|
||||||
return `[${node.innerText}](${node.href})`;
|
return `[${content}](${node.href})`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.turndownService.addRule('listItem', {
|
this.turndownService.addRule('listItem', {
|
||||||
@@ -137,14 +138,22 @@ export class HTMLMarkdownConverter {
|
|||||||
this.turndownService.addRule('p', {
|
this.turndownService.addRule('p', {
|
||||||
filter: 'p',
|
filter: 'p',
|
||||||
replacement: function (content, node) {
|
replacement: function (content, node) {
|
||||||
|
let isAnchorElement: boolean = false;
|
||||||
node.childNodes.forEach(c => {
|
node.childNodes.forEach(c => {
|
||||||
if (c.nodeType === Node.TEXT_NODE) {
|
if (c.nodeType === Node.TEXT_NODE) {
|
||||||
c.nodeValue = escapeAngleBrackets(c.textContent);
|
c.nodeValue = escapeAngleBrackets(c.textContent);
|
||||||
} else if (c.nodeType === Node.ELEMENT_NODE) {
|
} else if (c.nodeType === Node.ELEMENT_NODE) {
|
||||||
c.innerText = escapeAngleBrackets(c.textContent);
|
c.innerText = escapeAngleBrackets(c.textContent);
|
||||||
|
if (c.nodeName === 'A') {
|
||||||
|
isAnchorElement = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return '\n\n' + node.innerHTML.replace(/</gi, '<').replace(/>/gi, '>').replace(/ /gi, '') + '\n\n';
|
if (isAnchorElement) {
|
||||||
|
return content;
|
||||||
|
} else {
|
||||||
|
return '\n\n' + node.innerHTML.replace(/</gi, '<').replace(/>/gi, '>').replace(/ /gi, '') + '\n\n';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.turndownService.addRule('heading', {
|
this.turndownService.addRule('heading', {
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ suite('HTML Markdown Converter', function (): void {
|
|||||||
assert.equal(htmlMarkdownConverter.convert(htmlString), '[msft](https://www.microsoft.com/images/msft.png)', 'Basic https link test failed');
|
assert.equal(htmlMarkdownConverter.convert(htmlString), '[msft](https://www.microsoft.com/images/msft.png)', 'Basic https link test failed');
|
||||||
htmlString = '<a href="http://www.microsoft.com/images/msft.png">msft</a>';
|
htmlString = '<a href="http://www.microsoft.com/images/msft.png">msft</a>';
|
||||||
assert.equal(htmlMarkdownConverter.convert(htmlString), '[msft](http://www.microsoft.com/images/msft.png)', 'Basic http link test failed');
|
assert.equal(htmlMarkdownConverter.convert(htmlString), '[msft](http://www.microsoft.com/images/msft.png)', 'Basic http link test failed');
|
||||||
|
htmlString = 'Test <a href="http://www.microsoft.com/images/msft.png">msft</a>';
|
||||||
|
assert.equal(htmlMarkdownConverter.convert(htmlString), 'Test [msft](http://www.microsoft.com/images/msft.png)', 'Basic http link + text test failed');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Should transform <li> tags', () => {
|
test('Should transform <li> tags', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user