course-renderer
Version:
Manages CA School Courses file system storage and HTML conversion
28 lines (22 loc) • 713 B
text/typescript
/**
* @module PathSanitizer
*/
import * as path from 'path';
import Token from '../markdown/Token'
/**
* sanitizer - Sanitizes the path's on the rendered HTML attribute values. This is to hide the internal file system structure on the HTML.
*/
export function pathSanitize(tokens: Token[], courseName: string, chapter: string) {
return sanitizeChapter(tokens, chapter)
}
function sanitizeChapter(tokens: Token[], chapter: string): Token[] {
tokens.forEach((token) => {
if (token.children instanceof Array) {
token.chapter = chapter
sanitizeChapter(token.children, chapter)
} else {
token.chapter = chapter
}
})
return tokens
}