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

Support HTML code in community/collection description fields #1322

Closed
2 tasks done
anayram opened this issue Oct 3, 2019 · 11 comments
Closed
2 tasks done

Support HTML code in community/collection description fields #1322

anayram opened this issue Oct 3, 2019 · 11 comments
Assignees

Comments

@anayram
Copy link
Member

anayram commented Oct 3, 2019

Many "Description or abstract" fields (at the Item level), as well as Description fields (Communities and Collections) contain HTML tags. Because these are text fields, HTML is not rendered in the UI and text looks garbled and it's way less readable than ideal.

Support HTML markup, specifically bold/strong text highlighting, italics, line breaks, and paragraphs entered in:

  • Description field (Collection and Community levels)
  • Description or Abstract field (Item level)

Examples of items with HTML tags:
Ad $ Summary
https://era.library.ualberta.ca/admin/communities/b41cdbfd-6af2-4a13-8ba6-59725565d445/collections/2c1f3d8f-376a-45f8-a422-2afc3363987d

Board Practices
https://era.library.ualberta.ca/admin/communities/b41cdbfd-6af2-4a13-8ba6-59725565d445/collections/71f4b544-22f3-436f-bed0-c215df838be9

Electrical and Computer Engineering, Department of
https://era.library.ualberta.ca/admin/communities/55bafdf5-db7f-48a8-a91e-69b8c01cc9fb

Platts Historical US Domestic Crude Prices
https://era.library.ualberta.ca/admin/communities/b41cdbfd-6af2-4a13-8ba6-59725565d445/collections/b73484ff-194c-4aa5-9011-95410f02ee34

@anayram anayram changed the title Support HTML code in community/collection description pages Support HTML code in community/collection description fields Oct 3, 2019
@anayram
Copy link
Member Author

anayram commented Oct 3, 2019

Related to #1295

@seanluyk
Copy link

@mbarnett not sure what our resources are for these kinds of enhancements at the moment, but I'd like to flag this as a very desirable improvement for ERA. Rather than HTML tags for formatting, I think something like Markdown would work really well since that's already used in many of the tools staff working in repositories are familiar with

@mbarnett
Copy link
Contributor

Makes sense! HTML is always a bit of a security risk but Markdown ought to be both more doable and fairly low effort.

I’ll refine this out a bit in the next day or two and then flag it as a good issue for some to pick up when they’re between larger priorities.

@seanluyk
Copy link

Excellent, thanks, Matt!

@mbarnett
Copy link
Contributor

Scope/Notes:

– We convert Markdown->HTML on page render (so don't store the HTML or anything)
– To make this a lot less effort to achieve, no preview functionality initially. Re-edit it if your Markdown isn't great, etc.
– we'll want to do this by building/enhancing decorators for Communities et al using https://github.com/vmg/redcarpet to intercept and render the appropriate field.
filter_html, no_images, no_styles, probably hard_wrap & link_attributes to add noreferer/noopener. That should leave room for text styling without security holes or accidentally breaking the page.
– will also need to use the StripDown renderer in the Solr exporters for all the fields this is added to, to completely strip out the Markdown when sending the data to Solr, because those special characters aren't going to play well with search indexes.
– not sure what the failure modes for RedCarpet are but rule #1 here is user input shouldn't be able to crash either the page or the Solr export, so we'll need to trap everything that it could possible complain about and fall back to just displaying the unrendered text or similar.
– unless I'm missing something we can't feature flag this, because the markdown text will be markdown-y even with the flag off.

@pgwillia pgwillia self-assigned this Feb 26, 2021
pgwillia added a commit that referenced this issue Apr 23, 2021
## Context

Many "description" or "abstract" fields (at the Item level as well as Communities and Collections) contain HTML tags. Because these are text fields, HTML is not rendered in the UI and text looks garbled and it's way less readable than ideal.

Markdown should work really well for this since that's already used in many of the tools staff working in repositories are familiar with.

Related to #1322
Replaces #2230

## What's New
- Added the redcarpet gem because it basically does what we want with markdown.  
- add `markdown` and `strip_markdown` to ApplicationDecorator
- updated SolrExporters to use the new `strip_markdown` helper to remove content being indexed

## Nits
* Faker markdown tables aren't parsed as tables by redcarpet.  Seems that adding a newline before the table is all that's needed as a workaround though.  This means that some text generated by `Faker::Markdown.sandwhich` isn't nice until it's edited to add the extra newline.
@seanluyk
Copy link

Just confirming that this is in production? Feature flag has been enabled but I don't seem to be able to get any formatting to render, e.g. the hyperlink at the bottom of this description: https://era.library.ualberta.ca/admin/communities/e4fdd15f-c21d-4612-a2f7-bfec3fdfc1de/collections/089d2213-9263-4b07-b3c4-05e18d6260dd

@seanluyk seanluyk reopened this Dec 16, 2021
@pgwillia
Copy link
Member

This is in production. There isn't a feature flag for this feature. I'll take a look.

@seanluyk
Copy link

seanluyk commented Dec 16, 2021 via email

@pgwillia
Copy link
Member

Oh, I see. I missed a spot for rendering the markdown. Need to fix for admin but

https://era.library.ualberta.ca/communities/e4fdd15f-c21d-4612-a2f7-bfec3fdfc1de/collections/089d2213-9263-4b07-b3c4-05e18d6260dd

renders the markdown.

@seanluyk
Copy link

Thanks!

@pgwillia
Copy link
Member

I opened a new issue for the outstanding work: #2708

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

No branches or pull requests

4 participants