【问题标题】:TinyMCE Advanced theme - Where is it?TinyMCE 高级主题 - 它在哪里?
【发布时间】:2013-06-19 17:13:46
【问题描述】:

我正在创建一个包含类列表的下拉列表,以便我的用户可以将它们应用于链接、段落等。我已经在很多地方阅读了 advanced 主题支持这一点盒子,但我找不到在哪里下载这个主题。

我怀疑高级主题只是在这一点上是 Wordpress,因为我发现它包含在 wordpress 下载中,但不是以允许我使用它的格式。

我错过了什么吗?

【问题讨论】:

  • @Thariama - 谢谢,我发现了这方面的困惑,并在下面回答。

标签: tinymce tinymce-4


【解决方案1】:

好的,我发现了困惑的所在。

TinyMCE 版本 3.x 包含 advanced 主题,但我使用的 4.0 未附带它。我确实下载了 3.x 并尝试了 4.0 的高级主题,但它不兼容。 Wordpress 似乎随 3.x 一起提供,这就是为什么我认为它是 wordpress 唯一的选项。

更多信息(希望对其他人有所帮助):

现在看来,您必须对 TinyMCE 编辑器使用 format_stylescustom_formats 选项才能让用户能够选择样式。我编写了一些代码来解析我的 CSS 文件,查找所有 H2, 2 etcPA 类并填充这些选项。这是很长的路要走,但效果很好。可惜没有开箱即用的例程。

我最终使用CssParser 和以下代码(C# - 复制粘贴这行不通,但它应该提供一个很好的指导):

//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(','));
}

style_formats 的初始化代码如下所示(注意,我必须重新添加默认选项,因为将任何内容添加到 style_format 会清除它的现有列表。

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"] %>]
}]

更多关于style_formats选项的信息可以在这里找到:TinyMCE Style Formats

【讨论】:

    猜你喜欢
    • 2014-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-09
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多