diff --git a/packages/openscd/src/finder-list.ts b/packages/openscd/src/finder-list.ts index f4bcfcf5c..a98582e53 100644 --- a/packages/openscd/src/finder-list.ts +++ b/packages/openscd/src/finder-list.ts @@ -91,9 +91,6 @@ export class FinderList extends LitElement { return path.join('/'); } - getDisplayString(entry: string, path: string[]): string { - return entry; - } @query('div') container!: Element; @@ -153,9 +150,11 @@ export class FinderList extends LitElement { html` JSON.stringify(p)) + .map(p => { + return JSON.stringify(p) + }) .includes(JSON.stringify(path.concat(entry)))} - >${this.getDisplayString(entry, path)}${entry}` )} `; diff --git a/packages/plugins/src/menu/Help.ts b/packages/plugins/src/menu/Help.ts index e5b9ef26a..d4514a6cd 100644 --- a/packages/plugins/src/menu/Help.ts +++ b/packages/plugins/src/menu/Help.ts @@ -9,6 +9,10 @@ import { newWizardEvent, Wizard } from '@openscd/open-scd/src/foundation.js'; import { openSCDIcon } from '@openscd/open-scd/src/icons/icons.js'; import { Directory } from '@openscd/open-scd/src/finder-list.js'; +const GITHUB_WIKI_LINK_PATTERN = /https:\/\/github\.com\/openscd\/open-scd\/wiki\/([^)]*)/g; +const MD_LINK_TITLE_PATTERN =/[^\\]]*/; +const HYPHEN_PATTERN = /-/g; + function aboutBox(version: string) { return html`
@@ -43,19 +47,22 @@ async function getLinkedPages(path: string[]): Promise { } const page = path[path.length - 1].replace(/ /g, '-'); - const res = await fetch(`/public/md/${page}.md`); + const res = await fetch(`/openscd/public/md/${page}.md`); const md = await res.text(); + const MD_LINK_REPLACEMENT = `$1` const unlinkedMd = md.replace( - /\[([^\]]*)\]\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g, - `$1` + new RegExp(`\\[(${MD_LINK_TITLE_PATTERN.source})\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'), + MD_LINK_REPLACEMENT ); + const header = html`
${page === 'Home' ? aboutBox(edition.version) : html``} ${unsafeHTML(marked.parse(unlinkedMd))}
`; const entries = Array.from( - md.matchAll(/\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g) - ).map(([_, child]) => child.replace(/-/g, ' ')); + md.matchAll( new RegExp(`\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g')) + + ).map(([_, child]) => child.replace(HYPHEN_PATTERN, ' ')); return { path, header, entries }; }