All files / app/components Markdown.tsx

81.81% Statements 9/11
100% Branches 0/0
33.33% Functions 1/3
100% Lines 8/8

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 2513x   13x       13x   13x       137x 137x     822x           137x    
import dynamic from "next/dynamic";
 
const Markdown = dynamic(() => import("components/MarkdownNoSSR"), {
  ssr: false,
});
 
export default Markdown;
 
export function increaseMarkdownHeaderLevel(
  source: string,
  topHeaderLevel: number
) {
  let convertedSource = source;
  for (let i = 6; i >= 1; i--) {
    //loop through each header level, and add extra # as necessary
    //also put a ~ in front so we know that line is done
    convertedSource = convertedSource.replace(
      new RegExp(`^${"#".repeat(i)}`, "gm"),
      `~${"#".repeat(Math.min(i + topHeaderLevel - 1, 6))}`
    );
  }
  //take out the ~ markers (line start only)
  return convertedSource.replace(/^~#/gm, "#");
}