Package com.ericbouchut.learndev.course
Class MarkdownRenderer
java.lang.Object
com.ericbouchut.learndev.course.MarkdownRenderer
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).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordSanitized lesson HTML plus its table of contents (ADR-0018).static final recordOne TOC entry: minted anchor id, heading text, rendered level. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringCache key: SHA-256 of the source.static StringstripLeadingTitleHeading(String markdown, String title) Drops a leading level-1 heading whose text repeats the lesson title, so the common habit of starting a document with its title does not render as anh2duplicating the pageh1(see ADR-0014).
-
Constructor Details
-
MarkdownRenderer
public MarkdownRenderer()
-
-
Method Details
-
render
@Cacheable(cacheNames="renderedMarkdown", key="T(com.ericbouchut.learndev.course.MarkdownRenderer).cacheKey(#markdown)") public MarkdownRenderer.RenderedMarkdown render(String markdown) -
stripLeadingTitleHeading
Drops a leading level-1 heading whose text repeats the lesson title, so the common habit of starting a document with its title does not render as anh2duplicating the pageh1(see ADR-0014). Handles the ATX form (# Title, closing#s tolerated) and the setext form (Titleunderlined with=); the match is trimmed and case-insensitive. Callers apply this BEFORErender(String)so the render cache stays keyed by the exact rendered input; the stored Markdown is never modified. -
cacheKey
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.
-