11'use strict' ;
22
3- var gemoji = require ( 'gemoji' ) . name ;
3+ var byName = require ( 'gemoji' ) . name ;
44
5- module . exports = plugin ;
5+ module . exports = gemoji ;
66
77var colon = ':' ;
88var own = { } . hasOwnProperty ;
99
10- function plugin ( ) {
11- var proto = this . Parser . prototype ;
12- var methods = proto . inlineMethods ;
10+ tokenize . locator = locate ;
1311
14- proto . inlineTokenizers . gemojiShortCode = tokenize ;
12+ function gemoji ( ) {
13+ var parser = this . Parser ;
14+ var proto ;
15+
16+ if ( ! isRemarkParser ( parser ) ) {
17+ throw new Error ( 'Missing parser to attach `remark-gemoji` to' ) ;
18+ }
19+
20+ proto = this . Parser . prototype ;
1521
16- methods . splice ( methods . indexOf ( 'strong' ) , 0 , 'gemojiShortCode' ) ;
22+ proto . inlineTokenizers . gemojiShortCode = tokenize ;
23+ proto . inlineMethods . splice ( proto . inlineMethods . indexOf ( 'strong' ) , 0 , 'gemojiShortCode' ) ;
1724}
1825
1926function tokenize ( eat , value , silent ) {
@@ -33,7 +40,7 @@ function tokenize(eat, value, silent) {
3340
3441 subvalue = value . slice ( 1 , pos ) ;
3542
36- if ( ! own . call ( gemoji , subvalue ) ) {
43+ if ( ! own . call ( byName , subvalue ) ) {
3744 return ;
3845 }
3946
@@ -48,14 +55,13 @@ function tokenize(eat, value, silent) {
4855 /* Eat a text-node. */
4956 subvalue = colon + subvalue + colon ;
5057
51- return eat ( subvalue ) ( {
52- type : 'text' ,
53- value : subvalue
54- } ) ;
58+ return eat ( subvalue ) ( { type : 'text' , value : subvalue } ) ;
5559}
5660
57- tokenize . locator = locate ;
58-
5961function locate ( value , fromIndex ) {
6062 return value . indexOf ( colon , fromIndex ) ;
6163}
64+
65+ function isRemarkParser ( parser ) {
66+ return Boolean ( parser && parser . prototype && parser . prototype . inlineTokenizers ) ;
67+ }
0 commit comments