markdown_ex

package module
v0.0.0-...-006cb5a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2023 License: MIT Imports: 14 Imported by: 0

README

caddy-markdown-ex

This module adds a template function markdown_ex to caddy (v2) which can be used with the templates directive. markdown_ex uses a custom markdown renderer that, in addition to the default markdown renderer (template function markdown)

  • adds the html class "task-list-item" for items of a TaskList to add an easy style option via CSS to disable the normal list-style-type and use the checkbox instead like this:

    .task-list-item {
      list-style-type: none;
    }
    
    .task-list-item input {
      margin: 0 .2em .25em -1.6em;
      vertical-align: middle;
    }
    

    which results in lists like this: (the github renderer should support this 😅)

    • not checked
    • checked
    • also not checked

    instead of looking like this with caddy's default renderer

      • not checked
      • checked
      • also not checked
  • support for mermaidJS syntax by using goldmark-mermaid

Installation

xcaddy build --with github.com/ueffel/caddy-markdown-ex

The latest version of this module needs caddy v2.7.6 or above.

Configuration

As of https://github.com/caddyserver/caddy/pull/5939 to use a new template function it needs to be configured as extension.

templates {
    extensions {
        markdown_ex
    }
}

Mermaid support needs a javascript file in order to render the diagrams client-side. This script is loaded by default from https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js

There is the option to change the source path of this script to serve the file from your own domain with the following in a Caddyfile:

templates {
    extensions {
        markdown_ex {
            mermaid_js /mermaid.min.js
        }
    }
}

The file then should be available @ https://[[your.domain]]/mermaid.min.js. For example by a file_server route:

[your.domain] {
    file_server /mermaid.min.js {
        root /var/www/html
    }
}

Usage

Use the template function markdown_ex instead of markdown to render your markdown within the template. See templates directive

Note

I created this module just for myself but feel free to use it.

You can also fork the repository and configure your own markdown renderer to your liking in unmarshalCaddyfile. The goldmark renderer, which is used by this module and caddy's default markdown function, has excellent extensibility.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MarkdownEx

type MarkdownEx struct {
	MermaidJS string `json:"mermaid_js"`
	// contains filtered or unexported fields
}

MarkdownEx exposes the template function "markdown_ex" which uses a custom markdown renderer that includes

  • the html class "task-list-item" for item if a TaskList
  • support for mermaidJS syntax

func (MarkdownEx) CaddyModule

func (MarkdownEx) CaddyModule() caddy.ModuleInfo

CaddyModule returns the Caddy module information.

func (*MarkdownEx) CustomTemplateFunctions

func (m *MarkdownEx) CustomTemplateFunctions() template.FuncMap

CustomTemplateFunctions should return the mapping from custom function names to implementations. markdown_ex uses a custom markdown renderer that includes

  • the html class "task-list-item" for items of a TaskList
  • support for mermaidJS syntax

func (*MarkdownEx) Provision

func (m *MarkdownEx) Provision(ctx caddy.Context) error

func (*MarkdownEx) UnmarshalCaddyfile

func (m *MarkdownEx) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL