Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the markdown parser #482

Open
egoist opened this issue Sep 27, 2019 · 3 comments
Open

Expose the markdown parser #482

egoist opened this issue Sep 27, 2019 · 3 comments
Labels
contribution welcome core Regarding Saber core.

Comments

@egoist
Copy link
Collaborator

egoist commented Sep 27, 2019

Feature request

What problem does this feature solve?

Allow plugins to use this API to turn Markdown into HTML.

What does the proposed API look like?

const { html } = api.markdown.render(markdownCode, {
  defaultPlugins?: boolean,
  plugins?: MarkdownItPlugins[],
  options?: MarkdownItOptions,
  env?: object // Passed to `md.render`
})
@egoist egoist added contribution welcome core Regarding Saber core. labels Sep 27, 2019
@brattonross
Copy link

Hey, I'm new to saber but I'd like to contribute if possible. As I understand it implementing this feature would mean taking some of the functionality from the markdown transformer and making it available on the saber instance so that plugins are able to make use of it?

@egoist
Copy link
Collaborator Author

egoist commented Oct 3, 2019

@brattonross yes, like the api.pages API you can initialize it here:

this.pages = new Pages(this)

@brattonross
Copy link

So currently the function signature that I have for render looks like this:

render(markdownCode, {
  defaultPlugins = true,
  plugins = [],
  options = {},
  env = {}
} = {}) {
  // ...
}

I'm assuming here that the second argument is optional, and that by default the default plugins should be used.

I then merge the options which are passed in with the existing options:

const chain = new ConfigChain()

chain.options.merge(
  Object.assign(
    {
      html: true,
      linkify: true,
      highlight: markdown.highlighter
    },
    markdown.options,
    options
  )
)

I have a couple of questions about the plugins; firstly, should the call to the chainMarkdown hook always happen, or only if we load default plugins? The current implementation that I have will only call it if the defaultPlugins flag is set. We could move the hook call outside of the if block, but then the plugins from config are loaded before this hook call, whereas previously the hook was called before these plugins were loaded. Also, are the plugins from config regarded as part of the default plugins? Or would the markdown transformer pass these in when calling the render method?

if (defaultPlugins) {
  // Load built-in plugins
  chain.loadPlugins(builtInPlugins, configDir)

  this.api.hooks.chainMarkdown.call(chain)

  // Load plugins from config file
  if (markdown.plugins) {
    chain.loadPlugins(markdown.plugins, configDir)
  }
}
// We could move the hook call here?

// Load user-defined plugins
chain.loadPlugins(plugins, )

Secondly, as you can see above I haven't passed a second argument to loadPlugins. I'm not sure currently what the cwd should be for these plugins. Will this be the same for all plugins or will the caller need to specify it for each plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome core Regarding Saber core.
Projects
None yet
Development

No branches or pull requests

2 participants