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

Add details text tag rendering in preprocessor #20

Merged
merged 2 commits into from
Jan 6, 2023

Conversation

HettieS
Copy link
Contributor

@HettieS HettieS commented Jan 3, 2023

Context

This is a first stab at adding a preprocessing step for the Govuk Details component

This means that a start and end tag can be used in a markdown document i.e. {details} some title. some text. {/details} and the correct details component will be rendered in the HTML.

Changes

  • Add functionality for {details}
  • Add def inject_details into preprocessor
  • Add def construct_details_from(match) to construct details array and def format_punctuation(match) for correct formatting
  • Preprocessor methods now return self so that they can be chained in def preprocess
  • Call new method in def preprocess so that HTML is injected before the markdown is processed by the renderer
  • Rename attr_reader :document to attr_reader :output so it looks nicer when we call it in def preprocess

Usage

I've built this so that the first sentence within the tag will be rendered as the details summary text. The rest of the content will then be rendered as the details text e.g.

{details} Find out about the fox and the dog. Whilst the fox is quick and brown, the dog is lazy. {/details}

will appear like:

Screenshot 2023-01-04 at 11 01 01

@HettieS HettieS force-pushed the add-govuk-details-tag-to-preprocessor branch 3 times, most recently from a47168c to 525b245 Compare January 4, 2023 11:14
@HettieS HettieS requested a review from peteryates January 4, 2023 11:22
@peteryates
Copy link
Member

Looks great, left one minor suggestion that will make adding extra preprocessing steps easier to add.

* Preprocess details tags to allow for markdown usage
* Substitute tags for relevant HTML
* Small refactor to make methods chainable
* Small test refactor
@HettieS HettieS force-pushed the add-govuk-details-tag-to-preprocessor branch from 525b245 to 64265ea Compare January 4, 2023 14:21
@HettieS HettieS requested a review from peteryates January 4, 2023 14:30
@HettieS HettieS force-pushed the add-govuk-details-tag-to-preprocessor branch 4 times, most recently from 6cb6f74 to 240a4ab Compare January 5, 2023 16:52
* Add def construct_details_from(match) and def format_punctuation to form details text array
* Refactor
@HettieS HettieS force-pushed the add-govuk-details-tag-to-preprocessor branch from 240a4ab to 8433b67 Compare January 5, 2023 17:01
Comment on lines +51 to +53
summary_text, match, details = match_string.partition(Regexp.union(*partition_characters))

summary = [summary_text, format_punctuation(match)].compact.join
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

Copy link
Member

@peteryates peteryates left a comment

Choose a reason for hiding this comment

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

I think this looks great.

Not important for this PR but a section in the README on how to use the custom markup would probably be a good idea.

@HettieS HettieS merged commit c17d7e1 into main Jan 6, 2023
@HettieS HettieS deleted the add-govuk-details-tag-to-preprocessor branch January 6, 2023 10:11
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