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 collapsible support #26

Merged
merged 1 commit into from
May 18, 2022
Merged

Add collapsible support #26

merged 1 commit into from
May 18, 2022

Conversation

gggto
Copy link
Contributor

@gggto gggto commented May 4, 2022

This Pull Request adds collapsible admonition support, as described in #18.

In its current state, this implementation has 2 shortcomings that I'm not sure how to overcome:

  1. The CSS could be modified to make the arrow look slightly better.
  2. The links to the admonition titles interfere with the open/close interaction. Clicking on the title doesn't open the box, which is counter-intuitive.

@gggto gggto marked this pull request as draft May 4, 2022 12:08
@gggto
Copy link
Contributor Author

gggto commented May 4, 2022

@tommilligan do you have any insight?

@schungx
Copy link
Contributor

schungx commented May 4, 2022

The links to the admonition titles interfere with the open/close interaction. Clicking on the title doesn't open the box, which is counter-intuitive.

This is going to need some thinking through... The link is there in order to generate the Copy Link Address context menu choice to copy the URL. Without it, it is hard to get a link to a particular part of the document.

However, you're also correct that the expected behavior upon clicking is to toggle the collapsing.

Maybe a custom onclick?

@tommilligan
Copy link
Owner

Sorry for the slow reply, been a busy couple of weeks for me.

The collapsible support looks really good, thanks for taking a stab at it!

I think I will move anchor link generation to an appear-on-hover icon, like a lot of sites (including doc.rs for code items) do:

anchor-link-hover

I think this is more discoverable anyway, and then leaves the header bar free to be clicked on to expand the dropdown/the title to contain links, etc.

This should allow this PR to be merged as is, after rebase and unit tests added.

@tommilligan
Copy link
Owner

@gggto now #27 is merged, title links should no longer be an issue

@gggto
Copy link
Contributor Author

gggto commented May 18, 2022

Thank you a lot! However, I'm not confident enough in my git-fu to properly fix the conflict between main and this fork, without screwing the git history or opening unwanted PR or whatever. The conflict looks really easy to solve though, so I'm sure we're not to far from merging.

What would you like me to do from there?

@tommilligan tommilligan marked this pull request as ready for review May 18, 2022 11:24
@tommilligan
Copy link
Owner

No worries, thanks for you work so far. I'll work through the conflict now and let you know what needed fixing. Then I'll add a review with any outstanding tasks.

@tommilligan
Copy link
Owner

For future reference, the conflict was reasonably simple to fix. You could run the following locally to reproduce what I did:

  • add the upstream repo (this one) as a new remote: git remote add upstream https://github.com/tommilligan/mdbook-admonish
  • fetch upstream's changes: git fetch upstream
  • run a rebase on the upstream main branch: git checkout main && git rebase upstream/main
  • fix the conflict. Git is pointing out that I moved the <a> tag at the same time as you did your changes
                Cow::Owned(format!(
<<<<<<< HEAD
                    r##"<{title_block} class="admonition-title">

{title}

<a class="admonition-anchor-link" href="#{ANCHOR_ID_PREFIX}-{anchor_id}"></a>
</{title_block}>
=======
<a class="admonition-anchor-link" href="#{ANCHOR_ID_PREFIX}-{anchor_id}">

{title}

</a>
>>>>>>> Add collapsible support
"##

so we can resolve as

                Cow::Owned(format!(
                    r##"<{title_block} class="admonition-title">

{title}

<a class="admonition-anchor-link" href="#{ANCHOR_ID_PREFIX}-{anchor_id}"></a>
</{title_block}>
"##
  • save your changes and finish the rebase with: git add -u && git rebase --continue
  • this should get you to a point where the tests pass (cargo test)
  • then push back to your own repository; you have to add -f to force overwrite the remote after a rebase: git push -f

Copy link
Owner

@tommilligan tommilligan left a comment

Choose a reason for hiding this comment

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

Looks really good, thanks for taking this on. I have some changes locally I will push onto your branch.

@@ -9,6 +9,7 @@ pub(crate) struct AdmonitionInfoRaw {
directive: String,
title: Option<String>,
additional_classnames: Vec<String>,
is_collapsible: bool,
Copy link
Owner

Choose a reason for hiding this comment

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

small nit: is_collapsible is generally superfluous, just collapsible is fine throughout

@@ -186,6 +188,30 @@ a.admonition-anchor-link {
}
}

summary {
Copy link
Owner

Choose a reason for hiding this comment

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

We should be specific we're only styling our summaries here, there could be others on the page in user content.

For example:

Suggested change
summary {
summary.admonition-title {

transition: transform .25s;
}

details[open] > &::after {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
details[open] > &::after {
details[open].admonition > &::after {

Comment on lines +68 to +69
--md-details-icon:
url("data:image/svg+xml;charset=utf-8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6-1.41-1.42Z'/></svg>");
Copy link
Owner

Choose a reason for hiding this comment

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

I think this looks perfect! Thanks very much.

For reference, we have:

image

and

image

@tommilligan
Copy link
Owner

Alright, updated and squashed. Just waiting for CI to run.

The final step was adding some docs and unit/integration tests (as we're adding new html elements I wanted to check that interaction too).

@tommilligan tommilligan merged commit 72deb84 into tommilligan:main May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants