Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [14.1.2] - 2026-09-15
### Fixed
- Set `position` and `size` on linkify text tokens so autolink highlights
map to the URL instead of the start of the block, #20.


## [14.1.1] - 2025-08-28
### Fixed
- Handle incorrect `pos`/`size` when `text_special` and `text_join` process
escaped links, #19.
- Restore ZWSP handling after the 14.1.0 merge.


## [14.1.0] - 2024-03-19
### Changed
- Updated CM spec compatibility to 0.31.2, #1009.
Expand Down Expand Up @@ -648,6 +661,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed presets folder (configs -> presets).


[14.1.2]: https://github.com/hackmdio/markdown-it/compare/b412edd7f252808f14ea03049cd04aebefc401a3...1ecb0cd2a2a4e8807d1b49e57e93cb84f55023fd
[14.1.1]: https://github.com/hackmdio/markdown-it/compare/6479bb4046afac05328c9d6a9ab6c1e714e444a1...b412edd7f252808f14ea03049cd04aebefc401a3
[14.1.0]: https://github.com/markdown-it/markdown-it/compare/14.0.0...14.1.0
[14.0.0]: https://github.com/markdown-it/markdown-it/compare/13.0.2...14.0.0
[13.0.2]: https://github.com/markdown-it/markdown-it/compare/13.0.1...13.0.2
Expand Down
42 changes: 42 additions & 0 deletions test/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,46 @@ describe('Annotation', function () {
assertTokenContent(src, tokens[28], 'Monde')
assertTokenContent(src, tokens[29], '|')
})

it('should annotate linkify text tokens with pos/size', function () {
const linkifyMd = require('../')({ linkify: true })
const src = 'See https://example.org/foo for details'
const tokens = linkifyMd.parse(src)
const children = tokens[1].children
const url = 'https://example.org/foo'

assert.strictEqual(children[0].type, 'text')
assert.strictEqual(children[0].content, 'See ')
assertTokenContent(src, children[0], 'See ')

assert.strictEqual(children[1].type, 'link_open')
assert.strictEqual(children[1].markup, 'linkify')

assert.strictEqual(children[2].type, 'text')
assert.strictEqual(children[2].content, url)
assert.strictEqual(children[2].position, 4)
assert.strictEqual(children[2].size, url.length)
assertTokenContent(src, children[2], url)

assert.strictEqual(children[3].type, 'link_close')
assert.strictEqual(children[4].content, ' for details')
assertTokenContent(src, children[4], ' for details')
})

it('should annotate multiple linkify text tokens in one block', function () {
const linkifyMd = require('../')({ linkify: true })
const src = 'text https://example.org/foo and https://hackmd.io/ more'
const tokens = linkifyMd.parse(src)
const children = tokens[1].children.filter(function (token) {
return token.type === 'text' && token.content.indexOf('http') === 0
})

assert.strictEqual(children.length, 2)
assert.strictEqual(children[0].position, 5)
assert.strictEqual(children[0].size, 'https://example.org/foo'.length)
assertTokenContent(src, children[0], 'https://example.org/foo')
assert.strictEqual(children[1].position, 33)
assert.strictEqual(children[1].size, 'https://hackmd.io/'.length)
assertTokenContent(src, children[1], 'https://hackmd.io/')
})
})