gemoire-1.0.1: yet another static gemlog generator + converter
Copyright(c) 2025 Sena
LicenseGPL-3.0-or-later
Maintainercontact@sena.pink
Stabilitystable
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Gemoire.Converter

Description

A tiny gemtext converter

Converting a Gemini capsule means substituting each gemtext element with a template in the desired syntax. The template syntax is detailed in Template. The document itself and each element in it have special formatting variables attached, which are, respectively:

  • Document - body and optional title
  • Paragraphs - text
  • Links - link and optional description
  • All headings - text
  • Quotes - text
  • Preformatted - text and optional alt
  • Lists themselves - items
  • List items - text

Additionally, the body text may be modified using RegEx rewrite rules. See RewriteRule.

The default configurations for HTML and Markdown can be found at Web and Markdown respectively, or, see the bottom of this module.

Synopsis

Configuration types

data Conversion Source #

A gemtext conversion recipe

See the module description for the variables available in each template.

Constructors

Conversion 

Fields

type RewriteRule = (String, String, String, Bool, Bool) Source #

A RegEx rewriting rule

The regular expressions must be POSIX extended variants, without the surrounding forward slashes. You can use \1 to get the substrings of matches for the replacement string. See Regex for more.

  • The first field is a RegEx matching the input filename in which the rewriting will occur.
  • The second field is the RegEx matching the string that will be replaced.
  • The third field is the replacement string.
  • The fourth field is whether the matching is multiline.
  • The fifth field is whether the matching is case sensitive.

Converters

convertCapsule :: Conversion -> FilePath -> FilePath -> IO () Source #

Convert a Gemini capsule using the configuration.

The files are scanned recursively, retaining the directory structure. Non-gemtext files will be copied without change, unless a rewrite rule applies on them. Gemtext files will be converted to the desired format with the target extension given in the configuration.

See the module description for more.

convertDocument Source #

Arguments

:: Values

Extra variable overrides

-> Conversion 
-> Text 
-> Text 

Convert the given gemtext document using the corresponding templates in the configuration.

See the module description for the special variables for each element and the document itself.

The extra variables are available only to the document template.

convertElement :: Conversion -> GemItem -> Text Source #

Convert a single GemItem element using the corresponding templates in the configuration.

See the module description for the special variables for each element.

Rewriting rules are not applied here.

Re-exported default conversions