markup: Add blockquote render hooks

Closes #12590
This commit is contained in:
Bjørn Erik Pedersen
2024-08-05 16:51:16 +02:00
parent 4c162deb03
commit 665ac949bd
9 changed files with 453 additions and 2 deletions

View File

@@ -78,6 +78,33 @@ type CodeblockContext interface {
Ordinal() int
}
// BlockquoteContext is the context passed to a blockquote render hook.
type BlockquoteContext interface {
AttributesProvider
text.Positioner
PageProvider
// Zero-based ordinal for all block quotes in the current document.
Ordinal() int
// The blockquote text.
// If type is "alert", this will be the alert text.
Text() hstring.RenderedString
/// Returns the blockquote type, one of "regular" and "alert".
// Type "alert" indicates that this is a GitHub type alert.
Type() string
// The GitHub alert type converted to lowercase, e.g. "note".
// Only set if Type is "alert".
AlertType() string
}
type PositionerSourceTargetProvider interface {
// For internal use.
PositionerSourceTarget() []byte
}
// PassThroughContext is the context passed to a passthrough render hook.
type PassthroughContext interface {
AttributesProvider
@@ -87,6 +114,9 @@ type PassthroughContext interface {
// Currently one of "inline" or "block".
Type() string
// The inner content of the passthrough element, excluding the delimiters.
Inner() string
// Zero-based ordinal for all passthrough elements in the document.
Ordinal() int
}
@@ -104,6 +134,10 @@ type CodeBlockRenderer interface {
RenderCodeblock(cctx context.Context, w hugio.FlexiWriter, ctx CodeblockContext) error
}
type BlockquoteRenderer interface {
RenderBlockquote(cctx context.Context, w hugio.FlexiWriter, ctx BlockquoteContext) error
}
type PassthroughRenderer interface {
RenderPassthrough(cctx context.Context, w io.Writer, ctx PassthroughContext) error
}
@@ -161,6 +195,7 @@ const (
HeadingRendererType
CodeBlockRendererType
PassthroughRendererType
BlockquoteRendererType
)
type GetRendererFunc func(t RendererType, id any) any