Class Code

java.lang.Object
io.mindspice.simplypages.core.HtmlTag
io.mindspice.simplypages.components.Code
All Implemented Interfaces:
Component

public class Code extends HtmlTag
Inline/code-block renderer with optional language and title metadata.

Mutable and not thread-safe. For block mode, markup is assembled lazily during render. Mutate within a request-scoped flow. For reuse, stop mutating and render as a stable structure with per-request slot/context values.

  • Method Details

    • inline

      public static Code inline(String code)
      Creates an inline code element.
      Parameters:
      code - the code text
    • block

      public static Code block(String code)
      Creates a code block element.
      Parameters:
      code - the code text
    • withLanguage

      public Code withLanguage(String language)
      Sets the programming language for syntax highlighting. This adds a language-specific class for syntax highlighters.
      Parameters:
      language - the language name (e.g., "java", "python", "javascript")
    • withTitle

      public Code withTitle(String title)
      Adds a title/filename to display above the code block.
      Parameters:
      title - the title or filename
    • withClass

      public Code withClass(String className)
      Description copied from class: HtmlTag
      Overrides:
      withClass in class HtmlTag
    • render

      public String render(RenderContext context)
      Description copied from class: HtmlTag
      Renders opening tag, text payload, child output, and closing tag.

      Security contract: slot and plain text are escaped; trusted HTML payload is emitted verbatim.

      Specified by:
      render in interface Component
      Overrides:
      render in class HtmlTag
      Parameters:
      context - context used for slot resolution and render policy
      Returns:
      rendered HTML for this component
    • render

      public String render()
      Description copied from interface: Component
      Renders this component with an empty context.
      Returns:
      rendered HTML for this component