Skip to content

Shortcode templates #4

@mntn-xyz

Description

@mntn-xyz

Just wanted to put this out there for consideration... it would be helpful to have some kind of shortcode processing in gmnhg. Given the variety of shortcodes available, as well as the ability for people to define custom shortcodes, it would make sense to build this around the idea of user-defined templates.

Here's one approach:

  • Shortcode templates will be placed in a specified folder and must be named to match the desired shortcode (highlight.go would match the built-in {{< highlight >}} shortcode, and foo/bar.go would match {{< foo/bar >}}).
  • Before parsing with gomarkdown, input files are parsed for shortcodes. This process will have to take into account unpaired, paired, and self-closing shortcodes. The templates themselves will have to handle "nested" shortcodes; the parser will not bother with this. This should simplify parsing somewhat.
  • Each shortcode template presents a common method with arguments that represent both shortcode parameters (if any) and inner content (if any). The method should return the processed text for rendering.
  • Depending on whether the shortcode was called with {{% %}} (further rendering requested) or {{< >}} (present content without further rendering), the template output will either be inlined with the text and passed to gomarkdown, or it will be set aside for inclusion in the final rendered text as-is. The latter could be accomplished by replacing the template with some kind of temporary token like {{<1>}}, which will be replaced after rendering; there may be better approaches as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestgmnhgIssue related to cmd/gmnhgmajorRequires a major refactoring or rewritequestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions