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 | 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 25x 25x 25x 25x 25x 25x 25x 27x 27x 27x 25x 25x 25x 25x 25x 25x 1x 1x 1x 106x 106x 106x 106x 1x 1x 1x 1x 27x 27x 27x 27x 27x 27x 1x 1x 27x 27x 27x 27x 27x 27x 27x 27x 1x 1x 204x 204x 204x 204x 204x 204x 204x 204x 204x 204x 141x 204x 204x 204x 43x 204x 204x 204x 12x 12x 44x 44x 44x 44x 12x 12x 204x 26x 25x 25x 204x 204x 204x 63x 63x 63x 39x 204x 204x 204x 204x 1x | /******************************************************************************* * Copyright bei * Entwicklungs- und Pflegeverbund für das gemeinsame Fachverfahren gefa * *******************************************************************************/ import { Component, Directive, Input, TemplateRef } from '@angular/core'; import { Typography } from '../../typography/typography.directive'; type FormattedTextSection = | { kind: 'p'; text: FormattedText }[] | { kind: 'plain'; text: FormattedText }; type FormattedText = ( | { kind: 'text'; text: string } | { kind: 'bold'; text: FormattedText } | { kind: 'italic'; text: FormattedText } | { kind: 'br' } | { kind: 'ul'; liArray: FormattedText[] } )[]; 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', ], standalone: false, }) export class TextFormatterComponent { /** * Sets data-gc-typography * Default: 'label' */ @Input() public typography: Typography = 'label'; /** * Input text in markdown format that will get converted and rendered */ @Input() public get markdownText(): string { return this._markdownText; } public set markdownText(newText: string) { this._markdownText = newText; this.formattedText = this.convertParagpraphs(newText); } /** @ignore */ protected formattedText: FormattedTextSection = []; /** @ignore */ private _markdownText = ''; /** @ignore */ protected isSections( v: FormattedTextSection, ): v is { kind: 'p'; text: FormattedText }[] { return Array.isArray(v); } /** @ignore */ private convertParagpraphs(text: string): FormattedTextSection { const trimmedText = text.trim(); const splitText = trimmedText.split(/\n{2,}/); if (splitText.length > 1) { const paragraphs: FormattedTextSection = []; splitText.forEach(s => paragraphs.push({ kind: 'p', text: this.convertEmptyLines(s), }), ); return paragraphs; } else { return { kind: 'plain', text: this.convertEmptyLines(trimmedText) }; } } 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( MDList.source + '|' + 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?.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 }); } else 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; } } |