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

(#300) Fix anchor links in Markdown docs #303

Merged
merged 1 commit into from
Sep 26, 2022

Conversation

danielparks
Copy link
Contributor

Previously, anchors in generated Markdown were not unique. There were two problems:

  1. Each parameter in a class, type, function, etc. had its own anchor, but the name of the anchor was just the normalized name of the parameter. This meant that all parameters with the same name would have the same anchor.

  2. Classes, types, etc. had their ::s removed, whiched opened the (rare) possibility of having non-unique anchor names for unique type names.

This fixes those problems by:

  1. Using the full name of the parameter, e.g. $my::class::param, to generate an anchor name.

  2. Using a better anchor normalization routine. Each invalid character, i.e. not [a-zA-Z0-9_-], is converted to -. This should always result in unique anchor names for standard Puppet identifiers, since the only invalid characters sequences are :: and $ (which only appears once at the beginning of the string). Furthermore, - never appears in a valid Puppet identifier, so those two cases are the only way for it to be generated.

@danielparks danielparks requested a review from a team as a code owner September 23, 2022 11:40
@CLAassistant
Copy link

CLAassistant commented Sep 23, 2022

CLA assistant check
All committers have signed the CLA.

@danielparks
Copy link
Contributor Author

I was unable to run the acceptance tests:

❯ bundle exec rake 'litmus:provision[docker, centos:7]'
Cloning into 'spec/fixtures/modules/facts'...
Cloning into 'spec/fixtures/modules/provision'...
Cloning into 'spec/fixtures/modules/puppet_agent'...
fatal: unable to connect to github.com:
github.com[0: 140.82.113.4]: errno=Operation timed out

fatal: unable to connect to github.com:
github.com[0: 140.82.113.4]: errno=Operation timed out

fatal: unable to connect to github.com:
github.com[0: 140.82.113.4]: errno=Operation timed out

#<Thread:0x00000001072f03e8 /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:471 run> terminated with exception (report_on_exception is true):
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:196:in `clone_repo': Failed to clone git repository git://github.com/puppetlabs/puppetlabs-puppet_agent.git into spec/fixtures/modules/puppet_agent (RuntimeError)
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:364:in `download_repository'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:427:in `block (2 levels) in <top (required)>'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:315:in `block (2 levels) in download_items'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
#<Thread:0x00000001072f08c0 /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:471 run> terminated with exception (report_on_exception is true):
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:196:in `clone_repo': Failed to clone git repository git://github.com/puppetlabs/provision.git into spec/fixtures/modules/provision (RuntimeError)
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:364:in `download_repository'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:427:in `block (2 levels) in <top (required)>'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:315:in `block (2 levels) in download_items'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
#<Thread:0x00000001072f0f78 /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:471 run> terminated with exception (report_on_exception is true):
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:196:in `clone_repo': Failed to clone git repository git://github.com/puppetlabs/puppetlabs-facts.git into spec/fixtures/modules/facts (RuntimeError)
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:364:in `download_repository'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:427:in `block (2 levels) in <top (required)>'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:315:in `block (2 levels) in download_items'
	from /Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
rake aborted!
Failed to clone git repository git://github.com/puppetlabs/puppetlabs-facts.git into spec/fixtures/modules/facts
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:196:in `clone_repo'
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:364:in `download_repository'
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:427:in `block (2 levels) in <top (required)>'
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/puppetlabs_spec_helper-4.0.1/lib/puppetlabs_spec_helper/tasks/fixtures.rb:315:in `block (2 levels) in download_items'
/Users/daniel/personal/projects/third-party/puppet-strings/.bundle/gems/ruby/3.1.0/gems/logging-2.3.1/lib/logging/diagnostic_context.rb:474:in `block in create_with_logging_context'
Tasks: TOP => spec_prep
(See full trace by running task with --trace)

I can access GitHub fine; so maybe it’s a Docker problem? I pretty much don’t use docker, so I have no idea.

@chelnak chelnak force-pushed the fix_markdown_anchors branch from dd66852 to baf5336 Compare September 26, 2022 08:04
Previously, anchors in generated Markdown were not unique. There were
two problems:

  1. Each parameter in a class, type, function, etc. had its own anchor,
     but the `name` of the anchor was just the normalized name of the
     parameter. This meant that all parameters with the same name would
     have the same anchor.

  2. Classes, types, etc. had their `::`s removed, whiched opened the
     (rare) possibility of having non-unique anchor names for unique
     type names.

This fixes those problems by:

  1. Using the full name of the parameter, e.g.  `$my::class::param`, to
     generate an anchor name.

  2. Using a better anchor normalization routine. Each invalid
     character, i.e. not `[a-zA-Z0-9_-]`, is converted to `-`. This
     should always result in unique anchor names for standard Puppet
     identifiers, since the only invalid characters sequences are `::`
     and `$` (which only appears once at the beginning of the string).
     Furthermore, `-` never appears in a valid Puppet identifier, so
     those two cases are the only way for it to be generated.
@chelnak
Copy link
Contributor

chelnak commented Sep 26, 2022

This looks fine to me. Thank you for providing such a clear description/commit message.

@chelnak chelnak merged commit 504675b into puppetlabs:main Sep 26, 2022
@danielparks danielparks deleted the fix_markdown_anchors branch September 26, 2022 08:19
@chelnak chelnak linked an issue Sep 26, 2022 that may be closed by this pull request
@chelnak chelnak added the bug label Sep 26, 2022
@chelnak chelnak self-assigned this Sep 26, 2022
@chelnak chelnak added bugfix and removed bug labels Sep 29, 2022
b4ldr added a commit to b4ldr/puppetlabs-stdlib that referenced this pull request Mar 14, 2023
b4ldr added a commit to b4ldr/puppetlabs-stdlib that referenced this pull request Mar 14, 2023
b4ldr added a commit to b4ldr/puppetlabs-stdlib that referenced this pull request Jun 22, 2023
cegeka-jenkins pushed a commit to cegeka/puppet-stdlib that referenced this pull request Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Anchor links in generated markdown are not unique
3 participants