Copyright | (c) 2025 Sena |
---|---|
License | GPL-3.0-or-later |
Maintainer | contact@sena.pink |
Stability | stable |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
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 optionaltitle
- Paragraphs -
text
- Links -
link
and optionaldescription
- All headings -
text
- Quotes -
text
- Preformatted -
text
and optionalalt
- 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
- data Conversion = Conversion {
- targetExtension :: !String
- escaper :: Text -> Text
- preEscaper :: Text -> Text
- attrEscaper :: Text -> Text
- documentTemplate :: Template
- textTemplate :: Template
- linkTemplate :: Template
- h1Template :: Template
- h2Template :: Template
- h3Template :: Template
- listTemplates :: (Template, Template)
- quoteTemplate :: Template
- preTemplate :: Template
- rewriteRules :: ![RewriteRule]
- conversionOverrides :: !Values
- type RewriteRule = (String, String, String, Bool, Bool)
- convertCapsule :: Conversion -> FilePath -> FilePath -> IO ()
- convertDocument :: Values -> Conversion -> Text -> Text
- convertElement :: Conversion -> GemItem -> Text
- defWebConversion :: Conversion
- defMarkdownConversion :: Conversion
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.
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.