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 markdown-powered fields #1749

Merged
merged 2 commits into from
Feb 5, 2025
Merged

Conversation

dchiller
Copy link
Contributor

@dchiller dchiller commented Jan 31, 2025

This PR adds machinery to use (edit and display) markdown in text fields. This PR implements this on the Source.selected_bibliography and Source.description fields, but the same machinery can be used for other fields (e.g., flat page fields, future landing page fields).

The PR includes the following features:

  1. a new MarkdownWidget django widget that can be used in forms. This widget provides both a textarea editing area and the ability to navigate via tabs to a "preview" area. This preview is generated client side (with the marked.js dependencies included by way of the widget definition.
  2. a new render_markdown template tag that converts the markdown to html and sanitizes the html on the server side for when fields containing markdown are displayed.
  3. stylings for both MarkdownWidget and a new class markdown-field-display that styles the contents of markdown fields (note: in future, these stylings could be expanded to multiple classes that can be used to style fields generated from markdown differently in different contexts).

Note: The render_markdown tag cleans the generated html to remove raw html included in the markdown. Thus, fields displayed with this template tag that have legacy raw html in them will need to be edited before they will display correctly. This editing should occur concurrently with the implementation of this PR on production. I realize that this limits the kinds of things we can do in these fields (we can't use markup alongside markdown), which may present a future problem; on the other hand, we may find that these limits are perfectly fine for our use of these fields.

Once this is implemented and relevant fields are edited, we will be able to deal with #1239, #1221, and #1219.

Screenshot of edit tab:

image

Screenshot of detail view:

image

Add a form field/widget to edit markdown for text fields. Implement this field initially for the `description` and `selected_bibliography` fields on the `Source` model.

Add helper tag `render_markdown` for displaying markdown fields.
@dchiller dchiller merged commit 1e7d0b7 into DDMAL:develop Feb 5, 2025
1 check passed
@dchiller dchiller deleted the markdown-fields branch February 5, 2025 20:31
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