-
Notifications
You must be signed in to change notification settings - Fork 10
Toward an Eleventy Plugin #74
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
Changes from all commits
e61398c
c7486da
08af031
d4b023b
0d6e294
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,13 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const linkMatcher = /\s*(\w+:\/\/\S+)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export default class Document { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(element, createPage, meterFaultButton) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| constructor(element, options = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| createPage = undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| meterFaultButton = undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pageTurnBehavior = 'log', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } = options; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const self = this; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.document = element.ownerDocument; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.parent = element; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -21,6 +29,7 @@ export default class Document { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.createPage = createPage || this.createPage; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.meterFaultButton = meterFaultButton; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.pageTurnBehavior = pageTurnBehavior; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Object.seal(this); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -40,8 +49,22 @@ export default class Document { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.br = false; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lift = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO merge with prior text node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.cursor.appendChild(document.createTextNode(lift + text)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const match = linkMatcher.exec(text); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (match === null) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO merge with prior text node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.cursor.appendChild(document.createTextNode(lift + text)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Support a hyperlink convention. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (lift !== '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this.cursor.appendChild(document.createTextNode(lift)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const link = document.createElement('a'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link.href = match[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link.target = '_blank'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link.rel = 'noreferrer'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| link.rel = 'noreferrer'; | |
| link.rel = 'noreferrer noopener'; |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The hyperlink implementation does not handle the case where the link text itself is empty (when match.index equals text.length). This would create an anchor element with no visible text, which is confusing for users and bad for accessibility.
| link.appendChild(document.createTextNode(text.slice(0, match.index))); | |
| const linkText = text.slice(0, match.index); | |
| link.appendChild(document.createTextNode(linkText !== '' ? linkText : match[1])); |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent indentation: this block uses 4 spaces while the rest of the file appears to use 2 spaces. Maintain consistent indentation throughout the file.
| // TODO merge with prior text node | |
| this.cursor.appendChild(document.createTextNode(lift + text)); | |
| } else { | |
| // Support a hyperlink convention. | |
| if (lift !== '') { | |
| this.cursor.appendChild(document.createTextNode(lift)); | |
| } | |
| const link = document.createElement('a'); | |
| link.href = match[1]; | |
| link.target = '_blank'; | |
| link.rel = 'noreferrer'; | |
| link.appendChild(document.createTextNode(text.slice(0, match.index))); | |
| this.cursor.appendChild(link); | |
| // TODO merge with prior text node | |
| this.cursor.appendChild(document.createTextNode(lift + text)); | |
| } else { | |
| // Support a hyperlink convention. | |
| if (lift !== '') { | |
| this.cursor.appendChild(document.createTextNode(lift)); | |
| } | |
| const link = document.createElement('a'); | |
| link.href = match[1]; | |
| link.target = '_blank'; | |
| link.rel = 'noreferrer'; | |
| link.appendChild(document.createTextNode(text.slice(0, match.index))); | |
| this.cursor.appendChild(link); |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The case 'log' appears to reference 'this.options.remove()' but should reference 'this.frame.remove()'. The 'log' behavior seems intended to keep previous pages in the document (for logging), but currently it only removes the options element, not handling the entire frame appropriately. This likely causes a bug where frames accumulate incorrectly.
| this.options.remove(); | |
| this.frame.remove(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use 'const' or 'let' instead of 'var' for the link variable declaration. Using 'var' is inconsistent with modern JavaScript best practices and can lead to unexpected scoping behavior.