Skip to content

Commit eaed61f

Browse files
committed
fix: undefined context id in the root context of the link parser
1 parent cd1f356 commit eaed61f

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

libs/core/src/adapters/dynamic-html-adapter.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,7 @@ export class DynamicHtmlAdapter implements IAdapter {
100100
return context
101101
}
102102

103-
private _handleMutations(
104-
element: HTMLElement,
105-
context: IContextNode
106-
) {
103+
private _handleMutations(element: HTMLElement, context: IContextNode) {
107104
const parsedContext = this.parser.parseContext(element, context.contextType)
108105
const pairs = this.parser.findChildElements(element, context.contextType)
109106
const insPoints = this._findAvailableInsPoints(element, context.contextType)

libs/core/src/parsers/link-parser.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ function tryParseUrl(text: string): URL | null {
99
}
1010

1111
export class LinkParser implements IParser {
12-
parseContext({ href, innerText }: HTMLAnchorElement) {
12+
parseContext(element: HTMLAnchorElement, contextName: string) {
13+
if (contextName === 'root') return { id: 'global' }
14+
1315
// ToDo: twitter-specific logic. Twitter adds '…' to the end of the url
14-
const cleanUrl = innerText.replace(/$/g, '')
16+
const cleanUrl = element.innerText.replace(/$/g, '')
1517

1618
return {
17-
id: href,
18-
href: href,
19+
id: element.href,
20+
href: element.href,
1921
innerHref: tryParseUrl(cleanUrl)?.href,
20-
innerText: innerText,
22+
innerText: element.innerText,
2123
}
2224
}
2325

0 commit comments

Comments
 (0)