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

Add a copy option to site context menus #1

Closed
wheelercj opened this issue Mar 4, 2024 · 0 comments
Closed

Add a copy option to site context menus #1

wheelercj opened this issue Mar 4, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@wheelercj
Copy link
Owner

wheelercj commented Mar 4, 2024

It would be great if Stardown could help with copying not just links to entire pages, but also links to specific parts of pages.

With the context menus API, it's probably possible to get the HTML of the right-clicked element. From that, a link could be created in either of two ways:

If the right-clicked element or a nearby one has . . .

  • an id attribute, it can be linked to with [${title}](${url}#${id})
  • selected text, it can be linked to in some browsers (currently not yet including Firefox) with Text Fragments

pseudocode

get the page's title
get the page's URL

if the right-clicked element is selected text:
    get the selected text
    create a Text Fragment
    create markdown link: `[${title}](${url}${textFragment})`
else if the right-clicked element has an ID attribute:
    get the right-clicked element's ID
    create markdown link: `[${title}](${url}#${id})`
else:
    create markdown link: `[${title}](${url})`

I discovered after writing the pseudocode above that text fragments and element IDs can be used together. Browsers that support text fragments will try to use them first, and only use the ID as a fallback if the text fragment doesn't match the page anywhere. When I tried using a link with both a text fragment and an ID in Firefox (which currently does not support text fragments), not only did the text fragment not work, but it also prevented the ID from working.

further reading

@wheelercj wheelercj added the enhancement New feature or request label Mar 4, 2024
@wheelercj wheelercj self-assigned this Mar 4, 2024
wheelercj added a commit that referenced this issue Mar 10, 2024
wheelercj added a commit that referenced this issue Mar 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant