Skip to content

Add support for line breaks markdown and mathjax in metadata#1851

Merged
tdonohue merged 11 commits intoDSpace:mainfrom
atmire:w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata
Sep 29, 2022
Merged

Add support for line breaks markdown and mathjax in metadata#1851
tdonohue merged 11 commits intoDSpace:mainfrom
atmire:w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata

Conversation

@samuelcambien
Copy link
Copy Markdown
Contributor

@samuelcambien samuelcambien commented Sep 22, 2022

References

Description

This PR focuses on two things:

  • preserve and display line breaks in metadata values
  • render markdown and mathjax in the dc.description.abstract metadata values

Instructions for Reviewers

List of changes in this PR:

  • some new libraries have been added:
    • markdown-it
    • markdown-it-mathjax3
    • sanitize-html
  • the class 'preserve-line-breaks' has been added to display line breaks for these components:
    • MetadataValuesComponent
    • TruncatablePartComponent
    • EditInPlaceFieldComponent
  • two new configuration fields have been added:
    • enableMarkdown (boolean, default: false)
    • enableMathjax (boolean, default: false)
  • new pipe 'MarkdownPipe' has been created, this will:
    • render markdown html for the input value
    • if the enableMathjax environment config is true:
      • lazy load the markdown-it-mathjax3 code
      • render mathjax html for the input value
    • because the default Angular sanitizer doesn't let svg tags through, and these are used by the mathjax html, the sanitize-html sanitizer is used here instead. It's configuration is tweaked to let the relevant tags through.
  • new field 'enableMarkdown' has been added to the MetadataValuesComponent, this is controlled by the ItemPageFieldComponent, and is only true for the ItemPageAbstractFieldComponent
  • the MetadataValuesComponent template has been updated to use the markdown pipe if both of the following conditions are true:
    • markdown is enabled for this metadata field
    • markdown is enabled in the environment config

To test this PR, create an item with line breaks, markdown and mathjax code (for instance this item), and verify that everything renders correctly.

Checklist

  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes TSLint validation using yarn run lint
  • My PR doesn't introduce circular dependencies
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • If my PR includes new, third-party dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.

@artlowel artlowel added bug high priority ux User Experience related works new feature e/8 Estimate in hours labels Sep 22, 2022
@artlowel artlowel added this to the 7.4 milestone Sep 22, 2022
@artlowel artlowel changed the title W2p 93963 add support for line breaks markdown and mathjax in metadata Add support for line breaks markdown and mathjax in metadata Sep 22, 2022
@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch from b3a773d to d3e6d39 Compare September 22, 2022 14:29
@samuelcambien samuelcambien changed the base branch from main to or2018 September 22, 2022 14:59
@samuelcambien samuelcambien changed the base branch from or2018 to main September 22, 2022 14:59
@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Sep 22, 2022

This pull request introduces 1 alert when merging eb4cda4 into edd193a - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@tdonohue
Copy link
Copy Markdown
Member

@samuelcambien : This appears to have lint errors (try running yarn lint locally to see them).

Additionally, the size of this PR is massive (15K lines) because it is somehow attempting to replace the entire yarn.lock file. It's unclear why that is, when you've only added a few new dependencies?

Maybe you've somehow accidentally changed all the line endings in yarn.lock? If that's the case, it's possible we may want to add yarn.lock eol=lf to our .gitattributes to force it to always use unix line endings: https://github.com/DSpace/dspace-angular/blob/main/.gitattributes#L9-L16 (You could include this in this PR if you want, but keep in mind that adding this setting will likely mean you'll need to re-nomalize your local files, see the notes here: https://git-scm.com/docs/gitattributes#_end_of_line_conversion)

@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch from eb4cda4 to 2eb8243 Compare September 23, 2022 07:12
@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Sep 23, 2022

This pull request introduces 1 alert when merging 2eb8243 into 001d6dc - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch from 2eb8243 to c744b3d Compare September 23, 2022 08:19
@lgtm-com
Copy link
Copy Markdown

lgtm-com bot commented Sep 23, 2022

This pull request introduces 1 alert when merging c744b3d into 001d6dc - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch 3 times, most recently from 829f9aa to c04a982 Compare September 23, 2022 11:24
…or line breaks, markdown and mathjax in metadata
…wn_and_mathjax_in_metadata

# Conflicts:
#	package.json
#	src/app/shared/shared.module.ts
#	src/app/shared/truncatable/truncatable-part/truncatable-part.component.html
#	src/config/app-config.interface.ts
#	src/config/default-app-config.ts
#	src/environments/environment.test.ts
#	src/styles/_global-styles.scss
#	yarn.lock
…or line breaks, markdown and mathjax in metadata - fix lint issues
@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch from 80207b0 to f57fb39 Compare September 23, 2022 12:01
…or line breaks, markdown and mathjax in metadata - add sanitize-html types to devdependencies for documentation
@samuelcambien
Copy link
Copy Markdown
Contributor Author

