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

feat: Add support for mermaid.js rendering #4614

Merged
merged 5 commits into from
Aug 7, 2023
Merged

feat: Add support for mermaid.js rendering #4614

merged 5 commits into from
Aug 7, 2023

Conversation

juliusknorr
Copy link
Member

@juliusknorr juliusknorr commented Jul 31, 2023

📝 Summary

Fixes #163

Implements mermaid js support for code blocks. By default the preview mode is used, unless the code block is empty or has faulty syntax. Users can then switch between preview/split and code mode. This also provides a way to switch the language of code blocks in the same location.

🖼️ Screenshots

Mermaid code block

Screenshot 2023-08-02 at 13 33 29

Screenshot 2023-08-02 at 13 32 09

Regular code bock

Screenshot 2023-08-02 at 13 32 49

🚧 TODO

  • There seems to be no syntax highlighting for mermaid on highlight.js -> no highlight
  • Design: Figure out language selector
  • Design: Check mode switcher and what the default should be
  • Design: Maybe we shall have some border or boxing around the element
  • BUG: Preview should probably be not contenteditable (noticable when selecting all text with Ctrl-A)
  • BUG: Make sure to only render the preview in read only mode (Feature: Add support for mermaid diagrams collectives#284)
  • Make preview the default and call it Diagram
  • Use NcActions Edit button -> floating on the top right, move language selector to the menu

Follow up tickets

  • Custom mermaid theme
  • Ctrl-A in code block should probably only select the code block
  • Clear preview if code block gets emptied
  • Cypress tests

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits
  • Tests (unit, integration and/or end-to-end) passing and the changes are covered with tests
  • Documentation (README or documentation) has been updated or is not required

@cypress
Copy link

cypress bot commented Jul 31, 2023

2 flaky tests on run #11528 ↗︎

0 149 2 0 Flakiness 2

Details:

feat: Add support for mermaid.js rendering
Project: Text Commit: a1b711687c
Status: Passed Duration: 07:41 💡
Started: Aug 7, 2023 12:56 PM Ended: Aug 7, 2023 1:04 PM
Flakiness  nodes/FrontMatter.spec.js • 1 flaky test

View Output Video

Test Artifacts
Front matter support > Add front matter Output Screenshots
Flakiness  api/SyncServiceProvider.spec.js • 1 flaky test

View Output Video

Test Artifacts
Sync service provider > recovers from a dropped message Output Screenshots

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@juliusknorr
Copy link
Member Author

@nextcloud/designers Do you have any suggestions to make the UI a bit nicer here?

@juliusknorr juliusknorr added enhancement New feature or request 2. developing labels Jul 31, 2023
@juliusknorr juliusknorr force-pushed the feat/mermaid branch 4 times, most recently from 2da2c63 to 5317b4e Compare August 2, 2023 12:30
Copy link
Member

@jancborchardt jancborchardt left a comment

Choose a reason for hiding this comment

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

Looks nice! Some enhancements for the diagram style:

  • It is purple now, could instead use the primary color: primary-light for bg, primary for the border
  • The text in the boxes doesn’t look vertically aligned but a bit too far up / too much bottom padding
  • Boxes could use border-radius (3px default), might look nicer and Nextcloud-y
  • The Yes/No boxes in the example could use some more padding
  • If it makes sense, the Yes/No text can also be bold? Or is the other stuff more important? (Either way maybe makes sense to bold one of the types)

@nimishavijay
Copy link
Member

nimishavijay commented Aug 2, 2023

Super cool! :) 🎉 It looks great! Agreed with Jan's visual changes, and I'm also wondering if we can just change this to "Insert flowchart" as a separate formatting option and link to the mermaid language documentation for help with the syntax? so not have it as a part of the code block option. It can insert an example flowchart so people have something to start with. What do you think? :)

@juliusknorr
Copy link
Member Author

juliusknorr commented Aug 2, 2023

Looks nice! Some enhancements for the diagram style:

I'll see how far we can influence the diagram rendering, but this might be more complex if we need to provide a custom theme: https://mermaid.js.org/config/theming.html

