Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX]: Fix error Help page linking error #1594

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions packages/openscd/src/finder-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export class FinderList extends LitElement {
return path.join('/');
}

getDisplayString(entry: string, path: string[]): string {
return entry;
}

@query('div')
container!: Element;
Expand Down Expand Up @@ -153,9 +150,11 @@ export class FinderList extends LitElement {
html`<mwc-list-item
value="${entry}"
?activated=${this.getPaths(path.length)
.map(p => JSON.stringify(p))
.map(p => {
return JSON.stringify(p)
})
.includes(JSON.stringify(path.concat(entry)))}
>${this.getDisplayString(entry, path)}</mwc-list-item
>${entry}</mwc-list-item
>`
)}
</filtered-list>`;
Expand Down
17 changes: 12 additions & 5 deletions packages/plugins/src/menu/Help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`<div>
<div style="display:flex">
Expand Down Expand Up @@ -43,19 +47,22 @@ async function getLinkedPages(path: string[]): Promise<Directory> {
}

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 = `<a style="cursor: help; color: var(--mdc-theme-primary)" href="https://github.com/openscd/open-scd/wiki/$2" target="_blank">$1</a>`
const unlinkedMd = md.replace(
/\[([^\]]*)\]\(https:..github.com.openscd.open-scd.wiki.([^)]*)\)/g,
`<a style="cursor: help;" onclick="Array.from(event.target.closest('section').lastElementChild.children).find(child => child.text === '$2'.replace(/-/g, ' ')).click()">$1</a>`
new RegExp(`\\[(${MD_LINK_TITLE_PATTERN.source})\\]\\(${GITHUB_WIKI_LINK_PATTERN.source}\\)`, 'g'),
MD_LINK_REPLACEMENT
);

const header = html`<div style="padding: 8px;">
${page === 'Home' ? aboutBox(edition.version) : html``}
${unsafeHTML(marked.parse(unlinkedMd))}
</div>`;
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 };
}
Expand Down
Loading