Skip to content

Feature Request: Add source location (line/column) to shortcode context #2996

@colelawrence

Description

@colelawrence

Motivation

When building documentation sites with interactive features, it's valuable to link rendered content back to its source location for quick editing. Currently, shortcodes have access to page.relative_path, but lack line and column information about where the shortcode was invoked.

This prevents implementing "click-to-open-in-editor" functionality common in modern development tools.

Proposed Solution

Add source location metadata to the shortcode context:

{{ source.line }}      // Line number where shortcode starts (1-indexed)
{{ source.column }}    // Column number where shortcode starts (1-indexed)
{{ source.end_line }}  // Optional: line where shortcode ends
{{ source.end_column }}// Optional: column where shortcode ends

Use Case Example

Shortcode: templates/shortcodes/dev_link.html

<span data-source="{{ page.relative_path }}:{{ source.line }}:{{ source.column }}"> {{ body }} </span>

Markdown:

Some text here.

{% dev_link() %}
This content is on line 3
{% end %}

Rendered output:

<span data-source="content/blog/post.md:3:1"> This content is on line 3 </span>

This enables editor integration via vscode://file/path/to/content/blog/post.md:3:1 or similar protocols.

Additional Context

  • Similar to how template engines track error locations, this would expose that information to template authors
  • Particularly useful for documentation sites, technical blogs, and development workflows
  • Works well with existing nth variable for tracking invocation count

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions