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

Bold format. How replace <strong> tag with <span> wich has inline style 'font-weight: 700;' #3997

Open
mikeKlech opened this issue Feb 5, 2024 · 1 comment

Comments

@mikeKlech
Copy link

mikeKlech commented Feb 5, 2024

I want to replace tag with wich has inline style 'font-weight: 700;'

Is it possible?

My workaround is here, but it does not work on iphone(when use mobile formatting)

class CustomBold extends Inline {
        static blotName = 'bold';
        static tagName = 'SPAN';
        static create(value: string) {
            const node = super.create(value) as HTMLSpanElement;
            node.style.fontWeight = '700';
            return node;
        }
        static formats(domNode: HTMLSpanElement) {
            return domNode.style.fontWeight === '700' ? true : false;
        }
        format(name: string, value: boolean) {
            if (name === 'bold') {
                this.domNode.style.fontWeight = value ? '700' : '400';
            } else {
                super.format(name, value);
            }
        }
        formats() {
            let formats = super.formats();
            formats['bold'] = CustomBold.formats(this.domNode);
            return formats;
        }
}
@klwerklwer
Copy link

const { parchment } = Quill.imports
const {
	StyleAttributor,
	Scope
} = parchment

class CustomBoldAttributor extends StyleAttributor{
	constructor(){
	    return super( 'bold' , 'bold' ,{
			scope: Scope.INLINE,
		})
	}

	value( node ){
		return node.style.fontWeight
	}

	add( node , value ){
		node.style.fontWeight = value ? "bold" : ""
		return true
	}

	remove( node ){
		node.style.fontWeight = ""
	}
}

//local registry
const registry = new parchment.Registry
registry.register( new CustomBoldAttributor , true )

//global registry
Quill.register( new CustomBoldAttributor , true )

may work

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

2 participants