-
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.
feat: add syntax highlighting into markdown code block (#5389)
- Loading branch information
Showing
110 changed files
with
917 additions
and
311 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
-387 Bytes
(99%)
...ive-cards-js-inputs-card-with-custom-style-options-and-submit-action-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
+192 Bytes
(100%)
...s-should-show-response-from-bot-and-no-text-from-user-on-messageback-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
+192 Bytes
(100%)
...s-js-should-show-response-from-bot-and-text-from-user-on-messageback-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
+201 Bytes
(100%)
...ions-js-should-show-response-from-bot-and-text-from-user-on-postback-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
+196 Bytes
(100%)
...ack-js-calling-send-message-back-should-send-a-message-back-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
+186 Bytes
(100%)
...post-back-js-calling-send-post-back-should-send-a-post-back-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
-2.08 KB
(96%)
...-accessibility-requirement-disabling-adaptive-card-with-inputs-field-3-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
-130 Bytes
(100%)
...-actions-shown-should-stick-to-bottom-if-submitting-an-adaptive-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
+250 Bytes
(100%)
...operties-with-no-locale-is-sent-should-get-hello-and-welcome-message-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
+405 Bytes
(100%)
...properties-with-locale-of-en-us-should-get-hello-and-welcome-message-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
+250 Bytes
(100%)
...ies-with-locale-of-invalid-type-should-get-hello-and-welcome-message-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
+399 Bytes
(100%)
...erties-with-non-existing-locale-should-get-hello-and-welcome-message-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
+399 Bytes
(100%)
...ties-with-non-iso-format-locale-should-get-hello-and-welcome-message-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
+404 Bytes
(100%)
...h-locale-of-zh-cn-should-get-hello-and-welcome-in-simplified-chinese-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
+96 Bytes
(100%)
...rd-actions-js-hero-card-actions-message-back-display-text-text-value-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
-646 Bytes
(98%)
...ots__/html/hero-card-actions-js-hero-card-actions-message-back-value-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
-643 Bytes
(98%)
...apshots__/html/hero-card-actions-js-hero-card-actions-post-back-json-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.
Binary file modified
BIN
+24.6 KB
(110%)
...lied-dark-theme-applied-side-by-side-left-transcript-right-codeblock-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
+24.9 KB
(110%)
...lied-dark-theme-applied-side-by-side-left-transcript-right-codeblock-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
-41.3 KB
(86%)
...lied-dark-theme-applied-side-by-side-left-transcript-right-codeblock-3-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
+61.6 KB
(130%)
...lied-dark-theme-applied-side-by-side-left-transcript-right-codeblock-4-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
+245 KB
...lied-dark-theme-applied-side-by-side-left-transcript-right-codeblock-5-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
+24.6 KB
(110%)
...dark-theme-applied-side-by-side-left-transcript-right-codeblock-dark-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
+24.8 KB
(110%)
...dark-theme-applied-side-by-side-left-transcript-right-codeblock-dark-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
-41.3 KB
(86%)
...dark-theme-applied-side-by-side-left-transcript-right-codeblock-dark-3-snap.png
Oops, something went wrong.
Binary file modified
BIN
+61.3 KB
(130%)
...dark-theme-applied-side-by-side-left-transcript-right-codeblock-dark-4-snap.png
Oops, something went wrong.
Binary file added
BIN
+245 KB
...dark-theme-applied-side-by-side-left-transcript-right-codeblock-dark-5-snap.png
Oops, something went wrong.
Binary file modified
BIN
+25.9 KB
(110%)
...js-fluent-theme-applied-side-by-side-left-transcript-right-codeblock-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+26.2 KB
(110%)
...js-fluent-theme-applied-side-by-side-left-transcript-right-codeblock-2-snap.png
Oops, something went wrong.
Binary file modified
BIN
-60.7 KB
(82%)
...js-fluent-theme-applied-side-by-side-left-transcript-right-codeblock-3-snap.png
Oops, something went wrong.
Binary file modified
BIN
+77.3 KB
(130%)
...js-fluent-theme-applied-side-by-side-left-transcript-right-codeblock-4-snap.png
Oops, something went wrong.
Binary file added
BIN
+273 KB
...js-fluent-theme-applied-side-by-side-left-transcript-right-codeblock-5-snap.png
Oops, something went wrong.
Binary file modified
BIN
+27.2 KB
(110%)
...uent-theme-applied-side-by-side-left-transcript-right-codeblock-dark-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
+26.4 KB
(110%)
...uent-theme-applied-side-by-side-left-transcript-right-codeblock-dark-2-snap.png
Oops, something went wrong.
Binary file modified
BIN
-59.2 KB
(82%)
...uent-theme-applied-side-by-side-left-transcript-right-codeblock-dark-3-snap.png
Oops, something went wrong.
Binary file modified
BIN
+76.4 KB
(130%)
...uent-theme-applied-side-by-side-left-transcript-right-codeblock-dark-4-snap.png
Oops, something went wrong.
Binary file added
BIN
+273 KB
...uent-theme-applied-side-by-side-left-transcript-right-codeblock-dark-5-snap.png
Oops, something went wrong.
Binary file modified
BIN
-4.33 KB
(97%)
...cript-activity-grouping-js-transcript-with-activity-grouping-test-43-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-1.13 KB
(100%)
...cript-activity-grouping-js-transcript-with-activity-grouping-test-44-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-6 KB
(95%)
...cript-activity-grouping-js-transcript-with-activity-grouping-test-45-1-snap.png
Oops, something went wrong.
Binary file modified
BIN
-13.3 KB
(93%)
...cript-activity-grouping-js-transcript-with-activity-grouping-test-46-1-snap.png
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
__tests__/html2/markdown/codeBlock/layout.code-block-dark.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,9 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<script> | ||
location = './layout?code-block-theme=github-dark-default'; | ||
</script> | ||
</head> | ||
<body></body> | ||
</html> |
Binary file added
BIN
+41.2 KB
__tests__/html2/markdown/codeBlock/layout.code-block-dark.html.snap-1.png
Oops, something went wrong.
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,68 @@ | ||
<!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> | ||
<template id="messages"> | ||
<x-message snapshot-ignore> | ||
```javascript | ||
console.log('JavaScript code block using tripple ` delimiters'); | ||
``` | ||
---- | ||
Code block using indent | ||
also has copy button | ||
but no highlighting</x-message> | ||
<x-message> | ||
```javascript | ||
export default function JavaScript(is, supported) { using shiki; } | ||
``` | ||
```typescript | ||
export default type TypeScript = (is, supported): { using: shiki; } | ||
``` | ||
```python | ||
def Python(is_supported): return {'using': 'shiki'} | ||
``` | ||
</x-message> | ||
</template> | ||
<main id="webchat"></main> | ||
<script> | ||
run(async function () { | ||
const { | ||
WebChat: { renderWebChat, testIds } | ||
} = window; // Imports in UMD fashion. | ||
|
||
const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
||
const params = new URLSearchParams(location.search); | ||
|
||
renderWebChat({ | ||
directLine, | ||
store, | ||
styleOptions: { | ||
codeBlockTheme: params.get('code-block-theme') ?? 'github-light-default' | ||
} | ||
}, document.getElementById('webchat')); | ||
|
||
await pageConditions.uiConnected(); | ||
|
||
/** @type {HTMLElement[]} */ | ||
const messages = Array.from(window.messages.content.querySelectorAll('x-message')) | ||
for (const message of messages) { | ||
await directLine.emulateIncomingActivity({ | ||
text: message.innerText, | ||
type: 'message' | ||
}); | ||
if (!message.hasAttribute('snapshot-ignore')) { | ||
await host.snapshot('local'); | ||
} | ||
await pageConditions.numActivitiesShown(messages.indexOf(message) + 1); | ||
} | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.
Binary file modified
BIN
+1.79 KB
(100%)
...sts__/html2/markdown/codeBlockCopyButton/adaptiveCards/behavior.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+1.66 KB
(100%)
...sts__/html2/markdown/codeBlockCopyButton/adaptiveCards/behavior.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+1.52 KB
(100%)
...sts__/html2/markdown/codeBlockCopyButton/adaptiveCards/behavior.html.snap-3.png
Oops, something went wrong.
Binary file modified
BIN
+1.64 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/adaptiveCards/layout.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+1.21 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/behavior.denied.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+1.19 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/behavior.denied.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+1.27 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/behavior.denied.html.snap-3.png
Oops, something went wrong.
115 changes: 115 additions & 0 deletions
115
__tests__/html2/markdown/codeBlockCopyButton/behavior.highlighted.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,115 @@ | ||
<!doctype html> | ||
<html lang="en-US"> | ||
<head> | ||
<link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
<script crossorigin="anonymous" src="https://unpkg.com/@babel/standalone/babel.min.js"></script> | ||
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script> | ||
<script crossorigin="anonymous" src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script> | ||
<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" style="position: relative;"></main> | ||
<script type="text/babel"> | ||
run(async function () { | ||
await host.sendDevToolsCommand('Browser.setPermission', { | ||
permission: { name: 'clipboard-write' }, | ||
setting: 'granted' | ||
}); | ||
|
||
await expect(navigator.permissions.query({ name: 'clipboard-write' })).resolves.toHaveProperty( | ||
'state', | ||
'granted' | ||
); | ||
|
||
const { | ||
ReactDOM: { render }, | ||
WebChat: { ReactWebChat, testIds } | ||
} = window; // Imports in UMD fashion. | ||
|
||
const { directLine, store } = testHelpers.createDirectLineEmulator(); | ||
|
||
const App = () => ( | ||
<React.Fragment> | ||
<ReactWebChat directLine={directLine} store={store} /> | ||
<div style={{ gap: 8, position: 'absolute', top: 0, width: '100%' }}> | ||
<label> | ||
<div>Paste box</div> | ||
<textarea | ||
data-testid="paste box" | ||
spellCheck={false} | ||
style={{ background: '#f0f0f0', border: 0, height: 100, padding: 0, resize: 'none', width: '100%' }} | ||
/> | ||
</label> | ||
</div> | ||
</React.Fragment> | ||
); | ||
|
||
render(<App />, document.getElementById('webchat')); | ||
|
||
await pageConditions.uiConnected(); | ||
|
||
await directLine.emulateIncomingActivity({ | ||
text: `Laboris ut proident dolore nisi sint ullamco proident veniam est. | ||
\`\`\`python | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
def plot_sine_waves(): | ||
"""Create a beautiful visualization of sine waves with different frequencies.""" | ||
# Generate time points | ||
t = np.linspace(0, 10, 1000) | ||
\`\`\` | ||
Ea sint elit anim enim voluptate aliquip aliqua nulla veniam. | ||
<pre><code>Ea et pariatur sint Lorem ex veniam adipisicing. | ||
Aliqua magna aliquip nisi quis. | ||
</code></pre> | ||
Cupidatat nulla duis dolor nulla ut pariatur minim incididunt quis adipisicing velit id Lorem.`, | ||
type: 'message' | ||
}); | ||
|
||
await pageConditions.numActivitiesShown(1); | ||
|
||
// WHEN: Focus on the "Copy" button via keyboard. | ||
await host.click(document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`)); | ||
await host.sendShiftTab(3); | ||
await host.sendKeys('ENTER'); | ||
|
||
// THEN: Should focus on the "Copy" button | ||
const copyButton = document.querySelector(`[data-testid="${WebChat.testIds.codeBlockCopyButton}"]`); | ||
|
||
expect(document.activeElement).toBe(copyButton); | ||
await host.snapshot('local'); | ||
|
||
// WHEN: Press ENTER on the "Copy" button. | ||
await host.sendKeys('ENTER'); | ||
|
||
// THEN: The copy button should change to "Copied". | ||
await host.snapshot('local'); | ||
|
||
// WHEN: Paste into plain text and rich text text box. | ||
await host.click(document.querySelector('[data-testid="paste box"]')); | ||
await host.sendKeys('+CONTROL', 'v', '-CONTROL'); | ||
|
||
await host.click(document.querySelector(`[data-testid="${WebChat.testIds.sendBoxTextBox}"]`)); | ||
|
||
// Sleep for 1 second for the checkmark to go away. | ||
await testHelpers.sleep(500); | ||
|
||
// WHEN: Hiding Web Chat and showing it back. | ||
document.getElementById('webchat').style.display = 'none'; | ||
document.body.offsetWidth; // Need for browser to refresh the layout. | ||
document.getElementById('webchat').style.display = ''; | ||
|
||
// THEN: The "Copy" button should kept at normal. | ||
await host.snapshot('local'); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
Binary file added
BIN
+51.5 KB
__tests__/html2/markdown/codeBlockCopyButton/behavior.highlighted.html.snap-1.png
Oops, something went wrong.
Binary file added
BIN
+51.5 KB
__tests__/html2/markdown/codeBlockCopyButton/behavior.highlighted.html.snap-2.png
Oops, something went wrong.
Binary file added
BIN
+58.2 KB
__tests__/html2/markdown/codeBlockCopyButton/behavior.highlighted.html.snap-3.png
Oops, something went wrong.
Binary file modified
BIN
+1.21 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/behavior.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+1.21 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/behavior.html.snap-2.png
Oops, something went wrong.
Binary file modified
BIN
+1.14 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/behavior.html.snap-3.png
Oops, something went wrong.
Binary file modified
BIN
-427 Bytes
(99%)
__tests__/html2/markdown/codeBlockCopyButton/fluent/layout.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+1.16 KB
(100%)
__tests__/html2/markdown/codeBlockCopyButton/layout.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+771 Bytes
(100%)
__tests__/html2/markdown/math/layout.spec.html.snap-1.png
Oops, something went wrong.
Binary file modified
BIN
+411 Bytes
(100%)
__tests__/html2/markdown/math/layout.spec.html.snap-2.png
Oops, something went wrong.
Oops, something went wrong.
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
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.