zio.blocks.docs

package zio.blocks.docs

ZIO Blocks Markdown - A pure Scala GFM library.

This package provides a complete implementation of GitHub Flavored Markdown with a type-safe ADT, strict parser, renderer, and compile-time validated string interpolator.

==Quick Start==

 import zio.blocks.docs._

 // Parse markdown
 val doc = Parser.parse("# Hello *world*")

 // Render to string
 val md = Renderer.render(doc.toOption.get)

 // Use the interpolator
 val name = "World"
 val greeting = md"# Hello $$name"

==String Interpolator== The md interpolator validates markdown at compile time and supports interpolation of any type with a ToMarkdown instance.

 val title = "My Doc"
 val count = 42
 val doc = md"""
   # $$title

   There are $$count items.
 """

==Core Types==

  • Doc - A complete markdown document
  • Block - Block-level elements (headings, paragraphs, lists, etc.)
  • Inline - Inline elements (text, emphasis, links, etc.)
  • Parser - Strict GFM parser
  • Renderer - GFM renderer

==GFM Support== Supports all GitHub Flavored Markdown features including:

  • ATX headings, code blocks, thematic breaks
  • Block quotes, lists (ordered, unordered, task lists)
  • Tables with alignment
  • Inline formatting (emphasis, strong, strikethrough, code)
  • Links, images, autolinks
  • HTML blocks and inline HTML

Attributes

Members list

Type members

Classlikes

object Alignment

Attributes

Companion
trait
Source
Alignment.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Alignment.type
sealed trait Alignment extends Product, Serializable

Table column alignment in GFM tables.

Table column alignment in GFM tables.

Attributes

Companion
object
Source
Alignment.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
object Center
object Left
object None
object Right
final case class Autolink(url: String, isEmail: Boolean) extends Inline

An autolink ( or ).

An autolink ( or ).

Value parameters

isEmail

Whether this is an email autolink

url

The URL or email address

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed trait Block extends Product, Serializable

A block-level markdown element.

A block-level markdown element.

Blocks are the top-level structural elements in a markdown document, such as paragraphs, headings, code blocks, lists, and tables.

Attributes

Source
Block.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
class BlockQuote
class BulletList
class CodeBlock
class Heading
class HtmlBlock
class ListItem
class OrderedList
class Paragraph
class Table
object ThematicBreak
Show all
final case class BlockQuote(content: Chunk[Block]) extends Block

A block quote (> prefix).

A block quote (> prefix).

Value parameters

content

The blocks within the quote

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class BulletList(items: Chunk[ListItem], tight: Boolean) extends Block

An unordered list with bullet markers (-, *, or +).

An unordered list with bullet markers (-, *, or +).

Value parameters

items

The list items

tight

Whether the list is tight (no blank lines between items)

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Code(value: String) extends Inline

Inline code span (code).

Inline code span (code).

Value parameters

value

The code content

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class CodeBlock(info: Option[String], code: String) extends Block

A fenced code block.

A fenced code block.

Value parameters

code

The code content

info

Optional language/info string (e.g., "scala", "json")

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Doc(blocks: Chunk[Block], metadata: Map[String, String] = ...) extends Product, Serializable

A GitHub Flavored Markdown document.

A GitHub Flavored Markdown document.

Represents a complete GFM document as a sequence of block elements. Documents can be created by parsing markdown strings or constructed programmatically.

Value parameters

blocks

The sequence of block elements in the document

metadata

Optional metadata (reserved for future use)

Attributes

Example
 import zio.blocks.docs._ import zio.blocks.chunk.Chunk
// Parse from string val doc = Parser.parse("# Hello World")
// Construct programmatically val doc2 = Doc(Chunk( Heading(HeadingLevel.H1,
Chunk(Text("Hello World"))) )) 
Companion
object
Source
Doc.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Doc

Attributes

Companion
class
Source
Doc.scala
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Doc.type
final case class Emphasis(content: Chunk[Inline]) extends Inline

