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(gsoc'24): minimal markdown editor using simplemde #26

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

Waishnav
Copy link

@Waishnav Waishnav commented Jul 7, 2024

Fixes #15

This PR's covers following functionality

  • added the markdown editor using SimpleMDE

Screenshots:

Client side post drafting Server rendered post
image image

Summary by CodeRabbit

  • New Features

    • Introduced a new rich text editor (SimpleMDE) for enhanced text formatting and real-time previews in discussion posts.
    • Added improved styling for discussion elements and code snippets to enhance readability and visual hierarchy.
  • Bug Fixes

    • Updated form structures for better integration with the SimpleMDE editor, improving functionality.
  • Chores

    • Cleaned up code by removing commented-out lines and unnecessary HTML elements to streamline the user interface.

@Waishnav Waishnav marked this pull request as ready for review July 22, 2024 18:41
@Waishnav Waishnav force-pushed the markdown-editor branch 2 times, most recently from e042dc4 to 94dba46 Compare July 28, 2024 17:48
Copy link
Member

@tanmoysrt tanmoysrt left a comment

Choose a reason for hiding this comment

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

Except that pr looks good.

app/views/simple_discussion/forum_posts/_form.html.erb Outdated Show resolved Hide resolved
@Waishnav
Copy link
Author

@tanmoysrt do you think, this feature also needs to have feature flag to enable and disable it from initilizer file?

@tanmoysrt
Copy link
Member

Except that pr looks good.

@tanmoysrt do you think, this feature also needs to have feature flag to enable and disable it from initilizer file?

any specific reason for flag for markdown editor ?

there should be no issue in main repo after merge until unless we update the gemfile.lock.

@Waishnav
Copy link
Author

any specific reason for flag for markdown editor ?

Basically one can toggle this markdown editor according to their usecase. They may need just simple textarea without markdown editor.

Copy link

coderabbitai bot commented Aug 23, 2024

Walkthrough

The changes introduce a Markdown editor using SimpleMDE into the application, enhancing the user interface for forum posts and threads. The implementation includes updates to relevant HTML forms and JavaScript controllers to manage the editor, along with CSS enhancements for better styling. The integration allows users to format text and preview content while improving the overall structure and functionality of the discussion threads.

Changes

Files Change Summary
app/assets/stylesheets/simple_discussion.scss Added CSS styles for .simple_discussion and .CodeMirror, enhancing typography and blockquote presentation.
app/views/layouts/simple_discussion.html.erb Integrated SimpleMDE editor with a new Stimulus controller, including external CSS and JS files for enhanced functionality.
app/views/simple_discussion/forum_posts/_form.html.erb Updated form for forum posts to integrate with SimpleMDE, adding a controller attribute and adjusting the text area.
app/views/simple_discussion/forum_threads/_form.html.erb Enhanced the forum threads form with a new controller attribute for SimpleMDE integration and updated text area attributes.
app/views/simple_discussion/forum_threads/_forum_thread.html.erb Removed block displaying the first post content from the forum thread view.
app/views/simple_discussion/forum_threads/show.html.erb Minor formatting change in HTML for improved readability.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant View
    participant SimpleMDE
    participant Controller

    User->>View: Open forum post creation
    View->>Controller: Initialize SimpleMDE
    Controller->>SimpleMDE: Load editor
    User->>SimpleMDE: Edit post content
    SimpleMDE-->>User: Provide rich text formatting
    User->>View: Submit post
    View->>Controller: Handle submission
Loading

Assessment against linked issues

Objective Addressed Explanation
Adding basic markdown editor using SimpleMDE ( #15 )
Improving UX for tagging user, embedding video, embedding circuit ( #15 ) No information on whether these specific functionalities were implemented.

A little bunny hops with delight,
For Markdown edits brought to light.
With SimpleMDE, oh what a treat,
Our forum posts are now so neat!
Hooray for rich text, full of charm,
A joyful leap, no cause for alarm! 🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tachyons
Copy link
Member

tachyons commented Aug 23, 2024 via email

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 470e204 and 4878c94.

Files selected for processing (6)
  • app/assets/stylesheets/simple_discussion.scss (1 hunks)
  • app/views/layouts/simple_discussion.html.erb (3 hunks)
  • app/views/simple_discussion/forum_posts/_form.html.erb (2 hunks)
  • app/views/simple_discussion/forum_threads/_form.html.erb (2 hunks)
  • app/views/simple_discussion/forum_threads/_forum_thread.html.erb (1 hunks)
  • app/views/simple_discussion/forum_threads/show.html.erb (1 hunks)
Files skipped from review due to trivial changes (2)
  • app/views/simple_discussion/forum_threads/_forum_thread.html.erb
  • app/views/simple_discussion/forum_threads/show.html.erb
Additional comments not posted (10)
app/views/simple_discussion/forum_posts/_form.html.erb (2)

4-4: Ensure the controller is correctly initialized.

The addition of the controller: "simplemde" attribute suggests integration with the SimpleMDE editor. Verify that the controller is correctly initialized and functioning as expected.


16-16: Update the text_area configuration.

The simplemde_target data attribute is used to target the text area for the SimpleMDE editor. Ensure that this configuration aligns with how the editor is initialized and used in the application.

app/views/simple_discussion/forum_threads/_form.html.erb (2)

3-3: Ensure the controller is correctly initialized.

The addition of the controller: "simplemde" attribute suggests integration with the SimpleMDE editor. Verify that the controller is correctly initialized and functioning as expected.


27-27: Update the text_area configuration.

The simplemde_target data attribute is used to target the text area for the SimpleMDE editor. Ensure that this configuration aligns with how the editor is initialized and used in the application.

app/views/layouts/simple_discussion.html.erb (2)

79-80: Verify external resource loading.

The SimpleMDE CSS and JS files are loaded from a CDN. Ensure these resources are accessible and consider hosting them locally if necessary for better control and reliability.


123-160: Review the SimpleMDE controller implementation.

The Stimulus controller for SimpleMDE is responsible for initializing the editor and configuring its toolbar. Ensure that the toolbar options meet the application's requirements and that the editor is correctly initialized for all targeted text areas.

app/assets/stylesheets/simple_discussion.scss (4)

300-303: Verify the usage of the .preview class.

Ensure that the .preview class is used appropriately and does not conflict with other elements.

Run the following script to verify the usage of the .preview class:

Verification successful

The .preview class is used appropriately.

The .preview class is correctly used in the HTML file and styled in the SCSS file without any conflicts or issues identified. The ::before pseudo-element adds a "Preview" label, which aligns with its usage in the codebase.

  • Location of usage:
    • app/views/layouts/simple_discussion.html.erb
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `.preview` class.

# Test: Search for the `.preview` class usage. Expect: Occurrences in relevant HTML or templates.
rg --type css --type html --type erb --type js '\.preview'

Length of output: 233


320-321: Verify the impact of the font size change for .CodeMirror-line span.

Ensure that the font size change to 18px does not cause layout issues or inconsistencies.

Run the following script to verify the impact of the font size change:

Verification successful

Font size change is isolated and verified.

The change to set the font size to 18px for .CodeMirror-line span is isolated to the simple_discussion.scss file, with no other dependencies or references in the codebase. This indicates that the change is unlikely to cause layout issues or inconsistencies.

  • Location: app/assets/stylesheets/simple_discussion.scss
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the font size change for `.CodeMirror-line span`.

# Test: Search for the usage of `.CodeMirror-line span`. Expect: Consistent styling across components.
rg --type css --type html --type erb --type js '\.CodeMirror-line span' -A 5

Length of output: 261


310-318: Verify the styling of blockquote elements.

Ensure that the blockquote styling enhances readability and aligns with design guidelines.

Run the following script to verify the styling of blockquote elements:


305-307: Verify the impact of the font size change.

Ensure that the font size change to 18px does not cause layout issues or inconsistencies.

Run the following script to verify the impact of the font size change:

Verification successful

Font Size Change Impact Verified

The font size change to 18px for .simple_discussion .forum-post p and .CodeMirror p appears to be isolated to the simple_discussion.scss file, with no other references found in the codebase. This suggests that the change is unlikely to cause layout issues or inconsistencies.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the font size change to 18px.

# Test: Search for the usage of `.simple_discussion .forum-post p` and `.CodeMirror p`. Expect: Consistent styling across components.
rg --type css --type html --type erb --type js '\.simple_discussion \.forum-post p' -A 5
rg --type css --type html --type erb --type js '\.CodeMirror p' -A 5

Length of output: 934


Script:

#!/bin/bash
# Description: Comprehensive search for the usage of `.simple_discussion .forum-post p` and `.CodeMirror p` across all file types.

# Test: Search for the usage of `.simple_discussion .forum-post p` and `.CodeMirror p` in all file types to ensure comprehensive coverage.
rg '\.simple_discussion \.forum-post p' -A 5
rg '\.CodeMirror p' -A 5

Length of output: 846

Copy link

coderabbitai bot commented Aug 23, 2024

Tip

For best results, initiate chat on the files or code changes.

@tachyons Here are the unit and integration tests for the SimpleMDE markdown editor feature:

Unit Tests

These tests will verify the initialization and configuration of the SimpleMDE editor.

// Assuming you are using a JavaScript testing framework like Jest

describe('SimpleMDE Initialization', () => {
  let editor;

  beforeEach(() => {
    document.body.innerHTML = '<textarea id="editor"></textarea>';
    editor = new SimpleMDE({
      element: document.getElementById('editor'),
      forceSync: true,
      toolbar: ["bold", "italic", { name: "preview", action: SimpleMDE.togglePreview }],
      spellChecker: false,
    });
  });

  test('should initialize SimpleMDE with correct options', () => {
    expect(editor.options.forceSync).toBe(true);
    expect(editor.options.spellChecker).toBe(false);
    expect(editor.options.toolbar.length).toBe(3);
  });

  test('should attach SimpleMDE to the correct element', () => {
    expect(editor.element).toBe(document.getElementById('editor'));
  });
});

Integration Tests

These tests will ensure that the editor interacts correctly with the form elements.

// Assuming you are using a testing framework like Cypress for integration tests

describe('SimpleMDE Integration', () => {
  beforeEach(() => {
    cy.visit('/path-to-your-form-page');
  });

  it('should sync content with textarea', () => {
    cy.get('.editor-toolbar button').contains('Bold').click();
    cy.get('textarea').should('contain.value', '**');
  });

  it('should toggle preview mode', () => {
    cy.get('.editor-toolbar button').contains('Preview').click();
    cy.get('.editor-preview').should('be.visible');
  });
});

These tests should cover the basic functionality of the SimpleMDE editor in your application. Adjust the paths and selectors according to your actual implementation.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the initialization and usage of SimpleMDE in the relevant files.
rg 'SimpleMDE' -A 5

Length of output: 862

@Waishnav
Copy link
Author

@tachyons will we able to add the jest testing without introducing any js tooling(webpack and esbuild)?
I don't think it is possible?

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.

Markdown Editor support
3 participants