-
Notifications
You must be signed in to change notification settings - Fork 2
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
Conversation
a47168c
to
525b245
Compare
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
525b245
to
64265ea
Compare
6cb6f74
to
240a4ab
Compare
* Add def construct_details_from(match) and def format_punctuation to form details text array * Refactor
240a4ab
to
8433b67
Compare
summary_text, match, details = match_string.partition(Regexp.union(*partition_characters)) | ||
|
||
summary = [summary_text, format_punctuation(match)].compact.join |
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.
Nice!
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.
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.
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
{details}
def inject_details
into preprocessordef construct_details_from(match)
to construct details array anddef format_punctuation(match)
for correct formattingself
so that they can be chained indef preprocess
def preprocess
so that HTML is injected before the markdown is processed by the rendererattr_reader :document
toattr_reader :output
so it looks nicer when we call it indef 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: