@@ -9,6 +9,10 @@ import { newWizardEvent, Wizard } from '@openscd/open-scd/src/foundation.js';
9
9
import { openSCDIcon } from '@openscd/open-scd/src/icons/icons.js' ;
10
10
import { Directory } from '@openscd/open-scd/src/finder-list.js' ;
11
11
12
+ const GITHUB_WIKI_LINK_PATTERN = / h t t p s : \/ \/ g i t h u b \. c o m \/ o p e n s c d \/ o p e n - s c d \/ w i k i \/ ( [ ^ ) ] * ) / g;
13
+ const MD_LINK_TITLE_PATTERN = '([^\\]]*)' ;
14
+ const HYPHEN_PATTERN = / - / g;
15
+
12
16
function aboutBox ( version : string ) {
13
17
return html `< div >
14
18
< div style ="display:flex ">
@@ -43,19 +47,22 @@ async function getLinkedPages(path: string[]): Promise<Directory> {
43
47
}
44
48
45
49
const page = path [ path . length - 1 ] . replace ( / / g, '-' ) ;
46
- const res = await fetch ( `/public/md/${ page } .md` ) ;
50
+ const res = await fetch ( `/openscd/ public/md/${ page } .md` ) ;
47
51
const md = await res . text ( ) ;
52
+ const MD_LINK_REPLACEMENT = `<a style="cursor: help; color: var(--mdc-theme-primary)" href="https://github.com/openscd/open-scd/wiki/$2" target="_blank" >$1</a>`
48
53
const unlinkedMd = md . replace (
49
- / \[ ( [ ^ \] ] * ) \] \( h t t p s : .. g i t h u b . c o m . o p e n s c d . o p e n - s c d . w i k i . ( [ ^ ) ] * ) \) / g ,
50
- `<a style="cursor: help;" onclick="Array.from(event.target.closest('section').lastElementChild.children).find(child => child.text === '$2'.replace(/-/g, ' ')).click()">$1</a>`
54
+ new RegExp ( `\\[ ${ MD_LINK_TITLE_PATTERN } \ \]\\( ${ GITHUB_WIKI_LINK_PATTERN . source } \\)` , 'g' ) ,
55
+ MD_LINK_REPLACEMENT
51
56
) ;
57
+
52
58
const header = html `< div style ="padding: 8px; ">
53
59
${ page === 'Home' ? aboutBox ( edition . version ) : html `` }
54
60
${ unsafeHTML ( marked . parse ( unlinkedMd ) ) }
55
61
</ div > ` ;
56
62
const entries = Array . from (
57
- md . matchAll ( / \( h t t p s : ..g i t h u b .c o m .o p e n s c d .o p e n - s c d .w i k i .( [ ^ ) ] * ) \) / g)
58
- ) . map ( ( [ _ , child ] ) => child . replace ( / - / g, ' ' ) ) ;
63
+ md . matchAll ( new RegExp ( `\\(${ GITHUB_WIKI_LINK_PATTERN . source } \\)` , 'g' ) )
64
+
65
+ ) . map ( ( [ _ , child ] ) => child . replace ( HYPHEN_PATTERN , ' ' ) ) ;
59
66
60
67
return { path, header, entries } ;
61
68
}
0 commit comments