MD Composer 附加内容

Is it possible to move the Build Poll option (on desktop) out of the extra menu and next to the rest of the formatting buttons?

Like your request on mobile, it requires a bit more complex editing, that I can’t add on this theme component. But it should be doable on a custom component for desktop following the logic presented by angus and spirobel.

3 个赞

How would one remove the center and align left + right buttons?

love this component by the way.

Hi!

You can add these css lines in your theme or in a component:

.align_center_button, .align_right_button, .align_justify_button {
    display: none;
}

I guess you meant justify button, since align left has not been added in the same component

1 个赞

Is it possible to move all of these new buttons within the Options button/menu?

It’s possible but you’d need to dig in the code a little bit

In the Desktop > Head you’ll have all the javascript, you need to change a few lines.

Example the code for a button in the toolbar looks like this

api.onToolbarCreate(toolbar => {
    toolbar.addButton({
        id: "underline_button",
        group: "fontStyles",
        icon: "underline",
        perform: e => e.applySurround('[u]', '[/u]', 'underline_text')
    });
});

You need to change by using this

api.addToolbarPopupMenuOptionsCallback(() => {
  return {
      action: "underline",
      icon: "underline",
      label: "underline_button"
  };
});

And add the action in this part:

api.modifyClass("controller:composer", {
  actions: {
    underline() {
      this.get("toolbarEvent").applySurround('[u]', '[/u]', "underline_text");
    },
    floatleft() {
      this.get("toolbarEvent").applySurround('[wrap="floatl"]\n', '\n[/wrap]', "float_left_text");
    },
    columns() {
      this.get("toolbarEvent").applySurround('[wrap="columns"]\n', '\n[/wrap]', "columns_text");
    }
  }
});

The translation should be ok

You’ll quickly see if anything is wrong since Discourse give some error message when you save the changes.

5 个赞

Great component @Steven
Would be awesome if we could also have H1, H2 and H3

2 个赞

Can the [color] [/color] be added to this theme component? If it can, then it would be perfect because then one can use the official discourse bbcode+md composer. I’m currently using formatting toolbar + mdcomposer. Sure I can use CSS to hide the extra buttons, but there are places where CSS is not used like in the admin panel or pavilion’s Custom Wizard plugin. The color button is used a lot.

This is what I have with CSS: (which is perfect)

This is what I have without:

1 个赞

My plan is to have a component for people who don’t want to have a plugin. But I’ll make a branch with color bbcode. I’ll try it in a few hours if I have the time. I’ll let you know when it’s ready and how to install

I’ll probably use the time to reorganize the theme component, I prefer a simple tc by default, I’ll use a all-options branch with subscript buttons, a bbcode branch for those who have official bbcode plugin

2 个赞

Thanks, the subscript/superscript buttons is one of the reasons to keep using md composer which other plugins and theme components lack. The official bbcode has many things included that are not in the formatting toolbar plugin like the [spoiler] [/spoiler]. To have best of both worlds, I think it’s better to keep the discourse bbcode and then add the buttons we need through mdcomposer.

I didn’t think the script buttons were popular, I’ll keep them in the base component.

I’ll do a few branch, a simple one with only some basic formatting buttons, color branch that adds a color bbcode

2 个赞

Hey guys,

Just wanted to let you know that a new color branch has been added to the md composer. Now you can use the official discourse bbcode plugin + md composer (color branch) + discourse spoiler-alert (blur spoilers). I believe that this is the best combo available for composer buttons on Discourse.

There’s also an idea of adding a color picker using this free library:

https://github.com/Simonwep/pickr

If anyone wants to help and knows how to add a color picker, feel free to help Steven out!

2 个赞

How would I completely hide or remove some of these buttons? We only need a few of them and I noticed removing a button will not removing the item being still listed (it will still be a blank space with no visible icon).

The best way is to add some css lines in your current theme

I gave these examples for the align buttons, if you want to get rid of them

.align_center_button, .align_right_button, .align_justify_button {
    display: none;
}

I can also give you the css code for the specific buttons you want hidden

5 个赞

史蒂文,你好,很棒的组件。感谢分享!

有个小问题:是否可以添加一些按钮来插入不间断空格(例如 nbsp ; ensp ; emsp?我应该用什么代替 applySurround?

我的社区里有些成员在格式化帖子(主要是缩进)时遇到困难,我认为这对他们会有帮助。

谢谢!

是的,您可以轻松地添加一个按钮,并且使用 addText 而不是 applySurround

我有一个旧示例供您参考:

api.onToolbarCreate(toolbar => {
    toolbar.addButton({
        id: "br_button",
        group: "extras",
        icon: "level-down-alt",
        perform: e => e.addText('<br>', 'br_text')
    });
});
3 个赞

太好了!这招管用!

嗯……你的 Discourse Formatting Toolbar 中似乎没有删除线,但这里有。我更喜欢 Formatting Toolbar,因为它包含其他所有功能,甚至更多,但我希望删除线也能作为一个选项。考虑到这两者之间的兼容性问题,你有什么建议吗?

我可以在插件的工具栏中添加一个删除线按钮,这在未来可能很有用。

我会考虑一下,但在此期间,您可以使用该插件并添加此组件:GitHub - MonDiscourse/discourse-strikethrough: Add a strikethrough button in the composer

它将在弹出菜单操作中添加一个删除线按钮,它与该插件兼容。

3 个赞

我提交了一个拉取请求:https://github.com/MonDiscourse/md-composer-extras/pull/10,除非我放错了逗号什么的,否则应该可以修复

为防止测试出错,请在 `modifyClass` 调用中添加 `pluginId` 键。这将确保修改只应用一次。
2 个赞