TinyMCE Advanced theme - Where is it?

非 Y 不嫁゛ 提交于 2019-12-04 01:39:55

OK, I found out where the confusion lies.

TinyMCE versions 3.x contain the advanced theme but it is not shipped with 4.0 which I am using. I did download 3.x and try the advanced theme with 4.0 but it isn't compatible. Wordpress it seems ships with 3.x which is why I thought it was a wordpress only option.

For more info (hoping it helps someone else):

It seems now that you have to use the format_styles and custom_formats options against the TinyMCE editor to give users the ability to select styles. I have written some code that parses my CSS file, looks for all H2, 2 etc, P and A classes and populates those options. It's the long way round but it works very well. It' just a shame there is no out of the box routine.

I ended up using CssParser with the following code (C# - Copy pasting this won't work but it should give a good guide on what to do):

//Declared so we can deserialise into JSON
public class CustomFormat
{
    public string title;
    public string selector;
    public string classes;
}

private void BuildTinyMCECSS()
{
    List<string> AllowedTags = new List<string> { "p", "a", "h1", "h2", "h3", "h4", "h5", "h6" };
    CssParser StyleSheet = new CssParser();
    StyleSheet.AddStyleSheet("MyPath/Styles.css");

    //1: Only in our allowed tags. 2: Isn't a pseudo class. 3: Is a class of one of the allowed tags.
    foreach (KeyValuePair<string, StyleClass> Style in StyleSheet.Styles.Where(n => AllowedTags.Any(a => n.Key.StartsWith(a) && !n.Key.Contains(':') && n.Key.Contains('.'))))
    {
        CustomFormat CF = new CustomFormat();
        CF.title = Style.Key;
        CF.selector = Style.Key.Substring(0, Str.IndexOf('.'));
        CF.classes = Style.Key.Substring(Style.Key.IndexOf('.') + 1);

            //Note: CCUtils is a static class I use for utilities. Any code to deserialise will work
        string JS = String.Format("{1},", Style.Key, CCUtils.SerializeToStringJSON(CF, typeof(CustomFormat)));
        Session["JS"] += JS;
    }
    //Remove the spare comma at the end (ie won't like it)
    Session["JS"] = Session["JS"].ToString().Substring(0, Session["JS"].ToString().LastIndexOf(','));
}

My init code for style_formats looks like this (note, I have to re-add the default options as adding anything into style_format clears it's existing list.

style_formats:
[{
    title: "Headers",
    items: [{title: "Header 1",format: "h1"}, {title: "Header 2",format: "h2"}, {title: "Header 3",format: "h3"}, {title: "Header 4",format: "h4"}, {title: "Header 5",format: "h5"}, {title: "Header 6",format: "h6"}]}, 
            {title: "Inline",items: [{title: "Bold",icon: "bold",format: "bold"}, {title: "Italic",icon: "italic",format: "italic"}, 
            {title: "Underline",icon: "underline",format: "underline"}, {title: "Strikethrough",icon: "strikethrough",format: "strikethrough"}, {title: "Superscript",icon: "superscript",format: "superscript"}, {title: "Subscript",icon: "subscript",format: "subscript"}, {title: "Code",icon: "code",format: "code"}]}, 
            {title: "Blocks",items: [{title: "Paragraph",format: "p"}, {title: "Blockquote",format: "blockquote"}, {title: "Div",format: "div"}, {title: "Pre",format: "pre"}]}, 
            {title: "Alignment",items: [{title: "Left",icon: "alignleft",format: "alignleft"}, {title: "Center",icon: "aligncenter",format: "aligncenter"}, {title: "Right",icon: "alignright",format: "alignright"}, {title: "Justify",icon: "alignjustify",format: "alignjustify"}]}, 
            {
    title: "Classes", items: [<%= Session["JS"] %>]
}]

More information on the style_formats option can be found here: TinyMCE Style Formats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!