Closed lemon24 closed 3 years ago
markdown = mistune.create_markdown(plugins=['strikethrough'])
renderer = mistune.HTMLRenderer()
markdown = mistune.Markdown(renderer, plugins=[plugin_strikethrough])
markdown = mistune.create_markdown(plugins=[DirectiveToc(...)])
The string version uses plugins from a hand-written dict of "built-in" plugins.
On the second strikethrough
version, the renderer is required by the plugin (because it needs to do stuff to it); I assume create_markdown() adds it automatically.
db = SQLAlchemy(app, ...)
db = SQLAlchemy(...)
db.init_app(app)
Unlike Mistune:
reader = make_reader_from_config(..., plugins=[
'reader._plugins.regex_mark_as_read:regex_mark_as_read',
reader._plugins.ua_fallback.init,
])
Like Mistune, it takes either a string or a callable; unlike Mistune, the string is an import path, not a name.
It should be possible to change a make_reader() call to make_reader_from_config() without changing anything else.
If we use plugin names in make_reader(), we risk shadowing other packages; put another way, we need to be able to distinguish between plugin names and import paths from the start. Possible ways to deal with this:
reader.ua_fallback
(anything starting with reader.
is a built-in plugin)
module:object
form
regex_mark_as_read
duplication above (OTOH, if the callable was called init
, it'd be much shorter; newer plugins follow this convention; also, our current plugin-loading code requires this form)module:
expand to module:init
.ua_fallback
actually expands to the import path reader.plugins.ua_fallback
It seems we have a trade-off between:
ua_fallback
, thirdparty:init
reader.ua_fallback
, thirdparty
(where the plugin loader looks for init
by convention).ua_fallback
, thirdparty
Update: A one-user focus group concluded import paths everywhere is better:
reader = make_reader('db.sqlite', plugins=[
'reader.plugins.ua_fallback',
'thirdparty', # implicit callable
'thirdparty:init', # explicit callable also OK
])
This is more intuitive (users just have to learn one thing), and we don't have to explain why and how things are different.
Update #2: reader.ua_fallback
is not much harder to support, and still has (most) the benefits above.
To do:
With #226, it's become obvious that some plugins should be enabled by default.
There's also reader._config.make_reader_from_config(); ideally, make_reader() should tend toward it.
Important: This is not to make public hooks etc. (#80); the only promise we make is: this is how you enable/disable built-in plugins, and these are the built-in plugins.
Additionally, it would probably nice to allow callable-style plugins (a la Mistune v2); here, the promise we make is: given this list of callables, we'll call them with the instantiated reader before returning it.
Candidates for the status of built-in: