/**
 * Script that will be used by the markdown_to_html Bazel rule in order to transform
 * multiple markdown files into the equivalent HTML output.
 */ import { readFileSync , writeFileSync } from 'fs' ; import * as marked from 'marked' ; import { join } from 'path' ; import { highlightCodeBlock } from '../highlight-files/highlight-code-block' ; import { DocsMarkdownRenderer } from './docs-marked-renderer' ; const markdownExtension = /.md$/ ; const markdownRenderer = new DocsMarkdownRenderer ( ) ; marked . setOptions ( { renderer : markdownRenderer , highlight : highlightCodeBlock } ) ; if ( require . main === module ) { const [ bazelBinPath , ... inputFiles ] = process . argv . slice ( 2 ) ; inputFiles . forEach ( inputPath => { const outputPath = join ( bazelBinPath , inputPath . replace ( markdownExtension , '.html' ) ) ; const htmlOutput = markdownRenderer . finalizeOutput ( marked ( readFileSync ( inputPath , 'utf8' ) ) ) ; writeFileSync ( outputPath , htmlOutput ) ; } ) ; }