Customizing blockquote styling in QuillJS with a unique class

Currently, I am exploring a method to include a custom class when the user selects the blockquote toolbar button. When the blockquote is clicked, it generates the following element:

<blockquote class="ql-align-justify">this is my quoted text</blockquote>

I intend to append .blockquote to the existing class like this:

<blockquote class="ql-align-justify blockquote">this is my quoted text</blockquote>

My current approach involves adding a handler, although there appears to be limited documentation on how to implement this:

 this.editor = new Quill(this.$refs.editor, this.editorOptions)
 // Handlers can also be added post initialization
 var toolbar = this.editor.getModule('toolbar');
 toolbar.addHandler('blockquote', function(value) {
    //todo: working on adding the blockquote class to blockquotes.
    console.log('blockquote called');
    console.log('value:');
    console.log(value);

    if (value) {
       this.quill.format('blockquote');
    }

 });

Answer №1

It doesn't seem like handlers are capable of this task (at least not to my knowledge)

However, you have the option to customize the BlockQuote format, granting you complete control over the node. This allows you to add classes or even a click handler.

The blockquote format can be modified using this code:

const BlockQuote = Quill.import('formats/blockquote');

To implement changes, simply follow these steps:

  const BlockQuote = Quill.import('formats/blockquote');

  class CustomBlockQuote extends BlockQuote {
    static create(value) {
      const node = super.create(value);
      node.classList.add('test');
      return node;
    }
  }

You can adjust the tag name and blot name as desired:

  CustomBlockQuote.blotName = 'custom-blockquote';
  CustomBlockQuote.tagName = 'blockquote';

If you prefer a simpler method for changing only the class:

  class CustomBlockQuote extends BlockQuote {}
  CustomBlockQuote.blotName = 'custom-blockquote';
  CustomBlockQuote.tagName = 'blockquote';
  CustomBlockQuote.className = 'custom-class-name';
  Quill.register(CustomBlockQuote, true);

An example demonstrating this approach has been set up on jsfiddle: https://jsfiddle.net/hassansalem/095mh3fn/4/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to selectively import specific modules in three.js using ES6 syntax

I recently integrated the three.js library using NPM with the goal of leveraging its new ES6 modular architecture. This design allows for selective importation of specific modules as outlined in this resource: Threejs - Import via modules. For bundling an ...

Trigger a method within a component when there is a change in the Vuex state

I need to trigger a method inside a component whenever the vuex state changes in TypeScript and Vue.js. While I can access the vuex state value using getters in the template, I am unsure how to access the data within the component class. The vuex state is ...

Can you explain the distinction between these two Redux reducer scenarios?

While looking at someone else's code for a reducer, I noticed this snippet: export default function reducer(state, action) { switch(action.type) { case 'ADD_TODO': Object.assign({}, state, { ...

What is the process for programmatically importing a module into the local scope in Node.js?

The coding environment is using a browser and the bundle tool being used is webpack. In my router.js file, I have the following code: import foo from './views/foo.vue' import bar from './views/bar.vue' import zoo from './views/zoo. ...

Interactive image rotator featuring navigation buttons for next and previous slides

I recently followed a tutorial from W3Schools Now, I am looking to enhance it by adding previous / next buttons for the indicators, rather than for the slider itself Here is what I aim to accomplish: https://i.sstatic.net/qH1PQ.png Below is the code sn ...

Buefy fails to respond to Sass styling efforts

Hey there, I'm new to Vue and I've set up a simple Vue (2) app with node-sass and sass-loader following the instructions here. I have Buefy imported in main.js and below is an excerpt from my App.vue file: <style lang="scss"> // ...

Once an email address is entered, kindly instruct the driver to press the tab key twice for navigation

Adding a user to a website involves entering an email address first, which is then checked against the server's list of users. However, the issue arises when the email validation doesn't occur until clicking outside the input box or pressing tab ...

Personalized jQuery Slider with automatic sliding

I am currently working on creating my own image slider without relying on plugins. 1st inquiry : How can I achieve horizontal animation for the slider? 2nd inquiry : I want the images to cover both the height and width of their container while maintainin ...

Exploring the attributes and functions of JavaScript Objects in an Angular environment

Can Angular's $http.post method recognize JavaScript object properties when sending data? To understand more about JavaScript objects and their properties, visit https://www.w3schools.com/js/js_objects.asp. Here is an example to illustrate my questio ...

Reading and extracting data from a massive XML document using Node.js

Currently, I am facing a challenge with an XML file that is quite large - exceeding 70mb. My goal is to parse this data in Node.js for potential data visualizations down the line. After giving it some thought, I decided that converting the XML file to JSON ...

Utilizing JavaScript's Facebook Connect feature on a Ruby on Rails website

My ruby-on-rails web application is in need of integrating "Facebook connect" functionality to enable users to share various activities on Facebook. Are there any Javascript methods I can use for this purpose? Any demos you can suggest? In addition, I wou ...

Issue with Vue Checkbox not functioning properly upon being mounted in Edge browser

Currently, I am developing a Vue page with a checkbox that needs to read a value from a cookie upon mounting. However, I have observed that in the Edge browser, the checkbox does not get set correctly even though the Mounted function is definitely being ca ...

Having a Jquery resizing problem? No worries! When the width is less than 768, simply enable the click option. And when the width is

HTML <div class="profile"> <a href="#" class="hoverdropdown" onclick="return false;">Profile</a> <ul class="dropdown" style="display: none;"> <li><a href="#">Dashboard&l ...

Guide on setting up Tailwind CSS and material-tailwind concurrently within the tailwind.config.js configuration file

I am looking to integrate both Tailwind and Material Tailwind in a Next.js 14 project. Below is my customized tailwind.config.ts file (already configured with Tailwind CSS): import type { Config } from 'tailwindcss' const config: Config = { ...

Expo + tRPC: Oops! Looks like the application context couldn't be retrieved. Don't forget to wrap your App inside the `withTRPC` HoC for

I'm currently working on a straightforward tRPC server setup: // server.ts import { initTRPC } from "@trpc/server"; import { z } from "zod"; const t = initTRPC.create(); export const appRouter = t.router({ greeting: t.procedu ...

What could be causing the issue with the navigation circles on my carousel not updating when clicked?

I created my own carousel from scratch and it's working perfectly fine except for one issue - clicking on the navigation circles. When using the interval/infinite loop prop, the circles update to the correct active slide as expected. The same goes fo ...

Challenges encountered when implementing a personal library in a separate project

After updating a library I own, I seem to have encountered an issue when trying to use it in another project. However, the reason for this problem eludes me. A multitude of error logs with a similar theme are appearing: ERROR in ./node_modules/@company-na ...

Get only the text content from a hyperlink using Tinymce-4

Within tinymce.activeEditor, I currently have this line of innerHTML code (part of a ul-list): <li><a href="#">Important words</a></li> When I place the caret within the sentence "Important words," and click a button with the foll ...

use ajax to dynamically append a dropdown menu

Currently working on creating a form that includes a dropdown menu populated with elements from a database. The challenge I'm facing is ensuring that once an element is selected from the dropdown, another one appears dynamically. My goal is to use AJA ...

using node and express to route and pass variables to a required module

In my primary index.js file, I have the following code: var express = require('express') require("dotenv").config(); const db = require('./services/db_service').db_connection() const customers = require('./routes/custo ...