This documentation is also published as Markdown for efficient machine reading: the whole site is indexed at /llms.txt, and every page has a clean Markdown copy under /_llms/. These are generated from the same source and cost far fewer tokens to read than this rendered HTML.

Skip to main content Skip to navigation

CodeBlockRenderingService Pennington.Markdown.Extensions

Shared rendering pipeline for fenced code blocks. Runs registered ICodeBlockPreprocessors first, falls back to HighlightingService on the base language, applies CodeTransformer, and wraps the result via CodeBlockHtmlBuilder. Used by both the Markdig renderer and the <CodeBlock> Razor component so markdown fences and Razor usages produce identical HTML.

Constructors

CodeBlockRenderingService

#
public CodeBlockRenderingService(HighlightingService highlightingService, IEnumerable<ICodeBlockPreprocessor> preprocessors = null)

Creates the service with a highlighting dispatcher and the registered preprocessors (ordered by descending priority at construction).

Parameters

highlightingService HighlightingService
preprocessors IEnumerable<ICodeBlockPreprocessor>

Methods

Render

#
public string Render(string code, string languageId, CodeHighlightRenderOptions options = null, bool isInTabGroup = false)

Renders code with language tag languageId through the full pipeline.

Parameters

code string
languageId string
options CodeHighlightRenderOptions
isInTabGroup bool

Returns

string

Pennington.Markdown.Extensions.CodeBlockRenderingService

namespace Pennington.Markdown.Extensions;

/// Shared rendering pipeline for fenced code blocks. Runs registered ICodeBlockPreprocessors first, falls back to HighlightingService on the base language, applies CodeTransformer, and wraps the result via CodeBlockHtmlBuilder. Used by both the Markdig renderer and the <CodeBlock> Razor component so markdown fences and Razor usages produce identical HTML.
public class CodeBlockRenderingService
{
    /// Creates the service with a highlighting dispatcher and the registered preprocessors (ordered by descending priority at construction).
    
public CodeBlockRenderingService(HighlightingService highlightingService, IEnumerable<ICodeBlockPreprocessor> preprocessors = null)
; /// Renders code with language tag languageId through the full pipeline.
public string Render(string code, string languageId, CodeHighlightRenderOptions options = null, bool isInTabGroup = false)
; }