Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add render hooks passthroughs and blockquotes (with GitHub alert support) #12717

Merged
merged 3 commits into from
Aug 7, 2024

Conversation

bep
Copy link
Member

@bep bep commented Aug 5, 2024

Blockquote Hooks

// 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
}

Allows hook templates on the form:

  • render-blockquote.html
  • render-blockquote-alert.html (type)
  • render-blockquote-regular.html

Passthrough Hooks

// PassThroughContext is the context passed to a passthrough render hook.
type PassthroughContext interface {
	AttributesProvider
	text.Positioner
	PageProvider

	// 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
}

Allows hook templates on the form:

  • render-passthrough.html
  • render-passthrough-inline.html (type)
  • render-passthrough-block.html

Fixes #11927

@jmooring and others; comments? The blockquote API differs a little from your proposal. Having PlainText would be useful. but it seems that it hard to get some sensible plain text from markdown blocks, so that needs to wait; also, I have aimed for the least amount of new moving parts.

@bep bep force-pushed the feat/passthroughrenderhooks-11927 branch from 109f1d6 to 1a8c7d6 Compare August 5, 2024 14:20
@bep bep force-pushed the feat/passthroughrenderhooks-11927 branch from 1a8c7d6 to b003386 Compare August 5, 2024 18:30
@bep bep changed the title Add render hooks for inline and block passthrough snippets Add render hooks passthroughs and blockquotes (with GitHub alert support) Aug 5, 2024
@bep bep force-pushed the feat/passthroughrenderhooks-11927 branch 2 times, most recently from ea1af50 to b31826c Compare August 6, 2024 08:15
@jmooring
Copy link
Member

jmooring commented Aug 6, 2024

I've taken the blockquotes portion for a quick test drive (looks good), and will spend more time testing this evening.

@bep bep force-pushed the feat/passthroughrenderhooks-11927 branch from b31826c to 0cd4eea Compare August 6, 2024 15:10
@bep
Copy link
Member Author

bep commented Aug 6, 2024

@jmooring I just force pushed an update (which fixes the position handling)

@bep bep force-pushed the feat/passthroughrenderhooks-11927 branch 3 times, most recently from fd44d04 to bc6e724 Compare August 6, 2024 16:26
@bep bep force-pushed the feat/passthroughrenderhooks-11927 branch from bc6e724 to abfdb6c Compare August 6, 2024 17:14
@bep bep marked this pull request as ready for review August 6, 2024 17:54
@jmooring
Copy link
Member

jmooring commented Aug 7, 2024

LGTM

I've tested both hooks with various scenarios, and both are working great. I am working on the docs, and will probably finish by tomorrow evening.

@bep
Copy link
Member Author

bep commented Aug 7, 2024

Thanks, much appreciated. Ideally I would want the transform.ToMathML ready; else the passthrough hooks aren't of much obvious use. I have solved the technical bits, but I need to think about how to wire/configure it -- ideally I would want the wasm file(s) to live outside of the binary, but I may take a shortcut for the first release and mark it as "semi experimental".

@bep bep merged commit 665ac94 into gohugoio:master Aug 7, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create render hooks for inline and block passthrough snippets
2 participants