You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 . . .
id
attribute, it can be linked to with[${title}](${url}#${id})
pseudocode
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
createTextFragment
anddoGenerateFragment
in github.com/GoogleChromeLabs/link-to-text-fragmentThe text was updated successfully, but these errors were encountered: