Help - Adding Class using formatInline/formatBlock for Font Family
See original GitHub issueHey 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:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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
currently classes test does not allow regexp for validity check unfortunately.
@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.