empress / field-guide

SEO friendly static site implementation of a design system documentation site
https://field-guide.netlify.app/
MIT License
17 stars 7 forks source link

Unable (or unclear how) to set showdown config #73

Open Dhaulagiri opened 1 year ago

Dhaulagiri commented 1 year ago

Per the docs for ember-cli-showdown it should be possible to set global showdown config via an app's environment.js. However, these options don't appear to be passed along to showdown as part of the way showdown is invoked in field-guide.

I was able to make this work by doing something like this, but it's unclear if this is the best solution of if there is something else I'm missing here.

export default Controller.extend({
  fieldGuideConfig: config['field-guide'],
  showdownConfig: config['showdown'],
  renderedContent: computed('model.content', function() {
    const converter = new showdown.Converter(this.showdownConfig);
    return converter.makeHtml(this.model.content);
  })
})
NullVoxPopuli commented 1 year ago

Thanks! I did this technique, too, and used my own show controller.

Here is my version though, because extend is from the dark ages 😅

import showdown from 'showdown';
import footnotes from 'showdown-ghost-footnotes';

import Controller from '@ember/controller';
import { cached } from '@glimmer/tracking';

import config from 'my-app/config/environment';

// Overrides: https://github.com/empress/field-guide/blob/master/addon/controllers/show.js
// see: https://github.com/empress/field-guide/issues/73
export default class Show extends Controller {
    fieldGuideConfig = config['field-guide'];

    @cached
    get renderedContent() {
        const converter = new showdown.Converter({ extensions: [footnotes] });
        return converter.makeHtml(this.model.content);
    }
}