Skip to content

[Discover] Add “Copy as Markdown” option for selected results#245545

Merged
jughosta merged 15 commits intoelastic:mainfrom
jughosta:239689-copy-as-markdown
Dec 12, 2025
Merged

[Discover] Add “Copy as Markdown” option for selected results#245545
jughosta merged 15 commits intoelastic:mainfrom
jughosta:239689-copy-as-markdown

Conversation

@jughosta
Copy link
Contributor

@jughosta jughosta commented Dec 8, 2025

Summary

This PR adds support for copying rows of data in Markdown table format. Please help with testing for some edge cases in field values.

Screenshot 2025-12-08 at 16 52 55

Demo

Example of using the copied value on Github as a comment:
Screenshot 2025-12-08 at 16 55 46
Screenshot 2025-12-08 at 16 53 33

Checklist

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.
@jughosta jughosta self-assigned this Dec 8, 2025
@jughosta jughosta added release_note:enhancement backport:skip This PR does not require backporting Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// labels Dec 8, 2025
@jughosta jughosta marked this pull request as ready for review December 9, 2025 18:42
@jughosta jughosta requested review from a team as code owners December 9, 2025 18:42
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

Copy link
Contributor

@jbudz jbudz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/platform/test/moon.yml LGTM

Copy link
Contributor

@AlexGPlay AlexGPlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i did some testing around different special characters inside the tables and everything worked fine

Comment on lines 196 to 199
const escapedText = text.replace(/\|/g, '\\|').replace(/\n/g, ' ');
const start = isFirst ? '|' : ' |';
const end = isLast ? ' |' : '';
return `${start} ${escapedText}${end}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a 100% sure but i think the spaces are not mandatory between the content and the separators, so |a|, | a| or |a | are all the same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
In my opinion the readability of the copied output is better when it's with spaces.

Comment on lines 271 to 281
if (format === CopyAsTextFormat.tabular) {
expect(servicesMock.toastNotifications.addWarning).toHaveBeenCalledWith({
title: 'Copied to clipboard',
text: 'Values may contain formulas that are escaped.',
});
} else {
expect(servicesMock.toastNotifications.addWarning).not.toHaveBeenCalled();
expect(servicesMock.toastNotifications.addInfo).toHaveBeenCalledWith({
title: 'Copied to clipboard',
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: if we have conditions inside the test it might be better to just split them in 2 different ones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in fa4cce9

Copy link
Contributor

@PhilippeOberti PhilippeOberti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review only, LGTM for the @elastic/security-threat-hunting-investigations team

@jughosta jughosta enabled auto-merge (squash) December 12, 2025 07:55
@jughosta jughosta merged commit 267b863 into elastic:main Dec 12, 2025
12 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
cloudSecurityPosture 652.8KB 653.7KB +852.0B
discover 1.3MB 1.3MB +852.0B
esql 711.5KB 712.3KB +852.0B
esqlDataGrid 150.0KB 150.8KB +852.0B
securitySolution 11.2MB 11.2MB +852.0B
slo 994.5KB 995.4KB +855.0B
unifiedDocViewer 370.4KB 370.4KB +83.0B
total +5.1KB

History

cc @jughosta

@jughosta jughosta deleted the 239689-copy-as-markdown branch December 12, 2025 10:49
seanrathier pushed a commit to seanrathier/kibana that referenced this pull request Dec 15, 2025
…c#245545)

- Closes elastic#239689

## Summary

This PR adds support for copying rows of data in Markdown table format.
Please help with testing for some edge cases in field values.

<img width="1459" height="395" alt="Screenshot 2025-12-08 at 16 52 55"
src="https://github.com/user-attachments/assets/192e511e-82dc-478c-813f-441860fd2a06"
/>

### Demo
Example of using the copied value on Github as a comment: 
<img width="548" height="194" alt="Screenshot 2025-12-08 at 16 55 46"
src="https://github.com/user-attachments/assets/813deaeb-5c24-40c5-9835-35fd04a8dfbf"
/>
<img width="601" height="229" alt="Screenshot 2025-12-08 at 16 53 33"
src="https://github.com/user-attachments/assets/0b6e7668-ff7d-4390-9c6e-762bf8471494"
/>



### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
- [x] Review the [backport
guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)
and apply applicable `backport:*` labels.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting needs_docs release_note:enhancement Team:DataDiscovery Discover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t// v9.3.0

8 participants