@@ -46,75 +46,84 @@ export function setup(helper) {
4646 if ( opts . referencesEnabled ) {
4747 // TODO Make these configurable via config/settings.yml
4848 const refTypes = {
49- '^p(?:ackage)?:(.+)$' : {
50- class : 'ref-package' ,
51- url : m => `https://docs.doomemacs.org/-/package/#/${ m [ 1 ] } ` ,
52- text : m => m [ 1 ]
53- } ,
54- '^(?:(:[\\w-]+)(?: ([\\w-]+))(?: \\+([\\w-]+))?|\\+([\\w-]+))$' : {
55- class : 'ref-module' ,
56- url : m => {
57- let [ _ , cat , mod , flag , loneflag ] = m ;
58- if ( loneflag ) {
59- flag = loneflag ;
60- [ _ , cat , mod ] = window . location . pathname . match ( / \/ m o d u l e s \/ ( [ ^ \/ ] + ) \/ ( [ ^ \/ ] + ) \/ / ) ;
61- if ( ! ( cat && mod ) ) {
62- console . err ( `Couldn't resolve current module for [[${ flag } ]] link` ) ;
63- return ;
64- }
65- }
49+ '^(?:(:[\\w-]+)(?: ([\\w-]+))(?: \\+([\\w-]+))?|\\+([\\w-]+))(?:::(.*))?$' : m => {
50+ let [ _ , cat , mod , flag , loneflag , extra ] = m ;
51+ if ( loneflag ) {
52+ flag = loneflag ;
53+ [ _ , cat , mod ] = window . location . pathname . match ( / \/ m o d u l e s \/ ( [ ^ \/ ] + ) (?: \/ ( [ ^ \/ ] + ) \/ ) ? / ) || [ ] ;
54+ }
55+ if ( cat ) {
6656 const url = `${ cat } /${ mod } ` + ( flag ? `/#/description/module-flags/${ flag } ` : "" ) ;
67- return `https://docs.doomemacs.org/latest/modules/${ url } ` ;
68- } ,
69- text : m => m [ 0 ]
57+ const moduleLabel = cat ? [ `:${ cat } ` , mod , flag ] . join ( ' ' ) : null ;
58+ return {
59+ class : 'ref-module' ,
60+ href : `https://docs.doomemacs.org/latest/modules/${ url } ${ extra || '' } ` ,
61+ text : moduleLabel ,
62+ title : `Doom module documentation for ${ moduleLabel } `
63+ } ;
64+ }
65+ console . err ( `Couldn't resolve current module for [[${ flag } ]] link` ) ;
66+ return {
67+ class : 'ref-module' ,
68+ href : '#' ,
69+ text : "(couldn't find module)" ,
70+ title : "Couldn't find module"
71+ } ;
7072 } ,
71- '^fn:(.+)$' : {
73+ '^p(?:ackage|kg)?:(.+?)(?:::(.*))?$' : m => ( {
74+ class : 'ref-package' ,
75+ href : `https://docs.doomemacs.org/-/package/#/${ m [ 1 ] } ${ m [ 2 ] || '' } ` ,
76+ text : m [ 1 ] ,
77+ title : `Package documentation for ${ m [ 1 ] } `
78+ } ) ,
79+ '^fn:(.+?)(?:::(.*))?$' : m => ( {
7280 class : 'ref-fn' ,
73- url : m => `https://docs.doomemacs.org/-/function/${ m [ 1 ] } ` ,
74- text : m => m [ 1 ]
75- } ,
76- '^var:(.+)$' : {
81+ href : `https://docs.doomemacs.org/-/function/${ m [ 1 ] } ${ m [ 2 ] || '' } ` ,
82+ text : m [ 1 ] ,
83+ title : `Function documentation for ${ m [ 1 ] } `
84+ } ) ,
85+ '^var:(.+?)(?:::(.*))?$' : m => ( {
7786 class : 'ref-var' ,
78- url : m => `https://docs.doomemacs.org/-/var/${ m [ 1 ] } ` ,
79- text : m => m [ 1 ]
80- } ,
81- '^face:(.+)$' : {
87+ href : `https://docs.doomemacs.org/-/var/${ m [ 1 ] } ${ m [ 2 ] || '' } ` ,
88+ text : m [ 1 ] ,
89+ title : `Variable documentation for ${ m [ 1 ] } `
90+ } ) ,
91+ '^face:(.+?)(?:::(.*))?$' : m => ( {
8292 class : 'ref-face' ,
83- url : m => `https://docs.doomemacs.org/-/face/${ m [ 1 ] } ` ,
84- text : m => m [ 1 ]
85- } ,
86- '^(?:(?:([^/ ]+)/)?([^# ]+))?#([0-9]+)$' : {
87- class : 'ref-issue' ,
88- url : m => {
89- let [ user , repo ] = opts . defaultRepo ;
90- user = m [ 1 ] || user ;
91- repo = m [ 2 ] || repo ;
92- return `https://github.com/${ user } /${ repo } /issues/${ m [ 3 ] } ` ;
93- } ,
94- text : m => m [ 0 ]
93+ href : `https://docs.doomemacs.org/-/face/${ m [ 1 ] } ${ m [ 2 ] || '' } ` ,
94+ text : m [ 1 ] ,
95+ title : `Face documentation for ${ m [ 1 ] } `
96+ } ) ,
97+ '^(?:(?:([^/ ]+)/)?([^# ]+))?#([0-9]+)([#?].*)?$' : m => {
98+ let [ user , repo ] = opts . defaultRepo ;
99+ user = m [ 1 ] || user ;
100+ repo = m [ 2 ] || repo ;
101+ return {
102+ class : 'ref-issue' ,
103+ href : `https://github.com/${ user } /${ repo } /issues/${ m [ 3 ] } ${ m [ 4 ] || '' } ` ,
104+ text : m [ 0 ] ,
105+ title : "Github issue: ${user}/${repo}/#${m[3]}${m[4]}"
106+ } ;
95107 }
96108 } ;
97109 md . core . textPostProcess . ruler . push ( 'references' , {
98- matcher : / \[ \[ ( [ ^ \] \n ] + ) \] \] / ,
110+ matcher : / \[ \[ ( [ ^ \] \n ] + ) \] (?: \[ ( [ ^ \] \n ] + ) (?: " ( [ ^ " ] + ) " ) \] ) ? \] / ,
99111 onMatch : ( buffer , matches , state ) => {
100112 let result ;
101113 Object . keys ( refTypes ) . find ( re => {
102- let m = matches [ 1 ] . match ( new RegExp ( re ) ) ;
114+ const m = matches [ 1 ] . match ( new RegExp ( re ) ) ;
103115 if ( m ) {
104- let type = refTypes [ re ] ;
105- result = {
106- class : type . class ,
107- url : type . url ( m ) ,
108- text : type . text ( m )
109- } ;
110- if ( result . url ) {
111- return true ;
112- }
116+ result = refTypes [ re ] ( m ) ;
117+ result . text = result . text || matches [ 2 ] ;
118+ result . title = result . title || matches [ 3 ] || text ;
119+ return ! ! result . href ;
113120 }
114121 } ) ;
115122 if ( result ) {
116123 let token = new state . Token ( 'link_open' , 'a' , 1 ) ;
117- token . attrs = [ [ 'class' , result . class ] , [ 'href' , result . url ] ] ;
124+ token . attrs = [ [ 'class' , result . class ] ,
125+ [ 'href' , result . href ]
126+ [ 'title' , result . title ] ] ;
118127 buffer . push ( token ) ;
119128
120129 token = new state . Token ( 'text' , '' , 0 ) ;
@@ -170,13 +179,11 @@ export function setup(helper) {
170179 md . block . bbcode . ruler . push ( 'dump' , {
171180 tag : 'dump' ,
172181 replace : ( state , tag , content ) => {
173- state . push ( 'div_open' , 'pre' , 1 )
174- . attrs = [ [ 'class' , 'dump' ] ] ;
175- state . push ( 'div_open' , 'code' , 1 )
176- . attrs = [ [ 'data-encoded' , content ] ] ;
182+ state . push ( 'div_open' , 'div' , 1 )
183+ . attrs = [ [ 'class' , 'dump' ]
184+ [ 'data-encoded' , content ] ] ;
177185 state . push ( 'text' , '' , 0 ) . content = "Loading data dump..." ;
178- state . push ( 'div_close' , 'code' , - 1 ) ;
179- state . push ( 'div_close' , 'pre' , - 1 )
186+ state . push ( 'div_close' , 'div' , - 1 )
180187 return true ;
181188 }
182189 } ) ;
0 commit comments