-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Support HTML-in-Markdown (#5161)
* Added betterLinkDocumentMod * add markdownRenderHTML to styleOptions * Use new betterLinkDocumentMod and add a test * Fix asButton with aria-label and className * Update snapshots * Update entry * Use DOMParser + XMLSerializer * Revert red box * Update CHANGELOG.md * Update CHANGELOG.md Removes the redundant second changelog line * Add breaking changes * Run in JSDOM and remove empty "title" attribute * More explanation * Add HTML-in-Markdown for Adaptive Cards * Style HTML-in-Markdown for Adaptive Cards * Fix tests * Revert containerClassName * Move container to useRenderMarkdownAsHTML * Fix tests * Fix tests * Clean up * Add comment * Update entry * Fix tests * Added open in external icon * Add newline to end of XML serialization * Better test * Add HTML-in-Markdown --------- Co-authored-by: William Wong <[email protected]> Co-authored-by: Benjamin Yackley <[email protected]> Co-authored-by: Eugene Olonov <[email protected]>
- Loading branch information
1 parent
2b6e104
commit 84e32c9
Showing
58 changed files
with
1,377 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+274 Bytes
(100%)
__tests__/__image_snapshots__/chrome-docker/rich-cards-js-hero-card-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-95 Bytes
(100%)
...e-docker/style-options-js-style-options-hide-scroll-to-bottom-button-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-95 Bytes
(100%)
...e-docker/style-options-js-style-options-hide-scroll-to-bottom-button-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+40.9 KB
...ender-html-when-unset-should-render-sanitized-html-in-adaptive-cards-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+47.3 KB
...ender-html-when-unset-should-render-sanitized-html-in-citation-modal-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+41.2 KB
...der-html-when-unset-should-render-sanitized-html-in-message-activity-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+58 KB
...nder-html-when-set-to-false-should-not-render-html-in-adaptive-cards-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+71.5 KB
...nder-html-when-set-to-false-should-not-render-html-in-citation-modal-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+63.3 KB
...er-html-when-set-to-false-should-not-render-html-in-message-activity-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+249 Bytes
(100%)
...ceive-hero-card-click-on-scroll-to-end-button-should-focus-on-button-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+248 Bytes
(100%)
...ceive-hero-card-click-on-scroll-to-end-button-should-focus-on-button-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+288 Bytes
(100%)
...-text-message-click-on-scroll-to-end-button-should-focus-on-send-box-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+249 Bytes
(100%)
...-text-message-click-on-scroll-to-end-button-should-focus-on-send-box-2-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+273 Bytes
(100%)
...pshots__/html/markdown-hero-card-js-markdown-should-render-hero-card-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
...tton-tab-order-js-scroll-to-end-button-should-have-correct-tab-order-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
__tests__/html/markdownRenderHTML/default.adaptiveCards.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script crossorigin="anonymous" src="/test-harness.js"></script> | ||
<script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
</head> | ||
<body> | ||
<main id="webchat"></main> | ||
<script> | ||
run(async function () { | ||
const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
||
WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat')); | ||
|
||
await pageConditions.uiConnected(); | ||
|
||
await directLine.emulateIncomingActivity({ | ||
attachments: [ | ||
{ | ||
content: { | ||
type: 'AdaptiveCard', | ||
$schema: 'http://adaptivecards.io/schemas/adaptive-card.json', | ||
version: '1.5', | ||
body: [ | ||
{ | ||
style: 'heading', | ||
type: 'TextBlock', | ||
text: 'This is an Adaptive Card' | ||
}, | ||
{ | ||
type: 'TextBlock', | ||
text: atob( | ||
'IyMgSGVhZGVyCjxwPlRoaXMgaXMgc29tZSB0ZXh0IHdpdGggYSA8YSBocmVmPSJodHRwOi8vZXhhbXBsZS5jb20iIHRpdGxlPSJldmVuIGhhY2tlcnMgcmVzcGVjdCBhMTF5Ij5saW5rIGluIGl0PC9hPi4gQWxzbyA8c3Ryb25nPnNvbWUgdGV4dDwvc3Ryb25nPiA8ZW0+d2l0aCBmb3JtYXR0aW5nPC9lbT4uPC9wPgo8dWw+CjxsaT5Vbm9yZGVyZWQ8L2xpPgo8bGk+bGlzdDwvbGk+CjxsaT5pdGVtczwvbGk+CjwvdWw+CjxvbD4KPGxpPk9yZGVyZWQ8L2xpPgo8bGk+bGlzdDwvbGk+CjxsaT5pdGVtczwvbGk+Cjwvb2w+Cjx1bD4KPGxpPkJlbG93IGFyZSBzb21lIHVuc2FmZSB0aGluZ3MgdGhhdCBzaG91bGQgZ2V0IHNhbml0aXplZDoKPGxpPjxzY3JpcHQ+VGhpcyBpc24ndCBhbGxvd2VkITwvc2NyaXB0Pgo8bGk+PGltZyBzcmM9IiIgYWx0PSJJIGFtIGEgZHVtbXkgaW1hZ2UgdHJ5aW5nIHRvIGhhY2sgeW91IiBvbmVycm9yPWFsZXJ0KDEpIC8+CjxsaT48c3ZnIGFyaWEtbGFiZWw9Im1hbGljaW91cyBzdmcgaGVyZSI+PGcvb25sb2FkPWFsZXJ0KDIpLy88cD4KPGxpPjxwPmFiYzxpZnJhbWUvL3NyYz1qQXZhJlRhYjtzY3JpcHQ6YWxlcnQoMyk+ZGVmPC9wPgo8bGk+PG1hdGg+PG1pLy94bGluazpocmVmPSJkYXRhOngsPHNjcmlwdD5hbGVydCg0KTwvc2NyaXB0Pgo8bGk+CjwvdWw+' | ||
), | ||
wrap: true | ||
} | ||
], | ||
actions: [ | ||
{ | ||
type: 'Action.Submit', | ||
title: 'Submit card' | ||
} | ||
] | ||
}, | ||
contentType: 'application/vnd.microsoft.card.adaptive' | ||
} | ||
], | ||
type: 'message' | ||
}); | ||
|
||
await pageConditions.numActivitiesShown(1); | ||
|
||
const [firstActivityElement] = pageElements.activities(); | ||
|
||
const link = firstActivityElement.querySelector('[href="http://example.com"]'); | ||
const linkImage = link.querySelector('.webchat__render-markdown__external-link-icon'); | ||
|
||
expect(link.getAttribute('aria-label')).toBe('link in it Opens in a new window; external.'); | ||
expect(link.getAttribute('target')).toBe('_blank'); | ||
expect(link.getAttribute('rel')).toBe('noopener noreferrer'); | ||
expect(linkImage.title).toBe('Opens in a new window; external.'); | ||
|
||
await host.snapshot(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ | ||
|
||
describe('markdownRenderHTML when unset', () => { | ||
test('should render sanitized HTML in Adaptive Cards', () => runHTML('markdownRenderHTML/default.adaptiveCards')); | ||
}); |
105 changes: 105 additions & 0 deletions
105
__tests__/html/markdownRenderHTML/default.citationModal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script crossorigin="anonymous" src="/test-harness.js"></script> | ||
<script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
</head> | ||
<body> | ||
<main id="webchat"></main> | ||
<script> | ||
run(async function () { | ||
const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
||
WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat')); | ||
|
||
await pageConditions.uiConnected(); | ||
|
||
await directLine.emulateIncomingActivity({ | ||
entities: [ | ||
{ | ||
'@context': 'https://schema.org', | ||
'@id': '', | ||
'@type': 'Message', | ||
citation: [ | ||
{ | ||
'@type': 'Claim', | ||
appearance: { | ||
'@type': 'DigitalDocument', | ||
url: 'https://example.com/1/', | ||
usageInfo: { | ||
'@id': '_:1', | ||
'@type': 'CreativeWork', | ||
description: | ||
'Nisi quis ut sint elit est nulla enim eiusmod. Deserunt commodo pariatur nostrud culpa aliquip esse pariatur exercitation nulla do proident. Est qui eiusmod aliquip deserunt labore consequat fugiat. Ullamco reprehenderit nostrud eiusmod nisi nulla esse id. Reprehenderit aliqua quis consectetur sit cupidatat fugiat Lorem ex labore. Eiusmod velit laborum quis tempor incididunt excepteur culpa esse nulla.', | ||
keywords: ['encrypted-content'], | ||
name: 'Sit veniam do irure velit est et quis ut Lorem reprehenderit commodo cillum occaecat', | ||
pattern: { | ||
'@type': 'DefinedTerm', | ||
inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/', | ||
name: 'color', | ||
termCode: 'orange' | ||
} | ||
} | ||
}, | ||
position: 1 | ||
}, | ||
{ | ||
'@type': 'Claim', | ||
appearance: { | ||
'@type': 'DigitalDocument', | ||
text: 'Incididunt amet dolore anim commodo fugiat occaecat elit nulla do consequat. Quis incididunt occaecat labore adipisicing. Cillum sunt velit consequat irure ipsum ullamco sint ea aute. Sunt et eu ut enim aliqua cupidatat non adipisicing dolore commodo dolor magna enim. Commodo reprehenderit excepteur ad nostrud ex id aliquip deserunt eiusmod. Esse non labore nulla voluptate.', | ||
usageInfo: { | ||
'@type': 'CreativeWork', | ||
name: 'Velit exercitation', | ||
pattern: { | ||
'@type': 'DefinedTerm', | ||
inDefinedTermSet: 'https://www.w3.org/TR/css-color-4/', | ||
name: 'color', | ||
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 'https://schema.org/Message', | ||
usageInfo: { '@id': '_:1' } | ||
} | ||
], | ||
text: 'Ipsum[1] dolore[2] cupidatat[3] magna[4] consectetur[5] do tempor est excepteur.\n\n[1]: https://example.com/1/ "Sint amet id officia dolor ex eiusmod ipsum ipsum magna fugiat"\n[2]: https://example.com/2/ "Laboris cupidatat voluptate"\n[3]: _:3 "Velit nulla culpa eu ea consectetur consectetur dolore velit"\n[4]: _:4 "Adipisicing enim nulla"\n[5]: https://example.com/5', | ||
type: 'message' | ||
}); | ||
|
||
const [firstActivityElement] = pageElements.activities(); | ||
|
||
const linkDefinitions = firstActivityElement.querySelectorAll('.webchat__link-definitions__list-item'); | ||
|
||
expect(linkDefinitions).toHaveProperty('length', 5); | ||
|
||
linkDefinitions[3].querySelector('button').click(); | ||
|
||
const link = document.querySelector('dialog [href="http://example.com"]'); | ||
const linkImage = link.querySelector('.webchat__render-markdown__external-link-icon'); | ||
|
||
expect(link.getAttribute('aria-label')).toBe('link in it Opens in a new window; external.'); | ||
expect(link.getAttribute('target')).toBe('_blank'); | ||
expect(link.getAttribute('rel')).toBe('noopener noreferrer'); | ||
expect(linkImage.title).toBe('Opens in a new window; external.'); | ||
|
||
await host.snapshot(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ | ||
|
||
describe('markdownRenderHTML when unset', () => { | ||
test('should render sanitized HTML in citation modal', () => runHTML('markdownRenderHTML/default.citationModal')); | ||
}); |
42 changes: 42 additions & 0 deletions
42
__tests__/html/markdownRenderHTML/default.messageActivity.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script crossorigin="anonymous" src="/test-harness.js"></script> | ||
<script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script> | ||
</head> | ||
<body> | ||
<main id="webchat"></main> | ||
<script> | ||
run(async function () { | ||
const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
||
WebChat.renderWebChat({ directLine, store }, document.getElementById('webchat')); | ||
|
||
await pageConditions.uiConnected(); | ||
|
||
await directLine.emulateIncomingActivity({ | ||
text: atob( | ||
'IyMgSGVhZGVyCjxwPlRoaXMgaXMgc29tZSB0ZXh0IHdpdGggYSA8YSBocmVmPSJodHRwOi8vZXhhbXBsZS5jb20iIHRpdGxlPSJldmVuIGhhY2tlcnMgcmVzcGVjdCBhMTF5Ij5saW5rIGluIGl0PC9hPi4gQWxzbyA8c3Ryb25nPnNvbWUgdGV4dDwvc3Ryb25nPiA8ZW0+d2l0aCBmb3JtYXR0aW5nPC9lbT4uPC9wPgo8dWw+CjxsaT5Vbm9yZGVyZWQ8L2xpPgo8bGk+bGlzdDwvbGk+CjxsaT5pdGVtczwvbGk+CjwvdWw+CjxvbD4KPGxpPk9yZGVyZWQ8L2xpPgo8bGk+bGlzdDwvbGk+CjxsaT5pdGVtczwvbGk+Cjwvb2w+Cjx1bD4KPGxpPkJlbG93IGFyZSBzb21lIHVuc2FmZSB0aGluZ3MgdGhhdCBzaG91bGQgZ2V0IHNhbml0aXplZDoKPGxpPjxzY3JpcHQ+VGhpcyBpc24ndCBhbGxvd2VkITwvc2NyaXB0Pgo8bGk+PGltZyBzcmM9IiIgYWx0PSJJIGFtIGEgZHVtbXkgaW1hZ2UgdHJ5aW5nIHRvIGhhY2sgeW91IiBvbmVycm9yPWFsZXJ0KDEpIC8+CjxsaT48c3ZnIGFyaWEtbGFiZWw9Im1hbGljaW91cyBzdmcgaGVyZSI+PGcvb25sb2FkPWFsZXJ0KDIpLy88cD4KPGxpPjxwPmFiYzxpZnJhbWUvL3NyYz1qQXZhJlRhYjtzY3JpcHQ6YWxlcnQoMyk+ZGVmPC9wPgo8bGk+PG1hdGg+PG1pLy94bGluazpocmVmPSJkYXRhOngsPHNjcmlwdD5hbGVydCg0KTwvc2NyaXB0Pgo8bGk+CjwvdWw+' | ||
), | ||
type: 'message' | ||
}); | ||
|
||
await pageConditions.numActivitiesShown(1); | ||
|
||
const [firstActivityElement] = pageElements.activities(); | ||
|
||
const link = firstActivityElement.querySelector('[href="http://example.com"]'); | ||
const linkImage = link.querySelector('.webchat__render-markdown__external-link-icon'); | ||
|
||
expect(link.getAttribute('aria-label')).toBe('link in it Opens in a new window; external.'); | ||
expect(link.getAttribute('target')).toBe('_blank'); | ||
expect(link.getAttribute('rel')).toBe('noopener noreferrer'); | ||
expect(linkImage.title).toBe('Opens in a new window; external.'); | ||
|
||
await host.snapshot(); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @jest-environment ./packages/test/harness/src/host/jest/WebDriverEnvironment.js */ | ||
|
||
describe('markdownRenderHTML when unset', () => { | ||
test('should render sanitized HTML in message activity', () => runHTML('markdownRenderHTML/default.messageActivity')); | ||
}); |
Oops, something went wrong.