-
-
Notifications
You must be signed in to change notification settings - Fork 383
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
Generate Table of Contents #75
Generate Table of Contents #75
Conversation
…dered list of links to headers. * Add test cases for directly using HTML::Pipeline::TableOfContentsFilter * Add test cases for using HTML::Pipeline::TableOfContentsFilter within a HTML::Pipeline * Initialize result[:toc] to an empty string in TableOfContentsFilter#call * Initialize @toc to an empty string in TableOfContentsFilter#call * Set toc as an attr_reader on TableOfContentsFilter * Extract adding header anchor to TableOfContentsFilter#add_header_anchor * Define TableOfContentsFilter#append_toc for adding a toc item * Define TableOfContentsFilter#finalize_toc for wrapping toc items in a container * Markup from GitHub Styleguide Styling & CSS Navigation 8.3.1 * Update TomDoc * Update README.md explaining generated Table of Contents
First pull I've gotten with attached soundtrack. We're going to get along, you and I. 🤘 I'll look over the pull today and come back with notes. |
🎶 For sure. Glad you're enjoying it! 🎶 Thanks for taking the time to review. |
class TableOfContentsFilter < Filter | ||
PUNCTUATION_REGEXP = RUBY_VERSION > "1.9" ? /[^\p{Word}\- ]/u : /[^\w\- ]/ | ||
|
||
# Public: Gets the String value of the Table of Contents. | ||
attr_reader :toc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick, but I don't think there's any value in exposing a public toc
reader. To keep the interface consistent across filters, I think it's better to just have one way of accessing filter outputs - via the result
hash. The other change you'd need to make is update append_toc
to return the toc rather than assign it to @toc
:
result[:toc] = append_toc text, name, uniq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed on keeping the interface consistent. Removing the public toc
reader is a good idea.
If we remove @toc
, I think we can remove append_toc
.
Checked it out locally and it works great. I'll merge and cut a release after we discuss the changes above 😉 |
… removing attr_reader. Also, reduce complexity by removing private methods and keep changes within #call. Finally, implement #build_toc to wrap result[:toc] in an unordered list.
doc | ||
end | ||
|
||
# Private: Wrap Table of Contents list items within a container. | ||
def build_toc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, maybe we should move this logic into #call
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, I think that's a good idea. It's small and not called by anything else. It's clearer to have it all in #call.
I'd love to hack on #48. It's not too tricky to do, but we'd need to make sure it CI's properly. I'm in SF right now, but normally in Pasadena. We could work on it remotely, or even meet up half way to hack on it. Your call ;) |
Sweet! Sounds like fun. Thanks for offering options. I'll shoot you an email, so we can work out the details. |
🍻 |
Awesome! Thanks. 🍻 all around... |
In
TableOfContentsFilter
, generate a Table of Contents as a HTML unordered list of links to headers.HTML::Pipeline::TableOfContentsFilter
HTML::Pipeline::TableOfContentsFilter
within aHTML::Pipeline
result[:toc]
to an empty string inTableOfContentsFilter#call
@toc
to an empty string inTableOfContentsFilter#call
toc
as anattr_reader
onTableOfContentsFilter
TableOfContentsFilter#add_header_anchor
TableOfContentsFilter#append_toc
for adding a toc itemTableOfContentsFilter#finalize_toc
for wrapping toc items in a container🎵 Thanks to the tests, this Pull Request has a soundtrack. 🎵