samuelcambien commented Sep 23, 2022

Hi @tdonohue, I've fixed the issues you mentioned.

@tdonohue
Copy link
Copy Markdown
Member

@samuelcambien : Apologies but this now has minor merge conflicts (likely caused by the recent merge of #1780). Could you rebase it when you get the chance?

@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch 3 times, most recently from a8c1de3 to 1789a43 Compare September 27, 2022 14:27
@davide-negretti
Copy link
Copy Markdown
Contributor

image

I suggest to add the markdown support in the search result too, if this requires a minimum effort

@davide-negretti
Copy link
Copy Markdown
Contributor

davide-negretti commented Sep 27, 2022

I reviewed the code and it looks fine for me.

PS - I did not mean to close the PR, my mouse decided to make me click the wrong button :-D
image

@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch from 1789a43 to 7771cff Compare September 27, 2022 15:41
@samuelcambien
Copy link
Copy Markdown
Contributor Author

samuelcambien commented Sep 27, 2022

I suggest to add the markdown support in the search result too, if this requires a minimum effort

Hi @davide-negretti, great suggestion. Implementing this isn't very hard, but it looks a bit weird with the current truncatable-part components (see screenshot). An option would be to add a gradient to the bottom here, but this is currently out of scope.

image

@tdonohue
Copy link
Copy Markdown
Member

@samuelcambien : It appears this PR is now failing unit tests? Could you see if those could be fixed?

@hardyoyo
Copy link
Copy Markdown
Member

I'm testing this PR now, here are my results:

line breaks work correctly, with no additional configuration:
image

Markdown works correctly, when configured in config.dev.yml:
image

MathJax is a mixed bag, I copied the markup from the sample item on the demo server, as per the suggestion above. Some of it works, some of it does not. I suspect this might be a configuration issue?
image

@hardyoyo
Copy link
Copy Markdown
Member

Regardless of the mixed results with MathJax, I'm still +1 on this, as-is (assuming we can resolve the test failure)

Copy link
Copy Markdown
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

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

@samuelcambien : Overall, this is working better. But, in Production mode, I cannot load an Item page (where the Item has an abstract with mathjax & markdown) when this feature is disabled.

Here's what I tried:

  • Create an Item with Markdown & MathJax in the abstract (your test item is perfectly good)
  • Start in production mode (yarn build:prod; yarn serve:ssr)
  • Turn this feature off. I.e. don't add the markdown section to your config.prod.yml
  • Visit the Item you created. The abstract won't load & this error appears in the console:
ERROR TypeError: Cannot read properties of undefined (reading 'enabled')
    at MetadataValuesComponent_ng_container_2_Template (C:\Users\donohue\programming\dspace-angular\dist\server\main.js:1:1792568)

If I enable the feature, then it does work in Prod mode. The error only occurs when disabled.

This PR is also currently failing some specs, so that also needs to be addressed. Thanks!

@samuelcambien samuelcambien force-pushed the w2p-93963-Add_support_for_line_breaks_markdown_and_mathjax_in_metadata branch from 85a73ef to e3351eb Compare September 29, 2022 10:58
@tdonohue tdonohue self-requested a review September 29, 2022 13:26
@samuelcambien
Copy link
Copy Markdown
Contributor Author

I've repaired the tests, the ItemPageFieldComponent test's config change was breaking the ItemPageAbstractFieldComponent test.
I've also repaired the production build, it was a mistake in the DefaultAppConfig.
Tested the production build both with and without markdown/mathjax.

Copy link
Copy Markdown
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

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

👍 Thanks @samuelcambien ! The fixes work for me now. I've retested today in production mode and everything works well. I've tried the default settings (both disabled) and also enabling just markdown and both markdown & mathjax. Looks good now!

@alawvt
Copy link
Copy Markdown

alawvt commented Sep 30, 2022

Thank you very much, @samuelcambien and everyone, for working on this important improvement. Could someone add a screenshot of the test file with the configurations enabled, so can compare to it in our future testing? Thanks.

@tdonohue
Copy link
Copy Markdown
Member

@alawvt : To enable both features in your config.*.yml, you'd use:

markdown:
  enabled: true
  mathjax: true

By default both are false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug e/8 Estimate in hours high priority new feature ux User Experience related works

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Display line breaks in metadata Preserve line breaks in metadata Porting the MathJax display from previous DSpace versions

7 participants