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

Collapsing not working in xhtml #239

Closed
shenzo1 opened this issue Aug 17, 2021 · 19 comments
Closed

Collapsing not working in xhtml #239

shenzo1 opened this issue Aug 17, 2021 · 19 comments

Comments

@shenzo1
Copy link

shenzo1 commented Aug 17, 2021

Hello,

thanks for the great js! I am encountering issues in making the toc behave correctly in xhtml. The sections that should collapse don't as the parent/children relationship is not honored and all levels (h1, h2, h3) are considered to be at the same level. Everything else is functioning as it should. The collapsing works perfectly well in html but not in xhtml. Do you have any idea what would be the cause ot that?

@tscanlin
Copy link
Owner

Hi, there! Do you have an example somewhere that reproduces this behavior?

@shenzo1
Copy link
Author

shenzo1 commented Aug 18, 2021

Well I am working on my local server but here's the code I am using from your example:
https://paste.ofcode.org/9ZytV8BwKjYgxdyyUjUb6k

@tscanlin
Copy link
Owner

When I try this locally it appears to nest as I would expect. Maybe I am not testing right though.

@shenzo1
Copy link
Author

shenzo1 commented Aug 18, 2021

Ha interesting...I am testing locally on macos 10.14.6 with chrome and firefox and none appear to nest...I have been wondering if there was an issue with xhtml strict rules and the javascript code for nesting but it seems to work for you. Would you have any other idea as to what is going on? Thanks.

@tscanlin
Copy link
Owner

I’m not sure what else would be going on. Would you be able to host an example that reproduces this.

@shenzo1
Copy link
Author

shenzo1 commented Aug 22, 2021

Thanks for your reply. I don't have the ability to host right now. But the page source of my test when displayed in a browser is exactly the same as the code posted earlier. Really puzzling that it is working perfectly for you!

@tscanlin
Copy link
Owner

Are you able to post a screenshot or something that shows the issue? Also I'm curious, what reason do you have for using xhtml?

I would definitely be open to a PR if you are able to figure out what the fix is but for now I'll just keep this open.

@shenzo1
Copy link
Author

shenzo1 commented Aug 25, 2021

Here's a pic:
Pic

I use xhtml as a way to display xml files from conferences that involves custom non-html tags. I can use css to display those in xhtml, whereas they are ignored in html.

I will let you know if I find a solution. Thanks.

@tscanlin
Copy link
Owner

Hey, I was doing some reading and apparently tagName, a native DOM api, which is used by tocbot may return lowercase letters in xml. Does changing / overwriting this function to be like below fix the issue for you?

function getHeadingLevel (heading) {
    return +heading.nodeName.replace('H', '').replace('h', '')
}

@shenzo1
Copy link
Author

shenzo1 commented Aug 28, 2021

Thanks, Tim. I must confess I am not very versed in javascript or any of this. I see the code you are suggesting me to replace is in the parse-content.js but as I am calling the script with a link and didn't install it locally with npm, how can I modify/override this function? Don't worry about it if it requires tedious explanations. Appreciate your help.

@tscanlin
Copy link
Owner

Can you paste your code again? The link above seems to have expired

@shenzo1
Copy link
Author

shenzo1 commented Aug 28, 2021

Sure here it is: https://pastebin.com/QyPd2seV

@tscanlin
Copy link
Owner

It still seems to work fine for me with the code you provided. If you run tocbot.refresh() from the console does it look better?

@shenzo1
Copy link
Author

shenzo1 commented Sep 1, 2021

no luck :( Could it be that it is working for you because you have tocbot installed with npm? I have installed it with npm but I am not clear about the following step to try it on my xhtml page:

If you installed it with npm and use sass / postcss you might try importing the styles from 'node_modules', see the includePath option documentation for more info

@import 'tocbot/src/scss/tocbot';

@tscanlin
Copy link
Owner

tscanlin commented Sep 1, 2021

It looks like you are using it off the CDN though so I don't think that's the issue.

@shenzo1
Copy link
Author

shenzo1 commented Sep 1, 2021

True. Using the same code as html (apart from the xhtlm specific DTDs etc.) works perfectly well. So it is definitely related to xhtml and how the javascript code is parsed in this context. What you mentioned earlier about xhtml/xml parsing javascript as lowercase would make sense as a potential cause for the issue I am encountering. But then I don't understand why it works as it is supposed to in your system. It can't be browser related either, the issue is encountered on Chrome, Firefox and Safari. MacOs? I don't see how that would affect anything but then I am not an expert in these things.

@tscanlin
Copy link
Owner

tscanlin commented Sep 2, 2021

I made this PR with updated build files with the possible fix. Can you test it out and let me know if it fixes the issue for you?
#244

@shenzo1
Copy link
Author

shenzo1 commented Sep 2, 2021

This has completely fixed it! It works now as it should on xhtml! Thanks so much for your help and this great piece of code!

@shenzo1 shenzo1 closed this as completed Sep 2, 2021
@tscanlin
Copy link
Owner

tscanlin commented Sep 3, 2021

Hey, glad the fix worked! And thanks for your helping testing it out and verifying! This is released in version 4.13.3

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

No branches or pull requests

2 participants