INNER CODE UNIT · TypeScript

readHtmlFileFromPath

philschmid/clipper.js · src/utils.ts:4

export function readHtmlFileFromPath(path: string): string {
  const html = readFileSync(path, 'utf8');
  return html;
}

export function writeMarkdownToFile(markdown: string | Record<"markdown", string>[], output: string) {
  // check if markdown is array if yes loop over it an save 1 file per element
  if (Array.isArray(markdown)) {
    markdown.forEach((md, i) => {
      // check if outout is a markdown file else remove extension and add .md
      const outputFileName = output.replace(/\.[^/.]+$/, "") + `_${i}.md`
      // write markdown to file
      writeFileSync(outputFileName, md.markdown)
    })
  } else {
    // check if outout is a markdown file else remove extension and add .md
    const outputFileName = output.replace(/\.[^/.]+$/, "") + '.md'
    // write markdown to file

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…