I need to massage the rendered HTML on a page. The output from tasklists generated by Goldmark is problematic and there’s not a render hook for lists / list items.
I know it’s not possible to use block in an expression the way you can with partial. I’m curious what other strategies for this are? I’m currently using a partial within my layout template so I can operate on .Content directly, but I need to remember to use the partial in each layout template. Not the biggest deal, but makes me curious about a better approach.
I am pretty sure I am missing something in your issue. The mentioned badly rendered lists will not come out in your <head> section and not your surrounding markup won’t they? In that case the last three lines where you load .Content and then run them through a partial is exactly what you want to do (apart from a dedicated list-shortcode).
Sure, you need to repeat that for all layouts, but you could require a partial every where you output .Content.
There is the default construct, where you define a block location, and if it’s not defined in the subsequent runs you do something else… that’s probably the place to do something like this:
{{- block "content" . -}}
{{/* untested, the context could be different here */}}
{{- $content := .Content }}
{{- $content = partial "fixup-tasklists.html" .Content }}
{{- $content }}
{{- end -}}
If your layout has a {{ define “content” }} everything between start and end tag will be ignored/overridden.
The main issues is that they can’t be styled without :has() which is relatively new. There’s nothing on the <li> that tells you it’s a task list so you can disable the default list item marker. I’m targeting 5 years of browser support and :has() is only supported among the major browsers for about a year and even less for smaller browsers.
The reasons I want to style it are:
The alignment is wrong and doesn’t match other list types
Disabled inputs look bad with my color scheme on some browsers
Chrome has an accessibility callout for <input> elements without names or ids
Even GitHub has to massage the HTML output to be able to style task lists properly.