mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-27 03:54:24 +01:00
make internal variant of MarkedString be a string, #29076
This commit is contained in:
@@ -5,61 +5,27 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import { equals } from 'vs/base/common/arrays';
|
||||
|
||||
/**
|
||||
* MarkedString can be used to render human readable text. It is either a markdown string
|
||||
* or a code-block that provides a language and a code snippet. Note that
|
||||
* markdown strings will be sanitized - that means html will be escaped.
|
||||
*/
|
||||
export type MarkedString = string | { readonly language: string; readonly value: string };
|
||||
export type MarkedString = string;
|
||||
|
||||
export function markedStringsEquals(a: MarkedString | MarkedString[], b: MarkedString | MarkedString[]): boolean {
|
||||
if (!a && !b) {
|
||||
return true;
|
||||
}
|
||||
if (!a || !b) {
|
||||
} else if (!a || !b) {
|
||||
return false;
|
||||
} else if (typeof a === 'string' && typeof b === 'string') {
|
||||
return a === b;
|
||||
} else if (Array.isArray(a) && Array.isArray(b)) {
|
||||
return equals(a, b);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Array.isArray(a)) {
|
||||
if (!Array.isArray(b)) {
|
||||
return false;
|
||||
}
|
||||
return markedStringArrEquals(a, b);
|
||||
}
|
||||
return markedStringEqual(a, b as MarkedString);
|
||||
}
|
||||
|
||||
|
||||
function markedStringArrEquals(a: MarkedString[], b: MarkedString[]): boolean {
|
||||
let aLen = a.length,
|
||||
bLen = b.length;
|
||||
|
||||
if (aLen !== bLen) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < aLen; i++) {
|
||||
if (!markedStringEqual(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
function markedStringEqual(a: MarkedString, b: MarkedString): boolean {
|
||||
if (!a && !b) {
|
||||
return true;
|
||||
}
|
||||
if (!a || !b) {
|
||||
return false;
|
||||
}
|
||||
if (typeof a === 'string' || typeof b === 'string') {
|
||||
return typeof a === 'string' && typeof b === 'string' && a === b;
|
||||
}
|
||||
return (
|
||||
a.language === b.language
|
||||
&& a.value === b.value
|
||||
);
|
||||
}
|
||||
|
||||
export function textToMarkedString(text: string): MarkedString {
|
||||
|
||||
Reference in New Issue
Block a user