metalsmith / metalsmith/markdown
Provide marked walkTokens option to help with relative markdown links
- Dominant language
- JavaScript
- Stars
- 62
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
*Please thumbs up :+1: this comment if you would like to use this feature, or thumbs down :-1: if you don't think it should be added . Your feedback is valued*
---
Various editors provide typehint support for linking to local files.
A function like below could help auto-transform source links to html permalinks.
````js
walkTokens(token) {
if (token.type === 'link') {
if (token.href.endsWith('index.md')) {
token.href = token.href.replace(/\index.md$/, '')
}
if (token.href.startsWith('.')) {
token.href = baseUrl + '/' + relative(metalsmith.source(), metalsmith.path('src',token.href)).replace(/\\/g, '/')
console.log(token)
}
}
}
````
To consider:
- need to resolve relative to linking page's __filename
- complications when the root of the repo !== metalsmith.directory
- complications when a path-transforming plugin like metalsmith/permalinks is used after the markdown conversion
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the plugin's markdown conversion entry point and examine how a marked walkTokens option could receive each link token. Review the listed edge cases: the linking page's filename, a repository root differing from metalsmith.directory, and later metalsmith/permalinks transformations. Done means relative markdown links can be transformed into correct HTML permalinks without breaking those cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100