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

Markdown Checkbox Functionality #54

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

Markdown Checkbox Functionality #54

wants to merge 3 commits into from

Conversation

AdritRao
Copy link
Member

@AdritRao AdritRao commented Aug 2, 2024

Markdown Checkbox Functionality

♻️ Current situation & Problem

Checkboxes are currently not supported in markdown consent forms for SpeziOnboarding. Adding support for checkbox syntax in MD files can allow for yes/no consent questions in addition to the name and signature.

⚙️ Release Notes

  • Added functionality for checkbox syntax to be extracted from MD (extractMarkdownCB()). Checkbox questions can be put within square brackets (e.g. [Do you consent to data collection?]).
  • extractMarkdownCB() also returns a cleaned MD with checkbox syntax removed for PDF export
  • Added checkboxesView to create checkbox buttons based on the extracted items from MD
  • Used ImageRenderer to capture snapshot of checkboxesView when user taps 'I Consent'
  • Updated document export to use cleaned MD and added image of checkbox snapshot under the MD text (when available)
  • Updated OnboardingConsentMarkdownRenderingView.swift to allow for QuickLook PDF view

Below is an image of the UI and PDF export produced from the following MD data:

Data(
    """
    This is a *markdown* **example** of a consent document. 
    [May we contact you for future studies?] 
    [Can we store your step count for research purposes?]
    """.utf8
)
Simulator Screenshot - iPhone 15 Pro - 2024-08-02 at 01 21 58 Simulator Screenshot - iPhone 15 Pro - 2024-08-02 at 01 28 54

📝 Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

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

@AdritRao Thank you for taking a look at the issue and addressing a first element here!

I have a few first things that could help as you move forward:

  1. I would suggest using the GitHub task list syntax to extract checkboxes from the markdown: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#task-lists
  2. I would suggest that we allow these checkboxes to be translated to either Toggles or a Menu. I would probably prefer a SwiftUI Menu as it can also detail that no selection has been made yet, which might be important if a user needs to either agree or disagree to something.
  3. We should embed these at the places where they occur in the Markdown. This requires us to basically parse the MD fileline by line, then investigate if one line contains a special syntax we need to interpret (see above or below for possibilities), and then transform this into a specialized element. I would suggest that we create a special data structure for this instead of doing this in a few. This would also make it easier to unit test this:
    a. The data structure contains a list of elements that are enums. These can be Markdown text, an agree/disagree selection with a description, or the signature field (keeping it simple for these three for now).
    b. You can parse an MD string into this format so it is transformed in our internal representation.
    c. This is then used in the Consent Document to basically render this in a ForEach loop that just renders each section one after each other in our VStack/ScrollView.
    d. On export, this data is then collected and transferred into an easily parsable representation as noted in Supporting to distinguish multiple consent forms during onboarding via an identifier (#50) #51.

In addition, we should take a look at the GitHub MD syntax on how we might represent additional fields like an initial signature field. I can imagine we can use:

> [!INITIALS]
> Description for the initials field.

Syntax or something similar to how GitHub displays alerts boxes: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts.

I can also see that we only rely on this syntax and also use that for selections:

> [!AGREE]
> Description of the Agree/Disagree field

and

> [!SIGNATURE]

to even inject the signature field at the bottom of the consent document.

Let me know what you think; thank you for taking a deep-dive into all of this!

@PSchmiedmayer PSchmiedmayer added the enhancement New feature or request label Aug 4, 2024
@AdritRao
Copy link
Member Author

AdritRao commented Aug 5, 2024

Thank you for reviewing the PR and for providing these next steps @PSchmiedmayer! I will start working on migrating to the GitHub syntax and using SwiftUI menus. I will also add the functionality for line-by-line parsing to make sure that elements are created and displayed based on the order they appear in the Markdown file. After this, I will add the additional elements such as initials, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants