diff --git a/src/plugins/field_formats/common/content_types/html_content_type.ts b/src/plugins/field_formats/common/content_types/html_content_type.ts
index f1906ab3e68f7..22fbe81f1a69a 100644
--- a/src/plugins/field_formats/common/content_types/html_content_type.ts
+++ b/src/plugins/field_formats/common/content_types/html_content_type.ts
@@ -33,6 +33,7 @@ export const setup = (
htmlContextTypeConvert?: HtmlContextTypeConvert
): HtmlContextTypeConvert => {
const convert = getConvertFn(format, htmlContextTypeConvert);
+ const highlight = (text: string) => `${text}`;
const recurse: HtmlContextTypeConvert = (value, options = {}) => {
if (value == null) {
@@ -46,11 +47,23 @@ export const setup = (
const subValues = value.map((v: unknown) => recurse(v, options));
const useMultiLine = subValues.some((sub: string) => sub.indexOf('\n') > -1);
- return subValues.join(',' + (useMultiLine ? '\n' : ' '));
+ return subValues.join(highlight(',') + (useMultiLine ? '\n' : ' '));
};
const wrap: HtmlContextTypeConvert = (value, options) => {
- return recurse(value, options);
+ const convertedValue = recurse(value, options);
+
+ if (!Array.isArray(value) || value.length < 2) {
+ return convertedValue;
+ }
+
+ if (convertedValue.includes('\n')) {
+ const indentedValue = convertedValue.replaceAll(/(\n+)/g, '$1 ');
+
+ return highlight('[') + `\n ${indentedValue}\n` + highlight(']');
+ }
+
+ return highlight('[') + convertedValue + highlight(']');
};
return wrap;
diff --git a/src/plugins/field_formats/common/field_format.test.ts b/src/plugins/field_formats/common/field_format.test.ts
index 41c403d8055c7..2db6caca2c4c4 100644
--- a/src/plugins/field_formats/common/field_format.test.ts
+++ b/src/plugins/field_formats/common/field_format.test.ts
@@ -147,6 +147,35 @@ describe('FieldFormat class', () => {
expect(f.convert(['one', 'two', 'three'])).toBe('["one","two","three"]');
});
+
+ test('formats a list of values as html', () => {
+ const f = getTestFormat();
+
+ expect(f.convert([123, 456, 789], 'html')).toMatchInlineSnapshot(
+ `"[123, 456, 789]"`
+ );
+ });
+
+ test('formats a list of values containing newlines as html', () => {
+ const f = getTestFormat();
+ const newlineList = [
+ '{\n "foo": "bar",\n "fizz": "buzz"\n}',
+ '{\n "bar": "foo",\n "buzz": "fizz"\n}',
+ ];
+
+ expect(f.convert(newlineList, 'html')).toMatchInlineSnapshot(`
+ "[
+ {
+ "foo": "bar",
+ "fizz": "buzz"
+ },
+ {
+ "bar": "foo",
+ "buzz": "fizz"
+ }
+ ]"
+ `);
+ });
});
});
});
diff --git a/src/plugins/field_formats/public/index.scss b/src/plugins/field_formats/public/index.scss
index 7928d81b1f565..d3dffb385feeb 100644
--- a/src/plugins/field_formats/public/index.scss
+++ b/src/plugins/field_formats/public/index.scss
@@ -1 +1,2 @@
@import './lib/converters/index';
+@import './lib/content_types/index';
diff --git a/src/plugins/field_formats/public/lib/content_types/_html_content_type.scss b/src/plugins/field_formats/public/lib/content_types/_html_content_type.scss
new file mode 100644
index 0000000000000..244be673b4a4d
--- /dev/null
+++ b/src/plugins/field_formats/public/lib/content_types/_html_content_type.scss
@@ -0,0 +1,3 @@
+.ffArray__highlight {
+ color: $euiColorMediumShade;
+}
diff --git a/src/plugins/field_formats/public/lib/content_types/_index.scss b/src/plugins/field_formats/public/lib/content_types/_index.scss
new file mode 100644
index 0000000000000..e2fb515dd800f
--- /dev/null
+++ b/src/plugins/field_formats/public/lib/content_types/_index.scss
@@ -0,0 +1 @@
+@import './html_content_type';