Closed puzrin closed 9 years ago
I think the simplest solution is to ensure that the emoji's are surrounded by whitespace. (Or if an emoji follows an emoji.)
Resolved in master
@puzrin I think the solution in dd6a247f58ec96e508edfe83bc9d620587cce3f5 is still buggy.
e.g. :o
still conflicts with :octocat:
.
:+1: for @evaryont 's solution.
Thanks for info. I've created new ticket, sources of problems are different. \w
does not support unicode, and will be movement to wrong direction.
If anyone has time, he an try to write regex generator, as linkify-it
does.
e.g.
:o
still conflicts with:octocat:
.
@wizawu , I don't think it is. Here is the test I've come up with:
var md = require('markdown-it')()
var emoji = require('markdown-it-emoji')
md.use(emoji, {
defs: {
'octocat': 'B',
'ouch': 'A',
},
shortcuts: {
ouch: [ ':o' ]
}
})
console.log(md.render(':octocat:')
It'll produce B
, and never Actocat:
.
The reason is that when we build regexp, all emoticons get sorted, thus the resulting regexp would be /:octocat:|:o/
and not the other way around.
As far as I know, regexp matching engine returns leftmost match, so it would always work:
> /:octocat:|:o/.exec(':octocat:')
[ ':octocat:',
index: 0,
input: ':octocat:' ]
> /:o|:octocat:/.exec(':octocat:')
[ ':o',
index: 0,
input: ':octocat:' ]
Thus, no bug there.
@wizawu did you tested your example or not prior to report?
My case is rather simple.
var md = require('markdown-it')()
var emoji = require('markdown-it-emoji')
md.use(emoji)
console.log(md.render(':octocat:'))
The output is
<p>😮ctocat:</p>
The problem is not with the custom :o
shortcut. It is with the default :o
shortcut.
Need netter algorythm to avoid conflicts between shortcuts and text
:/
conflicts withhttp://
Ideas? Discuss.