Implement custom format template interpolation for refbox citation display
This PR implements support for custom format templates in the refbox citation display, allowing users to define their own citation formats through metadata while maintaining backward compatibility.
Problem
The refbox display text was using a hardcoded format that couldn't be customized per item. Users needed the ability to define custom citation formats using metadata fields.
Solution
Modified the ClarinRefBoxController to support a new local.refbox.format metadata field that acts as a template string with variable interpolation:
- Template support: When
local.refbox.formatmetadata exists, it's used as a format template with variable substitution - Variable interpolation: Supports
{title},{authors},{pid},{repository},{year}, and{publisher}variables - Backward compatibility: When no custom format is present, uses the existing hardcoded format behavior
- Flexible formatting: Users can now create custom citation formats like
"{authors} ({year}). {title}. {publisher}. {repository}. {pid}"
Example Usage
Items with local.refbox.format metadata will use the custom template:
Metadata: local.refbox.format = "{authors}: {title} [{year}]"
Output: "John Doe: Sample Article [2024]"
Items without the metadata field will continue using the default format for backward compatibility.
Testing
Added comprehensive test cases covering:
- Custom format templates with all variables
- Partial variable usage in templates
- Default behavior when no template is present
Fixes #1229
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@kosarko 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.
I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.
@copilot the pull request should have been against the clarin-v7 branch. This branch contains the instructions. I have changed the PR merge base and I have forced push to copilot/fix-1229 to update this branch to clarin-v7. I've included your initial plan commit. Can you start again?
@copilot the pull request should have been against the clarin-v7 branch. This branch contains the instructions. I have changed the PR merge base and I have forced push to copilot/fix-1229 to update th...
I've fixed the refbox format interpolation issue. The problem was that when both authors and publisher existed, the publisher field was being ignored. Now the display text properly includes both fields separately.
Changes made in commit e385bb2:
- Modified
buildDisplayText()method to extract publisher as a separate field - Updated format to include publisher when both authors and publisher exist
- Maintained backward compatibility (publisher still acts as author fallback when no authors exist)
- Added comprehensive test case to verify the fix
The refbox format now correctly displays: {authors}, {year}, {title}, {publisher}, {repository}, {identifier} instead of missing the dc.publisher field.
@copilot I see that the issue description was too vague. You seem to have found the correct files to modify, but the intention was:
if there is a local.refbox.format metadata field, this field will contain something like a python fstring (string with variable names in curly braces such as {title}). This should be used rather than the hardcoded format/order currently implemented in buildDisplayText. The variables in the format string need to be interpolated. Possible variables are: title, authors, pid, repository, year, and publisher.
when local.refbox.format is not present the buildDisplayText should behave as it does now.
@copilot I see that the issue description was too vague. You seem to have found the correct files to modify, but the intention was:
if there is a
local.refbox.formatmetadata field, this field wi...
I've implemented the custom format template functionality as requested. The solution now checks for a local.refbox.format metadata field and uses it for string interpolation when present, falling back to the default hardcoded format when absent.
Changes made in commit upcoming:
- Modified
buildDisplayText()to check forlocal.refbox.formatmetadata - Added
buildDisplayTextFromTemplate()method for variable interpolation with support for: {title}, {authors}, {pid}, {repository}, {year}, {publisher} - Refactored existing logic into
buildDisplayTextDefault()to maintain backward compatibility - Added comprehensive test cases to verify both template and default behavior
The implementation supports all requested variables and maintains full backward compatibility when no template is provided.