Implement better markdown escaping and inline code escape (#23222)

Motivation for this is using markdown for keymap error notifications in
#23113, but it also benefits the copied text of repl tables.

Release Notes:

- N/A
This commit is contained in:
Michael Sloan 2025-01-16 04:06:57 -07:00 committed by GitHub
parent 5fdd7edb90
commit 8e6fc3c807
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 250 additions and 12 deletions

View file

@ -61,6 +61,7 @@ use serde_json::Value;
use settings::Settings;
use theme::ThemeSettings;
use ui::{div, prelude::*, v_flex, IntoElement, Styled};
use util::markdown::MarkdownString;
use crate::outputs::OutputContent;
@ -139,17 +140,6 @@ impl TableView {
}
}
fn escape_markdown(s: &str) -> String {
s.replace('|', "\\|")
.replace('*', "\\*")
.replace('_', "\\_")
.replace('`', "\\`")
.replace('[', "\\[")
.replace(']', "\\]")
.replace('<', "&lt;")
.replace('>', "&gt;")
}
fn create_clipboard_content(table: &TabularDataResource) -> String {
let data = match table.data.as_ref() {
Some(data) => data,
@ -180,7 +170,7 @@ impl TableView {
let row_content = schema
.fields
.iter()
.map(|field| Self::escape_markdown(&cell_content(record, &field.name)))
.map(|field| MarkdownString::escape(&cell_content(record, &field.name)).0)
.collect::<Vec<_>>();
row_content.join(" | ")