All files / src/processors debugViewProcessor.ts

92.68% Statements 38/41
42.85% Branches 3/7
100% Functions 5/5
92.68% Lines 38/41

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    5x   71x   71x 1x     1x       1x   1x 1x     1x 1x           71x         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        
import { Options } from '../options';
 
export class DebugViewProcessor {
	process(markdown: string, options: Options) {
		let output = markdown;
 
		if (options.showGrid) {
			markdown
				.split(new RegExp(options.separator, 'gmi'))
				.map((slidegroup, index) => {
					return slidegroup
						.split(new RegExp(options.verticalSeparator, 'gmi'))
						.map((slide, index) => {
 
							const [md, notes] = this.extractNotes(slide, options);
 
							let newSlide = this.addDebugCode(md);
							Iif (notes.length > 0) {
								newSlide += '\n\n' + notes;
							}
							output = output.replace(slide, newSlide);
							return newSlide;
						})
						.join(options.verticalSeparator);
				})
				.join(options.separator);
		}
		return output;
	}
 
	addDebugCode(markdown: string) {
 
		let gridBlock = '';
		gridBlock += '<grid drag="100 10" drop="0 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 10" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 20" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 30" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 40" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 50" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 60" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 70" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 80" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="100 10" drop="0 90" border="thin dotted blue"/>\n';
 
		gridBlock += '<grid drag="10 100" drop="0 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="10 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="20 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="30 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="40 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="50 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="60 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="70 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="80 0" border="thin dotted blue"/>\n';
		gridBlock += '<grid drag="10 100" drop="90 0" border="thin dotted blue"/>\n';
 
		return markdown + '\n' + gridBlock;
	}
 
	extractNotes(input: string, options: Options): [string, string] {
 
		let noteSeparator = 'note:';
		Iif (options.notesSeparator && options.notesSeparator.length > 0) {
			noteSeparator = options.notesSeparator;
		}
 
		const spliceIdx = input.indexOf(noteSeparator);
		Iif (spliceIdx > 0) {
			return [input.substring(0, spliceIdx), input.substring(spliceIdx)];
		} else {
			return [input, ''];
		}
	}
}