Skip to main content

Overview

MarkdownTheme.Fonts defines the font styles used for rendering different markdown text elements. It provides separate font configurations for body text, code, headings, and text emphasis.

Declaration

public struct Fonts: Equatable

Properties

Text Fonts

body
UIFont / NSFont
The default font for body text.Default (iOS/visionOS): UIFont.preferredFont(forTextStyle: .body)Default (macOS): NSFont.systemFont(ofSize: NSFont.systemFontSize)
bold
UIFont / NSFont
Font used for bold text (strong emphasis).Default (iOS/visionOS): Bold variant of the body fontDefault (macOS): Bold variant of the system font
italic
UIFont / NSFont
Font used for italic text (emphasis).Default (iOS/visionOS): Italic variant of the body fontDefault (macOS): Italic variant of the system font

Code Fonts

codeInline
UIFont / NSFont
Font used for inline code spans within paragraphs.Default (iOS/visionOS): UIFont.monospacedSystemFont at body text sizeDefault (macOS): NSFont.monospacedSystemFont at system font size
code
UIFont / NSFont
Font used for code blocks.Default (iOS/visionOS): UIFont.monospacedSystemFont scaled by codeScale (0.85)Default (macOS): NSFont.monospacedSystemFont scaled by codeScale (0.85)Code blocks use a slightly smaller font size than body text by default.

Heading Fonts

largeTitle
UIFont / NSFont
Font used for large title headings (typically H1).Default (iOS/visionOS): Bold variant of the body fontDefault (macOS): Bold variant of the system font
title
UIFont / NSFont
Font used for title headings (typically H2-H6).Default (iOS/visionOS): Bold variant of the body fontDefault (macOS): Bold variant of the system font

Other Fonts

footnote
UIFont / NSFont
Font used for footnotes and small text.Default (iOS/visionOS): UIFont.preferredFont(forTextStyle: .footnote)Default (macOS): NSFont.systemFont(ofSize: NSFont.smallSystemFontSize)

Platform Types

  • iOS/visionOS: Uses UIFont from UIKit
  • macOS: Uses NSFont from AppKit

Example

var theme = MarkdownTheme()

// Customize body font
theme.fonts.body = UIFont.systemFont(ofSize: 17)

// Use custom monospace font for code
theme.fonts.code = UIFont(name: "Menlo", size: 14)!
theme.fonts.codeInline = UIFont(name: "Menlo", size: 17)!

// Customize heading fonts
theme.fonts.largeTitle = UIFont.boldSystemFont(ofSize: 28)
theme.fonts.title = UIFont.boldSystemFont(ofSize: 22)

Notes

  • All fonts default to system fonts with Dynamic Type support on iOS
  • Code fonts automatically use monospaced variants
  • The scaleFont(by:) method on MarkdownTheme adjusts all font sizes proportionally
  • The align(to:) method on MarkdownTheme sets all fonts to a base point size

Build docs developers (and LLMs) love