Class MarkdownRenderer

java.lang.Object
com.ericbouchut.learndev.course.MarkdownRenderer

@Service public class MarkdownRenderer extends Object
Converts lesson Markdown to HTML that is safe to serve.

Lesson content is instructor input and CommonMark passes raw HTML through, so the rendered output is sanitized against an allowlist: no script, event handler, or frame survives, whatever the Markdown contains. Results are cached by the SHA-256 of the source, so a lesson is rendered once per content version (see ADR-0013 in docs/adr/).

Markdown headings are demoted one level (# becomes h2, capped at h6): the lesson page already provides the single h1 (the lesson title), and one h1 per page with no skipped level is an RGAA 9.1 commitment (see ADR-0014 and docs/rgaa.md).

  • Constructor Details

    • MarkdownRenderer

      public MarkdownRenderer()
  • Method Details

    • render

      @Cacheable(cacheNames="renderedMarkdown", key="T(com.ericbouchut.learndev.course.MarkdownRenderer).cacheKey(#markdown)") public String render(String markdown)
    • cacheKey

      public static String cacheKey(String markdown)
      Cache key: SHA-256 of the source. Content-addressed, so edited content is a new key and stale entries cannot exist; the fixed-size key also avoids holding whole lesson sources in the cache's key set.