Would you consider this a blocker or just nice to have?

Super cool! :) 🎉 It looks great! I'm wondering if we can just change this to "Insert flowchart" as a separate formatting option and link to the mermaid language documentation for help with the syntax? :) so not have it as a part of the code block option, but a separate option :)

Mermaid supports all kinds of charts, but we could add a separate option "Insert diagram" with #4587 though I'd keep this as a follow up then. For the syntax documentation that seems like a nice suggestion.

@nimishavijay
Copy link
Member

That works! Adding a separate option would be great to increase visibility for such a cool feature.
Also one other small change: instead of "Side by side" we could change the wording to "Both", as on mobile the horizontal space would be quite less and we should show them below one another.

@juliusknorr
Copy link
Member Author

Theming is more complex as we'd need to set matching colors for all possible diagram formats and ideally also adapt them to the theme color from Nextcloud, so nothing we can easily achieve within the planned timeline.

@mejo-
Copy link
Member

mejo- commented Aug 2, 2023

Looks really nice and I'm looking forward to use this myself 😊

Regarding the menu icon, I wonder whether it would be better to have a static one to avoid confusion and mark the selected view (Source code, Both or Diagram) as highlighted in the menu.

Personally I find it confusing that clicking on an eye icon allows me to change to source code view and the other way round.

We could use the Pencil icon (that we use for editing buttons) to open the menu, what do you think?

@mejo-
Copy link
Member

mejo- commented Aug 2, 2023

Also, how about secondary button style for the menu button? Right now it looks a bit lost in the whitespace 😬

Or we set the --color-background-dark for the view mode of mermaid diagrams as well?

2023-08-02T18:29:43,265329853+02:00

@juliusknorr
Copy link
Member Author

The edit button seems more fitting indeed, but would probably not fit to indicate switching from edit to diagram view or in the regular code block to change the language.

Will think a bit about that, further input still welcome of course :)

@juliusknorr
Copy link
Member Author

My suggestion would be:

  • In diagram view mode -> show the edit icon
  • In split mode -> show the split icon
  • In code mode -> show the view icon
  • In the regular code block -> show the curly braces icon as it probably fits the language setting best

@juliusknorr juliusknorr force-pushed the feat/mermaid branch 2 times, most recently from fff7d2d to 1a2d594 Compare August 7, 2023 08:55
Copy link
Member

@mejo- mejo- left a comment

Choose a reason for hiding this comment

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

Just minor comments, otherwise looks good 😊

I wonder whether we should backport the setEditable() and defaultLanguage: 'plaintext' fixes to stable26 and stable27.

src/nodes/CodeBlockView.vue Outdated Show resolved Hide resolved
src/nodes/CodeBlockView.vue Show resolved Hide resolved
@juliusknorr
Copy link
Member Author

/compile

Signed-off-by: nextcloud-command <[email protected]>
@juliusknorr juliusknorr merged commit c11f7ad into main Aug 7, 2023
30 checks passed
@juliusknorr juliusknorr deleted the feat/mermaid branch August 7, 2023 14:46
@mejo-
Copy link
Member

mejo- commented Aug 8, 2023

/backport b9ea43f,62f5d3e846b604a9e7576f5b9eae85bdd82fba1f,6a8b01fa57d9ba253607257262d8c56cd7ee21ec,946ca9bcba925b9bca8809538a069d67c2303d73 to stable27

@backportbot-nextcloud
Copy link

The backport to stable27 failed. Please do this backport manually.

# Switch to the target branch and update it
git checkout stable27
git pull origin stable27

# Create the new backport branch
git checkout -b fix/foo-stable27

# Cherry pick the change from the commit sha1 of the change against the default branch
# This might cause conflicts. Resolve them.
git cherry-pick abc123

# Push the cherry pick commit to the remote repository and open a pull request
git push origin fix/foo-stable27

More info at https://docs.nextcloud.com/server/latest/developer_manual/getting_started/development_process.html#manual-backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LaTeX and Mermaid chart support
5 participants