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

Basic plugin management tool #2

Merged
merged 8 commits into from
Mar 17, 2018
Merged

Basic plugin management tool #2

merged 8 commits into from
Mar 17, 2018

Conversation

geezee
Copy link
Owner

@geezee geezee commented Mar 13, 2018

The point of this pull request is to make a system where everyone can control the rendered note. Presently I'm forcing asciinema and mathjax down users' throats, maybe someone doesn't want these.

Introducing the plugin system

A plugin is an anonymous function that takes the note of a body (string), and the note (object) and must return a promise of HTML (string). For example, here's the code for the markdown plugin:

function (body) {
    return loadScript('showdown', 'js/showdown.min.js')
    .then(() => {
        return new showdown.Converter().makeHtml(body);
    });
}

It makes use of loadScript(name, url) common function which returns a promise which will get resolved right after loading the script at the provided URL.

A plugin should be registered in the repository located in resources/note-format/repository.json under the format:

{
    "name": "plugin name",
    "description": "a small description",
    "src": "src\/plugin-source.js",
}

Here's how to use the plugin manager:

> php artisan note-format:list
  1. markdown             - Renders the note in markdown
  2. mathjax              - Render LaTeX equations inside the note
  3. markdown             - Renders the note in markdown

will list the installed plugins in order of execution.

> php artisan note-format:list --all
5 available formatters

* markdown             - Renders the note in markdown
  iframe               - Play around with iframe attributes or block them
* mathjax              - Render LaTeX equations inside the note
  asciinema            - Use $asciinema(attachment_url) to include an asciinema cast
  js-eval              - Evaluate javascript code and display output in an <iframe>

will list all the plugins in the repository.

> php artisan note-format:install markdown asciinema --after=2
> php artisan note-format:list
  1. markdown             - Renders the note in markdown
  2. mathjax              - Render LaTeX equations inside the note
  3. markdown             - Renders the note in markdown
  4. asciinema            - Use $asciinema(attachment_url) to include an asciinema cast
  5. markdown             - Renders the note in markdown

will install the markdown and asciinema plugins after the second plugin.

> php artisan note-format:remove 3
> php artisan note-format:list
  1. markdown             - Renders the note in markdown
  2. mathjax              - Render LaTeX equations inside the note
  3. asciinema            - Use $asciinema(attachment_url) to include an asciinema cast
  4. markdown             - Renders the note in markdown

will remove the third plugin. Unfortunately it does not support multiple indeces, unlike the install rule.

php artisan note-format:compile

will produce the output javascript file.

What it actually does

It generates a file in resources/note-format/note-format.out.js which is an array of the formatters to be applied in order.

bundle-js should be executed after every compilation

Available formatters

markdown

Will load Showdown and render the body to HTML.

mathjax

Will load MathJax and will render equations.

asciinema

Will replace all instances of $asciinema(attachement-name.cast) with an asciinema player

iframe

Will set a sandbox around all iframes. The set value is "allow-scripts allow-same-origin allow-forms"

js-eval

Evaluates all the javascript code that starts with !eval on its first line. The output is displayed inside a sandboxed iframe with only allow-scripts. For example if the note contains the code:

```js
!eval
for (var i=0; i < 10; i++) {
    document.write('hello world!<br>');
}
```

Then this javascript is executed in an iframe that will show "hello world!" 10 times, each on a line.

php artisan note-format:list
php artisan note-format:install markdown mathjax
php artisan note-format:remove mathjax
php artisan note-format:compile

The source code for the plugins should be in resoures/note-format/src
and should be registered in resources/note-format/repository.json
following the shape

{
    "name": "plugin name",
    "description": "a small description",
    "src": "src\/plugin-source.js",
    "args": object,
    "installed": false
}
@geezee geezee added the new feature New feature or request label Mar 13, 2018
@geezee geezee added this to the 1.0 milestone Mar 13, 2018
@geezee geezee self-assigned this Mar 13, 2018
@geezee geezee merged commit 46dbe48 into master Mar 17, 2018
@geezee geezee deleted the plugins branch March 17, 2018 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant