Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 28x 28x 28x 28x 28x 28x 28x 28x 28x 1x 1x 1x 45x 45x 45x 45x 45x 45x 13x 13x 13x 45x 45x 13x 13x 47x 47x 45x 47x 13x 13x 13x 13x 13x 13x 13x 13x 2x 45x 45x 45x 45x 45x 1x 1x 32x 32x 32x 32x 30x 30x 30x 30x 32x 32x 2x 2x 4x 4x 4x 2x 2x 2x 2x 32x 1x 1x 36x 36x 36x 36x 36x 36x 34x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 36x 1x 1x 215x 215x 215x 215x 215x 215x 163x 163x 52x 52x 52x 41x 52x 52x 24x 28x 28x 52x 52x 52x 52x 52x 52x 41x 52x 52x 52x 215x 1x | /*******************************************************************************
* Copyright bei
* Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa
*
*******************************************************************************/
import {
ChangeDetectionStrategy,
Component,
Directive,
TemplateRef,
computed,
input,
} from '@angular/core';
import { Typography } from '../../typography/typography.directive';
type FormattedTextSection = (
| { kind: 'p'; text: FormattedText }
| { kind: 'plain'; text: FormattedText }
| { kind: 'ul'; liArray: FormattedText[] }
)[];
type FormattedText = (
| { kind: 'text'; text: string }
| { kind: 'bold'; text: FormattedText }
| { kind: 'italic'; text: FormattedText }
| { kind: 'br' }
)[];
const MDList = /(?<list>^(?:\* .*\n*)+)/;
const MDBold = /\*\*(?<bold>\*.+?\*|.+?)\*\*/;
const MDItalic = /\*(?<italic>.+?)\*/;
const MDEmptyLine = /(?<br>\n(?!(\*\s.)))/;
interface FormattedTextContext {
$implicit: FormattedText;
}
interface FormattedSectionContext {
$implicit: FormattedTextSection;
}
/**
* Typeguard for the formatted text data structure
*/
@Directive({
selector: 'ng-template[data-gc-formatted-section]',
standalone: false,
})
export class SectionFormatterDirective {
constructor(public readonly template: TemplateRef<FormattedSectionContext>) {}
/**
* @ignore
*/
static ngTemplateContextGuard(
_dir: SectionFormatterDirective,
ctx: unknown,
): ctx is FormattedSectionContext {
return true;
}
}
/**
* Typeguard for the formatted text data structure
*/
@Directive({
selector: 'ng-template[data-gc-formatted-text]',
standalone: false,
})
export class TextFormatterDirective {
constructor(public readonly template: TemplateRef<FormattedTextContext>) {}
/**
* @ignore
*/
static ngTemplateContextGuard(
_dir: TextFormatterDirective,
ctx: unknown,
): ctx is FormattedTextContext {
return true;
}
}
/**
* Text formatter component that is used to convert a markdown text into HTML text
* Supported formats: bold text, italic text, unordered list (one level only)
*/
@Component({
selector: 'gc-text-formatter',
templateUrl: './text-formatter.component.html',
styleUrls: [
'../../utils/styles/reset-list.css',
'./text-formatter.component.css',
],
changeDetection: ChangeDetectionStrategy.Default,
standalone: false,
})
export class TextFormatterComponent {
/**
* Sets data-gc-typography
* Default: 'label'
*/
public typography = input<Typography>('label');
/**
* Input text in markdown format that will get converted and rendered
*/
public markdownText = input<string>('');
/** @ignore */
protected formattedText = computed(() =>
this.convertList(this.markdownText()),
);
private convertList(text: string): FormattedTextSection {
const mdReg = new RegExp(MDList.source, 'm');
const match: ReturnType<typeof mdReg.exec> = mdReg.exec(text);
if (match === null) {
return this.convertParagpraphs(text);
} else {
let parts: FormattedTextSection = [];
if (match.index > 0) {
parts = [...parts, ...this.convertList(text.slice(0, match.index))];
}
if (match.groups?.list) {
const enumList: FormattedText[] = [];
match[0].split('\n').forEach(line => {
const textonly = line.replace('* ', '').trim();
if (textonly.length > 0) {
enumList.push(this.convert(textonly));
}
});
parts.push({ kind: 'ul', liArray: enumList });
}
text = text.slice(match.index + match[0].length);
// store text following after the last match
if (text.length > 0) {
parts = [...parts, ...this.convertList(text)];
}
return parts;
}
}
private convertParagpraphs(text: string): FormattedTextSection {
const trimmedText = text.trim();
const splitText = trimmedText.split(/\n{2,}/);
if (splitText.length < 2) {
return [
{
kind: 'plain',
text: this.convertEmptyLines(trimmedText),
},
];
} else {
const paragraphs: FormattedTextSection = [];
splitText.forEach(s =>
paragraphs.push({
kind: 'p',
text: this.convertEmptyLines(s),
}),
);
return paragraphs;
}
}
private convertEmptyLines(text: string): FormattedText {
let parts: FormattedText = [];
const mdReg = new RegExp(MDEmptyLine.source, 'm');
const match: ReturnType<typeof mdReg.exec> = mdReg.exec(text);
if (match === null) {
return this.convert(text);
} else {
// store text before the first match
if (match.index > 0) {
parts = [...parts, ...this.convert(text.slice(0, match.index))];
}
if (match.groups?.br) {
parts.push({ kind: 'br' });
}
text = text.slice(match.index + match[0].length);
// store text following after the last match
if (text.length > 0) {
parts = [...parts, ...this.convertEmptyLines(text)];
}
}
return parts;
}
private convert(text: string): FormattedText {
let parts: FormattedText = [];
const mdReg = new RegExp(MDBold.source + '|' + MDItalic.source, 'm');
const match: ReturnType<typeof mdReg.exec> = mdReg.exec(text);
if (match === null) {
parts.push({ kind: 'text', text: text });
return parts;
} else {
// store text before the first match
if (match.index > 0) {
parts = [...parts, ...this.convert(text.slice(0, match.index))];
}
if (match.groups?.bold) {
parts.push({ kind: 'bold', text: this.convert(match.groups.bold) });
} else if (match.groups?.italic) {
parts.push({ kind: 'italic', text: this.convert(match.groups.italic) });
}
text = text.slice(match.index + match[0].length);
// store text following after the last match
if (text.length > 0) {
parts = [...parts, ...this.convert(text)];
}
}
return parts;
}
}
|