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

Allow magic redirection filter to javascript #100

Closed
antononcube opened this issue Dec 10, 2022 · 5 comments
Closed

Allow magic redirection filter to javascript #100

antononcube opened this issue Dec 10, 2022 · 5 comments

Comments

@antononcube
Copy link
Contributor

Please, implement in the magics specifications "filter redirection" from Raku to JavaScript -- %% raku > javascript and/or %% perl6 > javascript.

(This type of specification is already available for LaTeX <-> HTML.)

For example, with this kind of specification:

%%  raku > javasript
<raku-code-that-produces-javascript-d3-code>

I can produce the plot shown here:


Currently, I am using this very "targeted" hack to be able to make the JavaScript D3 diagrams as the one above:

sub mime-type($str) is export {
    return do given $str {
        when /:i ^ '<svg' / {
            'image/svg+xml';
        }
        when /:i ^ '<img' / {
            'text/html';
        }
        when / ^ \s* '(function(element)' \s* '{' \s* 'require' \s* '(' \s* '[\'d3\']' \s* ',' \s* 'function(d3)'  \s* '{' / {
            'application/javascript';
        }
        default { 'text/plain' }
    }
}

(This request related is to related to my previous one, but as far as I can tell requires different implementation approach.)

@bduggan
Copy link
Owner

bduggan commented Dec 12, 2022

There is a #% javascript magic -- is that sufficient?

@antononcube
Copy link
Contributor Author

There is a #% javascript magic -- is that sufficient?

No, it is not -- I am proposing Raku code (in Raku cells) that generates JavaScript code to have the results of the JavaScript code in the corresponding output cell.

@bduggan
Copy link
Owner

bduggan commented Dec 13, 2022

Okay, implemented in 075f7f5

You can now do

#% > js

for stdout to be interpreted as javascript, or

#% js

for the result to be intepreted as javascript.

@antononcube
Copy link
Contributor Author

Thank you!
Just tried it:

(Using the package "JavaScript::D3".)

@bduggan
Copy link
Owner

bduggan commented Dec 14, 2022

cool!

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

No branches or pull requests

2 participants