Module Bushel.Md

Markdown processing with Bushel link extensions.

Bushel Markdown extensions and utilities

This module provides mappers to convert Bushel markdown extensions to different output formats. Bushel extends standard markdown with:

Two main mapper modes:

Sidenote Types

Sidenote data types for interactive previews on hover. These are defined here as Cmarkit inline extensions that can be generated by the sidenote mapper and rendered by the webserver.

type sidenote_data =
  1. | Contact_note of Sortal_schema.Contact.t * string
  2. | Paper_note of Bushel__.Bushel_paper.t * string
  3. | Idea_note of Bushel__.Bushel_idea.t * string
  4. | Note_note of Bushel__.Bushel_note.t * string
  5. | Project_note of Bushel__.Bushel_project.t * string
  6. | Video_note of Bushel__.Bushel_video.t * string
  7. | Footnote_note of string * Cmarkit.Block.t * string
type Cmarkit.Inline.t +=
  1. | Side_note of sidenote_data

Extensible inline for sidenotes

val is_bushel_slug : string -> bool
val is_tag_slug : string -> bool
val is_kind_slug : string -> bool
val is_contact_slug : string -> bool
val strip_handle : String.t -> String.t

Custom label resolver for Bushel links

Text Extraction

val text_of_inline : Cmarkit.Inline.t -> string
val image_target_is_bushel : Cmarkit.Inline.Link.t -> (string * Cmarkit.Block_line.tight list option * string) option

Plain Text Extraction

Strips bushel links from the AST and extracts plain text. Follows the same detection pattern as the sidenote and HTML mappers:

val inline_to_plain_text : Cmarkit.Inline.t -> string
val make_plain_text_mapper : ?contact_name:(String.t -> String.t option) -> unit -> Cmarkit.Mapper.t
val plain_text_of_markdown : ?contact_name:(String.t -> String.t option) -> string -> string

Sidenote Mapper

Creates sidenotes for Bushel links. Used for interactive previews on the main website.

Resolve link text: if it looks like a bushel slug, look up the entry title.

val make_sidenote_mapper : Bushel__.Bushel_entry.t -> 'a -> Cmarkit.Inline.t -> Cmarkit.Inline.t Cmarkit.Mapper.result
val make_bushel_inline_mapper : Bushel__.Bushel_entry.t -> 'a -> Cmarkit.Inline.t -> Cmarkit.Inline.t Cmarkit.Mapper.result

Alias for compatibility

Converts Bushel links to regular HTML links without sidenotes. Used for Atom feeds, RSS, search indexing.

Alias for compatibility

Slug Scanning

val scan_for_slugs : 'a -> string -> Cmarkit.Label.key list

Extract all links from markdown text, including from images

Extract external URLs from markdown content

First Image Extraction

val extract_first_image : string -> string option

Plaintext Conversion

val markdown_to_plaintext : 'a -> string -> string

Convert markdown text to plain text, resolving bushel links to just their text

Validation

val make_validation_mapper : Bushel__.Bushel_entry.t -> (Cmarkit.Label.key, unit) Hashtbl.t -> (Cmarkit.Label.key, unit) Hashtbl.t -> 'a -> Cmarkit.Inline.t -> 'b Cmarkit.Mapper.result

Validation mapper that collects broken references

val validate_references : Bushel__.Bushel_entry.t -> string -> Cmarkit.Label.key list * Cmarkit.Label.key list

Validate all bushel references in markdown and return broken ones

Markdown to Markdown Conversion

val make_to_markdown_mapper : ?base_url:string -> ?image_base:string -> Bushel__.Bushel_entry.t -> 'a -> Cmarkit.Inline.t -> Cmarkit.Inline.t Cmarkit.Mapper.result

Create a mapper that converts Bushel markdown to standard markdown.

This resolves:

  • :slug links to Title(URL)
  • @@handle to Name(best_url)
  • ##tag to tag(/tags/tag)
  • !:image-slug(caption) to !caption(/images/slug.webp)
val to_markdown : ?base_url:string -> ?image_base:string -> entries:Bushel__.Bushel_entry.t -> string -> string

Convert Bushel markdown to standard markdown.

  • parameter base_url

    Base URL prefix for entry links (default: "")

  • parameter image_base

    Base path for images (default: "/images")

  • parameter entries

    The entry collection for resolving links

  • parameter md

    The Bushel-flavored markdown text

  • returns

    Standard markdown with all Bushel extensions resolved

References

Reference extraction for CiTO annotations.

type reference_source =
  1. | Paper
    (*

    CitesAsSourceDocument

    *)
  2. | Note
    (*

    CitesAsRelated

    *)
  3. | External
    (*

    Cites

    *)

Reference source type for CiTO annotations

val note_references : Bushel__.Bushel_entry.t -> Sortal_schema.Contact.t -> Bushel__.Bushel_note.t -> (string * string * reference_source) list

Extract references (papers/notes with DOIs) from a note. Returns a list of (doi, citation_text, reference_source) tuples.

  • parameter entries

    The entry collection

  • parameter default_author

    The default author contact for notes without explicit author

  • parameter note

    The note to extract references from