twostraws / Ignite

A static site generator for Swift developers.
MIT License
984 stars 34 forks source link

Feature Request: Hooks to patch in alternate Components for Markdown tags. #5

Open fbartho opened 1 month ago

fbartho commented 1 month ago

Purpose

When working on with Markdown, there are sometimes alternate dialects that you'd like to handle. These might simply be as simple as the language-tags on code-blocks, as complicated as custom sorting tools for Markdown Tables, and often these are project specific tweaks that wouldn't be appropriate to merge into the core Ignite library.

Proposed Implementation

In this module, there are a ton of visit* methods that each render raw html. https://github.com/twostraws/Ignite/blob/main/Sources/Ignite/Rendering/MarkdownToHTML.swift

It'd be great if there was a mapping step, where instead of directly emitting strings, users could hook full Ignite components.

// Current Implementation
func visitOrderedList(_ orderedList: Markdown.OrderedList) -> String {
  var result = "<ol>"

  for listItem in orderedList.listItems {
    result += visit(listItem)
  }

  result += "</ol>"
  return result
}

// Instead:
func visitOrderedList(_ orderedList: Markdown.OrderedList) -> Element {
  return (tagOverrides.OrderedList ?? MarkdownOrderedList)(listItems: visit(orderedList.listItems))
}
// Where tagOverrides obviously needs some way to be populated by the project -- ideally even allowing for different patches in different content directories.

Note: I think this should emit Element instead of String to allow these components to play nice with #3 and #2 -- Otherwise Markdown pages wouldn't be able to have a hypothetical AutomaticOutline static-component.

Alternatives Considered