Closed benlk closed 6 years ago
With the following post_content:
<!-- wp:shortcode -->
[pym src="https://f.benlk.com/graphics/heartbeat-abortion-bills/child.html"]
<!-- /wp:shortcode -->
<!-- wp:paragraph -->
<p>the preceding is a shortcode block.</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>The following is the Pym Embed:</p>
<!-- /wp:paragraph -->
<!-- wp:pym-shortcode/pym {"src":"http://blog.apps.npr.org/pym.js/examples/table/child.html","align":"full"} /-->
The following output:
<div id="pym_1" class="pym "></div>
<script>var pym_1 = new pym.Parent('pym_1', 'https://f.benlk.com/graphics/heartbeat-abortion-bills/child.html', {})</script>
<p>the preceding is a shortcode block.</p>
<p>The following is the Pym Embed:</p>
<div id="pym_0" class="pym alignfull "></div>
<script src="http://pym-shortcode.test/wp-content/plugins/pym-shortcode/js/pym.v1.min.js"></script><script>var pym_0 = new pym.Parent('pym_0', 'http://blog.apps.npr.org/pym.js/examples/table/child.html', {})</script>
Why does the first one have a later ID? Does the block renderer run before the shortcode renderer? How can it be assured that the script source is output before any and all tags?
Looks like yes, the block renderer does run before the shortcode renderer.
Hrm, how might this work:
the_content
that checks for the presence of the string 'pym', and if it is there, sets a global "maybe" variable to true
definitely
variable to true
. If pymsrc is set, then instead output the pymsrc's tagthe_content
that runs at a very late priority, like 100
, if $maybe and $definitely, prepend the_content
with a script tag that registers Pym.Alternately:
<script>var pym_1 = new pym.Parent('pym_1', 'https://f.benlk.com/graphics/heartbeat-abortion-bills/child.html', {})</script>
, instead of outputting it then, add it to the footer with a generated callback function that has the correct variables inserted into its call!Gonna open a separate issue for this problem, because that makes it easier to discuss separately from "should we implement blocks".
Can the Gutenberg anchor item be used to set the parent ID?
In theory, yes.
In practice:
anchor
appears to require that the save
method on the block be implemented in a way that returns code to be saved in the post_content
, which effectively prevents its use on dynamic bocks and serverside-rendered blocks like the Pym Embed block. https://github.com/WordPress/gutenberg/issues/6356anchor
feature, and that's the heading block. And there are no implementation details there.So:
anchor
support declarationanchor
support with a migration function Things that I'm going to spin off into separate issues:
Left for this PR:
On the subject of the browser console errors, hard to tell.
It's disconcerting to deactivate the plugin and see nothing where a block used to be, just an empty "Classic" editor.
Internationalization is blocked by insufficient Gutenberg docs; see https://github.com/INN/pym-shortcode/issues/40.
Okay, state of this PR:
align=""
parameter, so that WordPress's generated alignment CSS classes can be used on embeds. By enabling this in the shortcode, the Gutenberg Block also gains support for alignment. PR #34the_content()
, instead being output during wp_footer()
by closures hooked on the 'wp_footer'
action. PR #34 for issues #33 and #35.pym.js
is no longer output by the_content()
, instead being output during wp_footer
by an action dedicated to the task. If different shortcodes and/or blocks on the page specify different source URLs for Pym.js, all are output (after removing duplicates), but a message is logged in the browser console. If WP_DEBUG
is set, this message is also logged to the server log, with the post ID specified. PR #34 for issues #33 and #35. See https://github.com/INN/pym-shortcode/tree/master/docs#ive-set-a-different-pymsrc-option-but-now-im-seeing-a-message-in-the-consolenew pym.Parent
is now configurable. By replacing the pluggable function pym_shortcode_script_footer_enqueue()
with your own function, you can now use alternate forms of embed code that may be required for PJAX sites or custom versions of Pym.js. This resolves issue #19.docs/readme.md
.anchor
support https://github.com/INN/pym-shortcode/issues/36Changes to docs:
Changes
To do list
pymsrc
script tags to the footernew pym.Parent
script tags to the footerparent_id
instead ofid
in order to avoid conflicts with Reactalignfull
andalignwide
classes, for testing purposes: https://wordpress.org/themes/atomic-blocks/Add support for converting a Pym iframe into a generic embed iframe via atransform
: https://wordpress.org/gutenberg/handbook/block-api/#transforms-optional