Emphasized text (text or text).

Emphasized text (text or text).

Value parameters

content

The inline elements to emphasize

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case object HardBreak extends Inline

A hard line break (two spaces or backslash before newline).

A hard line break (two spaces or backslash before newline).

Attributes

Source
Inline.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
HardBreak.type
final case class Heading(level: HeadingLevel, content: Chunk[Inline]) extends Block

An ATX-style heading (# to ######).

An ATX-style heading (# to ######).

Value parameters

content

The inline elements within the heading

level

The heading level (H1 to H6)

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed abstract class HeadingLevel(val value: Int) extends Product, Serializable

Heading level for ATX-style headings.

Heading level for ATX-style headings.

GFM supports six levels of headings, from H1 (# ) to H6 (###### ).

Value parameters

value

The numeric heading level (1-6)

Attributes

Companion
object
Source
HeadingLevel.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
object H1
object H2
object H3
object H4
object H5
object H6
Show all
object HeadingLevel

Attributes

Companion
class
Source
HeadingLevel.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
final case class HtmlBlock(content: String) extends Block

Raw HTML block content.

Raw HTML block content.

Value parameters

content

The HTML content

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class HtmlInline(content: String) extends Inline

Raw HTML inline content.

Raw HTML inline content.

Value parameters

content

The HTML content

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object HtmlRenderer

Renderer for HTML output.

Renderer for HTML output.

Converts markdown AST elements to HTML5-compliant HTML strings. Provides both full document rendering with DOCTYPE and head/body tags, and fragment rendering for embedding in existing HTML documents.

Attributes

Source
HtmlRenderer.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class Image(alt: String, url: String, title: Option[String]) extends Inline

An image.

An image.

Value parameters

alt

The alt text

title

Optional image title

url

The image URL

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Inline

Attributes

Companion
trait
Source
Inline.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Inline.type
sealed trait Inline extends Product, Serializable

An inline markdown element.

An inline markdown element.

Inline elements are the content within block elements, such as text, emphasis, links, and code spans.

Attributes

Companion
object
Source
Inline.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Known subtypes
class Autolink
class Code
class Emphasis
object HardBreak
class HtmlInline
class Image
class Autolink
class Code
class Emphasis
object HardBreak
class HtmlInline
class Image
class Link
object SoftBreak
class Strong
class Text
class Link
object SoftBreak
class Strong
class Text
Show all
final case class Link(text: Chunk[Inline], url: String, title: Option[String]) extends Inline

A hyperlink.

A hyperlink.

Value parameters

text

The link text

title

Optional link title

url

The link URL

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class ListItem(content: Chunk[Block], checked: Option[Boolean]) extends Block

A list item, which may be a task list item.

A list item, which may be a task list item.

Value parameters

checked

For task lists: Some(true) for [x], Some(false) for [ ], None for regular items

content

The blocks within the list item

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Source
MdInterpolator.scala
Supertypes
class Object
trait Matchable
class Any

Attributes

Source
MdInterpolatorRuntime.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class OrderedList(start: Int, items: Chunk[ListItem], tight: Boolean) extends Block

An ordered list with numeric markers (1., 2., etc.).

An ordered list with numeric markers (1., 2., etc.).

Value parameters

items

The list items

start

The starting number

tight

Whether the list is tight (no blank lines between items)

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Paragraph(content: Chunk[Inline]) extends Block

A paragraph containing inline content.

A paragraph containing inline content.

Value parameters

content

The inline elements within the paragraph

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class ParseError(message: String, line: Int, column: Int, input: String) extends Product, Serializable

A parse error with position information.

A parse error with position information.

Returned when the parser encounters invalid markdown syntax.

Value parameters

column

Column number where the error occurred (1-based)

input

The input line that caused the error

line

Line number where the error occurred (1-based)

message

Human-readable error message

Attributes

Source
ParseError.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Parser

Parser for GitHub Flavored Markdown.

Parser for GitHub Flavored Markdown.

Provides strict parsing of GFM documents, returning either a parsed Doc or a ParseError with position information.

==Supported Features==

  • ATX headings (# to ######)
  • Fenced code blocks (
 - Thematic breaks (---, ***, ___)
 - Block quotes (> prefix)
 - Bullet and ordered lists
 - Task lists (- [ ] and - [x])
 - Tables with alignment
 - Inline formatting (emphasis, strong, strikethrough, code)
 - Links and images
 - Autolinks
 - HTML blocks and inline HTML

==Not Supported==
 - YAML frontmatter (causes parse error)
 - Setext headings (use ATX style)
 - Indented code blocks (use fenced)
 - Link reference definitions

Attributes

Source
Parser.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Parser.type
object Renderer

Renderer for GitHub Flavored Markdown.

Renderer for GitHub Flavored Markdown.

Converts markdown AST elements back to GFM-compliant markdown strings. The rendered output can be re-parsed to produce an equivalent AST.

Attributes

Source
Renderer.scala
Supertypes
class Object
trait Matchable
class Any
Self type
Renderer.type
case object SoftBreak extends Inline

A soft line break (single newline).

A soft line break (single newline).

Attributes

Source
Inline.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
SoftBreak.type
final case class Strikethrough(content: Chunk[Inline]) extends Inline

Strikethrough text (text).

Strikethrough text (text).

Value parameters

content

The inline elements to strike through

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Strong(content: Chunk[Inline]) extends Inline

Strong/bold text (text or text).

Strong/bold text (text or text).

Value parameters

content

The inline elements to make strong

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class Table(header: TableRow, alignments: Chunk[Alignment], rows: Chunk[TableRow]) extends Block

A GFM table.

A GFM table.

Value parameters

alignments

Column alignments

header

The header row

rows

The data rows

Attributes

Source
Block.scala
Supertypes
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class TableRow(cells: Chunk[Chunk[Inline]]) extends Product, Serializable

A row in a GFM table.

A row in a GFM table.

Each cell contains a chunk of inline elements.

Value parameters

cells

The cells in the row, where each cell is a chunk of inline elements

Attributes

Source
TableRow.scala
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Renderer for ANSI terminal output.

Renderer for ANSI terminal output.

Converts markdown AST elements to colorful, formatted terminal output using ANSI escape codes. The output is designed to be readable on both light and dark terminal backgrounds.

Attributes

Source
TerminalRenderer.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class Text(value: String) extends Inline

Plain text content.

Plain text content.

Value parameters

value

The text string

Attributes

Source
Inline.scala
Supertypes
trait Inline
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case object ThematicBreak extends Block

A thematic break (---, ***, or ___).

A thematic break (---, ***, or ___).

Attributes

Source
Block.scala
Supertypes
trait Singleton
trait Product
trait Mirror
trait Block
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
Self type
object ToMarkdown

Attributes

Companion
trait
Source
ToMarkdown.scala
Supertypes
class Object
trait Matchable
class Any
Self type
ToMarkdown.type
trait ToMarkdown[-A]

Type class for converting values to markdown inline elements.

Type class for converting values to markdown inline elements.

Used by the md string interpolator to support interpolation of arbitrary types. Implement this trait for custom types to enable markdown interpolation.

Type parameters

A

The type to convert to markdown

Attributes

Example
 case class Person(name: String, age: Int)
implicit val personToMarkdown: ToMarkdown[Person] = (p: Person) =>
Strong(Chunk(Text(p.name)))
val person = Person("Alice", 30) val doc = md"# User: $$person" 
Companion
object
Source
ToMarkdown.scala
Supertypes
class Object
trait Matchable
class Any

Extensions

Inherited extensions

extension (inline sc: StringContext)
inline def md(inline args: Any*): Doc

Attributes

Inherited from:
MdInterpolator
Source
MdInterpolator.scala