question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help - Adding Class using formatInline/formatBlock for Font Family

See original GitHub issue

Hey guys,

This isn’t a bug, but need some advice, trying to create a simple ‘addClass’ command so that I can do font family. I’ve been trying to find some documentation somewhere on the best way to do font family but can’t really find anything reliable, so I’ve come up with the following;

wysihtml5.commands.addClass = {
            exec: function(composer, command, className) {
                var r = new RegExp("/" + className + "/", 'g')
                return wysihtml5.commands.formatBlock.exec(composer, 'formatBlock', {nodeName: 'span', className: className, classRegExp: r, toggle:true});
            },
            state: function(composer, command, className) {
                var r = new RegExp("/" + className + "/", 'g')
                return wysihtml5.commands.formatBlock.state(composer, 'formatBlock', {nodeName: 'span', className: className, classRegExp: r, toggle:true});
            }
        };

This manages to put the selection into a span with the class, but it keeps nesting spans with the classes i.e.

This could just be related to @cristianbell problem here; https://github.com/Voog/wysihtml/issues/188

Any advice here would be really appreciated.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
pulgescommented, May 11, 2016

@Dayjo Trying to explain:

one_of_type is an option to pass as tests (defined above in file under “type_definitions”). If all of the type tests fail element gets removed or unwrapped (defined by “remove_action”:“unwrap” here). (these not needed for the font class logic as they define currently only class or inline style color spans to be kept. If the color is also used a type for font names may be added)

keep styles defines what inline css styles to keep. If your editor does not use inline styles to add colors or other things this part can be discarded too

classes: “any” means all classes are allowed and kept. If you want to make the cleanup strict you can list allowed classes of your fonts and whatever is needed as an object

"classes": {
            "ff-verdana": 1,
            "ff-arialt": 1
};

currently classes test does not allow regexp for validity check unfortunately.

0reactions
Dayjocommented, May 16, 2016

@cristianbell thanks! Yeah the bottom issue (5) I had, only way I could see to do it was to have “classes”: “any” so the ability to use regex here would be grand.

Read more comments on GitHub >

github_iconTop Results From Across the Web

font-family - CSS: Cascading Style Sheets - MDN Web Docs
The font-family property specifies a list of fonts, from highest priority to lowest. Font selection does not stop at the first font in...
Read more >
How to get font family from other class? - Stack Overflow
i have two elements with different class and have option panel to change font family. but one element does not have any option...
Read more >
How To Load and Use Custom Fonts with CSS | DigitalOcean
But first, you will create example HTML to demonstrate the fonts. Begin by opening index.html in your text editor. Then, add the following...
Read more >
Add custom fonts to your training site with CSS - Skilljar Support
To find a font and retrieve the font-specific code block: Choose the font(s) or font families you'd like to use in your training...
Read more >
How to use @font-face in CSS
The @font-face rule allows custom fonts to be loaded on a webpage. Once added to a stylesheet, the rule instructs the browser to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found