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

On Hover Footnote Preview #2522

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[Catppuccin](https://catppuccin.com/) color palette. The existing themes
(`documenter-light` and `documenter-dark`) are still the default light and dark theme,
respectively. ([#2496])
* On-hover Footnote Preview feature added. ([#2080])

### Changed

Expand Down Expand Up @@ -1764,6 +1765,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2071]: https://github.com/JuliaDocs/Documenter.jl/issues/2071
[#2076]: https://github.com/JuliaDocs/Documenter.jl/issues/2076
[#2078]: https://github.com/JuliaDocs/Documenter.jl/issues/2078
[#2080]: https://github.com/JuliaDocs/Documenter.jl/issues/2080
[#2081]: https://github.com/JuliaDocs/Documenter.jl/issues/2081
[#2085]: https://github.com/JuliaDocs/Documenter.jl/issues/2085
[#2100]: https://github.com/JuliaDocs/Documenter.jl/issues/2100
Expand Down
10 changes: 10 additions & 0 deletions assets/html/js/footnote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// libraries: jquery
// arguments: $

$(document).ready(function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is where it actually sets the preview text that will be shown on hover, right?

Can you elaborate a little on what assumptions this makes on the HTML of the footnote? I'm trying to figure out if these assumptions hold / could be made to hold for bibliographic references as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this is used to get the footnote content in hidden span for preview! This jQuery code takes the footnote definitions from the end of the page and puts it into the hidden spans just under the footnotes based on their footnote IDs!

For bibliographic references, we will need another way because the references are in another file and not on same page!
We can add a hidden span in Julia part like this:

span[".footnote-preview", :id => "fn-$(f.id)"](footnote content comes here using that JQuery!)

We can add a small julia function which stores bibliographic reference on pages its being used on and then add them in span! This way we can use this method for all things that require hover preview feature whether it is footnotes, bibliographic references or docstring references!

We will just need those small julia functions for storing content and put them in span and similar css can be used for all, No Javascript or JQuery will be needed and this is most efficient way!

I used JQuery because I was not able to fetch content using Julia (lack of my expertise)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For bibliographic references, we will need another way because the references are in another file and not on same page!

That's probably not that much of an issue: I wouldn't mind adding (hidden) bibliography items on each page for anything that's being referenced on that page, just for the hover to be able to pick up the text for there. But there should be some existing JS to hook into (i.e., this PR) for showing the hover: I'd like to avoid having to instruct people using the plugin to manually set up JS.

$('.footnote-ref').hover(function() {
var id = $(this).attr('href');
var footnoteContent = $(id).clone().find('a').remove().end().html();
$(this).next('.footnote-preview').html(footnoteContent);
});
});
1 change: 1 addition & 0 deletions assets/html/scss/documenter/components/_all.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
@import "docstring";
@import "example";
@import "warner";
@import "footnote"
35 changes: 35 additions & 0 deletions assets/html/scss/documenter/components/_footnote.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.footnote-reference {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe name these, e.g., .hover-reference and .hover-preview to make them more general for things beyond footnotes, like citations?

Copy link
Contributor Author

@shravanngoswamii shravanngoswamii Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now until jQuery is being used we can only use this for footnotes but if can we use Julia for adding content then it will be better to change this to global use for preview features in all parts!

position: relative;
}

.footnote-preview {
display: none;
position: absolute;
z-index: 1;
max-width: 300px;
width: max-content;
background-color: $body-background-color;
border: 1px solid $link-hover;
padding: 10px;
margin-top: 10px;
border-radius: 5px;
left: 50%;
transform: translateX(-50%);
top: calc(100% + 10px);
}

.footnote-preview::before {
content: "";
position: absolute;
top: -10px;
left: 50%;
transform: translateX(-50%);
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid $link-hover;
}

.footnote-ref:hover+.footnote-preview,
.footnote-ref:focus+.footnote-preview {
display: block;
}
2 changes: 1 addition & 1 deletion assets/html/themes/catppuccin-frappe.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/html/themes/catppuccin-latte.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/html/themes/catppuccin-macchiato.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/html/themes/catppuccin-mocha.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/html/themes/documenter-dark.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/html/themes/documenter-light.css

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/html/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2271,8 +2271,12 @@
end

function domify(::DCtx, ::Node, f::MarkdownAST.FootnoteLink)
@tags sup a
sup[".footnote-reference"](a["#citeref-$(f.id)", :href => "#footnote-$(f.id)"]("[$(f.id)]"))
@tags sup a span

Check warning on line 2274 in src/html/HTMLWriter.jl

View check run for this annotation

Codecov / codecov/patch

src/html/HTMLWriter.jl#L2274

Added line #L2274 was not covered by tests
# Create the footnote reference with preview
sup[".footnote-reference"](

Check warning on line 2276 in src/html/HTMLWriter.jl

View check run for this annotation

Codecov / codecov/patch

src/html/HTMLWriter.jl#L2276

Added line #L2276 was not covered by tests
a["#citeref-$(f.id)", :href => "#footnote-$(f.id)", :class => "footnote-ref"]("[$(f.id)]"),
span[".footnote-preview", :id => "fn-$(f.id)"]()
)
end
function domify(dctx::DCtx, node::Node, f::MarkdownAST.FootnoteDefinition)
# As we run through the document to generate the document, we won't render the footnote
Expand Down
Loading