-
Notifications
You must be signed in to change notification settings - Fork 22
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
Improve headers
method
#66
Improve headers
method
#66
Conversation
d09ceda
to
7dd9b5a
Compare
headers.flatten.compact | ||
end | ||
|
||
private |
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.
Our style is to indent this at the class
level and drop the whitespace line beneath. See https://github.com/alphagov/styleguides/blob/master/ruby.md
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.
Addressed in guidance-guarantee-programme@84c74e6
LGTM. Any thoughts @fofr, @dsingleton? |
@@ -3,11 +3,45 @@ module Govspeak | |||
|
|||
class HeaderExtractor < Kramdown::Converter::Base | |||
def convert(doc) | |||
headers = [] | |||
|
|||
doc.root.children.map do |el| |
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.
Because you're now explicitly pushing things into the headers
array, each
is more appropriate than map
here. map
is used to create an array of the items that the iterator block yields, whereas each
just executes the block once per item.
84c74e6
to
1d2582e
Compare
doc.root.children.map do |el| | ||
if el.type == :header | ||
Header.new(el.options[:raw_text], el.options[:level], generate_id(el.options[:raw_text])) | ||
headers.push(build_header(el)) |
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.
Personal preference maybe, but I'd prefer headers << build_header(el)
Couple of tiny comments, otherwise 👍
You are now 😄 |
1d2582e
to
32febdb
Compare
Thanks both, comments should all be addressed now! |
Fixes issues to do with nested headers not being found, and where explicitly assigned ID's were being ignored in favoured of the auto-generated versions.
32febdb
to
1135ada
Compare
@boffbowsh @benlovell either of you free to push the button? |
Fixes two issues to do with nested headers not being picked up, and where explicitly assigned ID's were being ignored in favoured of the auto-generated versions.
Please be kind with code review – I'm not a ruby developer 😇
Example:
headers
, it was only returning the first heading with an incorrect ID (#heading
as opposed to#explicit-id
).<h2>Heading two</h2>
was not being recognised by the govspeak method, even though it was in the rendered HTML.Follows the kramdown documentation for Specifying a Header ID and HTML Blocks.