# Need help getting an "enable plugin" setting feature to work

**URL:** https://meta.discourse.org/t/need-help-getting-an-enable-plugin-setting-feature-to-work/141709
**Category:** Development
**Created:** [February 15, 2020, 9:01pm UTC](https://meta.discourse.org/t/need-help-getting-an-enable-plugin-setting-feature-to-work/141709 "2020-02-15T21:01:29Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [February 15, 2020, 9:01pm UTC](https://meta.discourse.org/t/need-help-getting-an-enable-plugin-setting-feature-to-work/141709/1 "2020-02-15T21:01:29Z")

</div>

I’m working on a markdown plugin and I’m having trouble adding a site setting to allow you to disable the feature. I wrote the plugin by following the structure of [Discourse Footnote](https://meta.discourse.org/t/discourse-footnote/84533), which has a setting allowing you to disable that plugin. I installed the footnote plugin and verified that it can be disabled from the UI and that its corresponding test passes. However, disabling my plugin from the site settings has no effect, and the unit test confirms this by failing.

I’m not sure what I’m doing differently compared to the footnote plugin. It’s possible my usage of `opts.features` is completely wrong or making bad assumptions, because like pretty much everywhere else I just replaced “footnotes” with “ruby”. Any help would be appreciated.

The repo is here: [GitHub - seanblue/discourse-ruby: Adds ruby markdown support to Discourse · GitHub](https://github.com/seanblue/discourse-ruby)

* * *

Key aspects related to the site setting would include:

> <https://github.com/seanblue/discourse-ruby/blob/master/assets/javascripts/lib/discourse-markdown/markdown-ruby.js.es6#L2-L4>

> <https://github.com/seanblue/discourse-ruby/blob/master/config/settings.yml#L1-L4>

> <https://github.com/seanblue/discourse-ruby/blob/master/plugin.rb#L9>

And this is the test that keeps failing (not in the repo yet):

```plaintext
  it "can be disabled" do
    SiteSetting.enable_markdown_ruby = false

    markdown = <<~MD
      Here is some text: {漢字|かん|じ}.
    MD

    html = <<~HTML
      <p>Here is some text: {漢字|かん|じ}.</p>
    HTML

    cooked = PrettyText.cook markdown.strip
    expect(cooked).to eq(html.strip)
  end

```

Not surprisingly, the failure says it’s getting the cooked text as if the markdown still applied.

```plaintext
expected: "<p>Here is some text: {漢字|かん|じ}.</p>"
     got: "<p>Here is some text: <ruby>漢<rt>かん</rt>字<rt>じ</rt></ruby>.</p>"

```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 20, 2020, 3:47am UTC](https://meta.discourse.org/t/need-help-getting-an-enable-plugin-setting-feature-to-work/141709/2 "2020-02-20T03:47:29Z")

</div>

What I usually do in cases like this is start printing stuff out.

Have you tried adding some internal `console.log` statements outputting vars, they may help shed some light here. I do believe the settings are send down to the markdown engine, your test does look legitimate.

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [February 20, 2020, 2:12pm UTC](https://meta.discourse.org/t/need-help-getting-an-enable-plugin-setting-feature-to-work/141709/3 "2020-02-20T14:12:20Z")

</div>

It’s been a while since I’ve done some good old console log debugging. I’ll give that a shot.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 21, 2020, 1:11am UTC](https://meta.discourse.org/t/need-help-getting-an-enable-plugin-setting-feature-to-work/141709/4 "2020-02-21T01:11:15Z")

</div>

I am very much a [puts debugger](https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html) it is the mechanism I find I fallback to most of the time.

---

<div class="post-metadata">

### Author: ![seanblue](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@seanblue](https://meta.discourse.org/u/seanblue)
#### Post date: [February 23, 2020, 1:51am UTC](https://meta.discourse.org/t/need-help-getting-an-enable-plugin-setting-feature-to-work/141709/5 "2020-02-23T01:51:15Z")

</div>

I figured out the issue. It was in fact a problem with how I was using `opts.features` as I suspected. After looking at the [core markdown code](https://github.com/discourse/discourse/blob/1c179177e7c84362572481e61b18597f7d2d5050/app/assets/javascripts/pretty-text/engines/discourse-markdown-it.js.es6), I realized that the feature name is based on the file name. I had my file named `markdown-ruby.js.es6`, so the feature name was implicitly `markdown-ruby` even though I was assigning the feature `ruby` in my code. Renaming the file to `ruby.js.es6` resolved the issue.

It’s still a little unclear to me if the `opts.features` I’m modifying represents all features or just the markdown subset of features. If it’s all features, `ruby` feels a little too short/vague and I might rename the file and feature to `markdown-ruby` just to be safe.
