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

Remove Kramdown overrrides #298

Merged
merged 1 commit into from
Dec 13, 2023
Merged

Remove Kramdown overrrides #298

merged 1 commit into from
Dec 13, 2023

Conversation

jkempster34
Copy link
Contributor

@jkempster34 jkempster34 commented Dec 12, 2023

https://trello.com/c/lu30wpdq

Currently, in order to disable ordered lists for legislative lists, we modify the @@parsers class variable and the LIST_START constant of the Kramdown library.

We are seeing a bunch of errors relating to these missing in production, such as:

  • NoMethodError: undefined method `start_re' for nil:NilClass (NoMethodError) if @src.check(@parsers[name].start_re)
  • Kramdown::Error: Unknown parser: list (Kramdown::Error)
  • NameError: uninitialized constant Kramdown::Parser::Kramdown::LIST_START

Rather than modifying class variables and constants in a non thread-safe manner, this takes the simpler approch of copying the body of the parse_list method and making the neccessary changes required for disabling ordered lists.

The downside of copying the majority body of the parse_list method may be offset by the fact that:

  • This is thread-safe
  • This is significantly simpler to understand
  • The list module of Kramdown is rarely updated.
  • The previous implementation also relied on the internals of Kramdown.

This repo is owned by the publishing platform team. Please let us know in #govuk-publishing-platform when you raise any PRs.

@jkempster34 jkempster34 force-pushed the fix-list-not-found-errors branch 2 times, most recently from 5a36eaf to 3e9f326 Compare December 12, 2023 11:35
@mike29736 mike29736 self-assigned this Dec 13, 2023
Copy link
Contributor

@mike29736 mike29736 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I think this is cleaner than the previous approach.

Considering that we haven't managed to reproduce the errors (and that we possibly wouldn't even want to reproduce them in the test suite if it is a thread safety issue), are you confident that the existing tests cover this area as well as they could?

Testing a branch of the gem in Whitehall sounds workable. But if you're happy with this, we could just release it generally and monitor it?

# The surrounding div is neccessary to control flow in `parse_block_html` and
# maintain the same functionality as a previous version of this extension.
# The surrounding div is neccessary to accurately identify legislative lists
# in post-processing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# We override the parse_list method with a modified version where ordered lists are
# disabled (for use with legislative lists). The majority of the method body is copied
# over, only the LIST_START is changed. Previously, we dynamically modified some of the
# class-scoped variables used in this method; this provides a thread-safe alternative.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about including a link to Github for the version of the method you copied in this comment? (e.g. maybe it was this one https://github.com/gettalong/kramdown/blob/REL_2_3_1/lib/kramdown/parser/kramdown/list.rb#L54 ?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

@jkempster34
Copy link
Contributor Author

Personally, I think this is cleaner than the previous approach.

Considering that we haven't managed to reproduce the errors (and that we possibly wouldn't even want to reproduce them in the test suite if it is a thread safety issue), are you confident that the existing tests cover this area as well as they could?

Testing a branch of the gem in Whitehall sounds workable. But if you're happy with this, we could just release it generally and monitor it?

I've pulled the Govspeak out of the content items which are raising these errors, and all of them work as expected in Govspeak Preview. I think the test suite is fairly comprehensive when it comes to legislative lists. What would you recommend we call the release?

Currently, in order to disable ordered lists for legislative lists, we modify
the @@parsers class variable and the LIST_START constant of the Kramdown
library.

We are seeing a bunch of errors relating to these missing in production, such
as:
- NoMethodError: undefined method `start_re' for nil:NilClass (NoMethodError)
  if @src.check(@parsers[name].start_re)
- Kramdown::Error: Unknown parser: list (Kramdown::Error)
- NameError: uninitialized constant Kramdown::Parser::Kramdown::LIST_START

Rather than modifying class variables and constants in a non thread-safe
manner, this takes the simpler approch of copying the body of the `parse_list`
method and making the neccessary changes required for disabling ordered lists.

The downside of copying the majority body of the `parse_list` method may be
offset by the fact that:
- This is thread-safe
- This is significantly simpler to understand
- The list module of Kramdown is rarely updated.
- The previous implementation also relied on the internals of Kramdown.
@jkempster34 jkempster34 force-pushed the fix-list-not-found-errors branch from 3e9f326 to ce1c192 Compare December 13, 2023 13:01
@jkempster34 jkempster34 merged commit 82920f2 into main Dec 13, 2023
9 checks passed
@jkempster34 jkempster34 deleted the fix-list-not-found-errors branch December 13, 2023 13:11
mike3985 added a commit that referenced this pull request Nov 19, 2024
We were revisiting Joe's old CTA and legislative list bug fixes in
mobbing today. We wanted to know whether we could remove the code that
we'd had to copy from the Kramdown codebase. The results turned out to
look spookily similar to the code that Joe had originally removed
(see: #298)
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

Successfully merging this pull request may close these issues.

2 participants