All files / src/processors skipSlideProcessor.ts

93.75% Statements 15/16
50% Branches 2/4
100% Functions 4/4
93.75% Lines 15/16

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 385x     5x 71x   71x     71x   71x     98x       99x   99x 11x 11x   11x       99x 99x         71x      
import { CommentParser } from 'src/comment';
import { Options } from '../options';
 
export class SkipSlideProcessor {
	private slideCommentRegex = /<!--\s*(?:\.)?slide.*-->/;
 
	private parser = new CommentParser();
 
	process(markdown: string, options: Options) {
		let output = markdown;
 
		markdown
			.split(new RegExp(options.separator, 'gmi'))
			.map((slidegroup, index) => {
				return slidegroup
					.split(new RegExp(options.verticalSeparator, 'gmi'))
					.map((slide) => {
 
						let newSlide = slide;
 
						if (this.slideCommentRegex.test(slide)) {
							const [match] = this.slideCommentRegex.exec(slide);
							const comment = this.parser.parseLine(match);
 
							Iif (comment.hasAttribute("skip") && comment.getAttribute("skip") == "true") {
								newSlide = '<!-- slide data-visibility="hidden" -->';
							}
						}
						output = output.replace(slide, newSlide);
						return newSlide;
					})
					.join(options.verticalSeparator);
			})
			.join(options.separator);
		return output;
	}
}