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

Inject browser script to rendered Markdown automatically #115

Merged
merged 13 commits into from
Oct 19, 2019

Conversation

yhatt
Copy link
Member

@yhatt yhatt commented Oct 18, 2019

Based on feedbacks in #112 and marp-team/marp-cli#168, I've implemented better script injection to work WebKit polyfill and auto-scaling observer in anywhere.

This implementation would make Marp Core work well in customized engine of Marp CLI. In addition, Marp CLI's browser script detection would no longer need.

script option

Marp constructor has a new script option to control browser script injection.

  • true: Insert the inline browser script into the last of slides. (default)
  • false: Not insert any script. Developer has to execute the script exported in @marp-team/marp-core/browser manually. It's suitable to the fully-controlled tool such as Marp Web.
  • You can control the detail of behavior by passing object:
    • source: Choose the kind of script.
      • inline: Insert inline script. It would work correctly also in the environment that there is not network. (default)
      • cdn: Insert script referred through jsDelivr CDN. It's better choice on the restricted environment by CSP.
    • nonce: Set nonce attribute of <script>.

Deprecated Marp.ready()

Marp.ready() was marked as deprecated because typically the script injection won't require to call browser script manually. If developer wants to use browser script (e.g. Marp Web), it can use a better entry point @marp-team/marp-core/browser splitted from Marp class.

ToDo

  • Update README.md

@@ -0,0 +1,3 @@
const dummy = 'This is a placeholder for the content of built browser script.'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using a strange trick for bundling precompiled IIFE script as string by rollup, without any errors.
https://github.com/marp-team/marp-core/pull/115/files#diff-ff6e5f22a9c7e66987b19c0199636480R23

@@ -6,6 +6,7 @@
"noImplicitAny": false,
"outDir": "lib",
"resolveJsonModule": true,
"rootDir": ".",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To resolve URL for CDN, we have to load package.json placed on the project root. Thus, rootDir was changed from src to .. It would change the structure of types directory too.

@yhatt yhatt merged commit 50c54d5 into master Oct 19, 2019
@yhatt yhatt deleted the inject-browser-script branch October 19, 2019 11:51
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

Successfully merging this pull request may close these issues.

None yet

1 participant