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

Truncate toc entry if its length exceeds a single line #200

Closed
rmannibucau opened this issue Jun 16, 2015 · 9 comments
Closed

Truncate toc entry if its length exceeds a single line #200

rmannibucau opened this issue Jun 16, 2015 · 9 comments
Assignees
Labels

Comments

@rmannibucau
Copy link

Depending the text

num_dots = ((bounds.width - (width_of %(#{sect_title}#{sect_page_num}), inline_format: true) - spacer_width) / dot_width).floor

can be negative.

In this case the next line (1571 in converter.rb):

%(#{(@theme.toc_dot_leader_content || DotLeaderDefault) * num_dots})

will fail with

Caused by: org.jruby.exceptions.RaiseException: (ArgumentError) negative argument

Would be great to

  • prevent negative size
  • print a message (warning?)
@mojavelinux
Copy link
Member

Zonk! I never thought of that case. This will definitely make a great test case.

I did some research on this and determined that a quick fix (a) is to just set the number of dots to 0 if the calculated result is less than zero.

However, the title text will still wrap. So the next fix (b) is to only allow the title to consume a single line.

However, then the text could still overlap the page number. The final fix (c) is to prevent the title text from expanding past a fixed column (better that it is fixed I think for consistency). Perhaps something like 80 or 90% of the page. That should leave enough room for the page numbers. In this case, the dots get a bit off, but I don't think that's a huge concern atm.

@mojavelinux mojavelinux added this to the v1.5.0 milestone Jun 16, 2015
@mojavelinux mojavelinux self-assigned this Jun 16, 2015
@mojavelinux
Copy link
Member

I think I'll move forward with (a) and (b) right away so that the processor isn't crashing. Then, I'll try to arrive at a nice solution for (c).

@mojavelinux
Copy link
Member

I've done (a) in master just so that you can move forward.

@rmannibucau
Copy link
Author

personally I just used a max between computed number and 0. If it is not enough wrapping or whatever solution makes rendering less nice IMO and needs "writer" works. That said if you manage to get a nicer default it is really better.

@mojavelinux mojavelinux changed the title clear error when a toc entry is too long truncate toc entry if its length exceeds a single line Jun 16, 2015
@mojavelinux mojavelinux changed the title truncate toc entry if its length exceeds a single line Truncate toc entry if its length exceeds a single line Jun 16, 2015
@mojavelinux
Copy link
Member

👍

Btw, thanks for pointing this out!

@graphitefriction
Copy link
Member

@mojavelinux Per the release notes for Alpha 8, it says this issue is closed ... but it looks like it is still open?

@mojavelinux
Copy link
Member

This is only partially addressed. A quick fix is in place, but there's still work to do to make it cover all cases in the proper way.

@mojavelinux
Copy link
Member

The milestone should be set to 1.5.0.beta.1 for now.

@mojavelinux
Copy link
Member

I've decided to split the remaining changes off into #1152 and #1153. I've also added a test to cover the fix that was made in this issue. Therefore, this issue can now be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants