Use MarkedString insetad of HTMLContentElement

This commit is contained in:
Martin Aeschlimann
2016-06-24 10:19:12 +02:00
parent 8b60f07f69
commit 51f2d539a6
24 changed files with 204 additions and 206 deletions

View File

@@ -5,11 +5,73 @@
'use strict';
/**
* 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 | { language: string; value: string };
export interface IHTMLContentElementCode {
language: string;
value: string;
}
export function markedStringsEquals(a:MarkedString | MarkedString[], b:MarkedString |MarkedString[]): boolean {
if (!a && !b) {
return true;
}
if (!a || !b) {
return false;
}
if (Array.isArray(a)) {
if (!Array.isArray(b)) {
return false;
}
return markedStringArrEquals(<MarkedString[]> a, <MarkedString[]> b);
}
return markedStringEqual(<MarkedString> a, <MarkedString> b);
}
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') {
return typeof b === 'string' && a === b;
}
return (
a['language'] === b['language']
&& a['value'] === b['value']
);
}
export function textToMarkedString(text: string) : MarkedString {
return { language: 'string', value: text };
}
export interface IHTMLContentElement {
/**
* supports **bold**, __italics__, and [[actions]]