Skip to content

Formatters

TypographyFormatter

Trek::TypographyFormatter applies French typography rules to strings and ProseMirror documents (only text nodes are modified):

  • non-breaking spaces before : ; ! ? % € $ » and after «, dashes,
  • non-breaking spaces before units (km, kg, h, min, °C…) and between digit groups
  • ..., ASCII apostrophes → typographic '
  • removes double spaces and spaces before periods/commas

Wire it to attributes with Formattable:

ruby
include Trek::Formattable
format_attributes Trek::TypographyFormatter, :title

ProseMirror → HTML pipeline

formatted_content (from Contentable) renders ProseMirror JSON to safe HTML through the prosemirror_to_html gem, extended with:

PieceRole
Nodes::ImageBlockrenders image_block nodes as figures (Shrine image, alt, caption, size)
Nodes::PromptsBlockrenders prompts_block nodes as call-to-action buttons
RemoveEmptyParagraphsFormatterstrips empty <p></p> tags
GlobalIdToLinksFormatterresolves gid:// references in links to real record URLs

The pipeline is orchestrated by the Prosemirror model — extend it with your own node renderers when you add custom blocks to the editor.

Released under the MIT License.