rehype plugins can be used by unified-doc to enhance the rendered document. unified-doc uses a number of private plugins to implement its core APIs. Plugins can be applied as prePlugins or postPlugins, which correspond to whether the plugins are run before/after private plugins are applied. Plugins should use the PluggableList interface e.g. [plugin1, [plugin2, plugin2Options]].
prePluginsThese plugins are applied before private plugins, and therefore API methods (e.g. marks) can act on the changes made by these plugins, as seen in the example below where the marks algorithm is able to operate on changes made by the rehype-highlight plugin.
function greet() {
return "hello world";
}<pre class="language-js"><code class="hljs language-js">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title"><mark data-mark-id="a" id="a">greet</mark></span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">return</span> <span class="hljs-string">"hello world"</span>;
}</code></pre>postPluginsUnlike prePlugins, these plugins are applied after private plugins, and therefore API methods (e.g. marks) do not act on changes made by these plugins (since they are applied later), as seen in the example below where the marks algorithm doesn't run on the changes made by rehype-plugins.
function greet() {
return "hello world";
}<pre class="language-js"><code class="hljs language-js">
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">return</span> <span class="hljs-string">"hello world"</span>;
}</code></pre>Use
postPluginswith care because some plugins might strictly overwrite any changes made by prviate plugins.
Here is an example of a custom plugin that capitalizes all text node values, and applied as a prePlugin so private plugins can pickup changes applied by it.
SOME MARKDOWN CONTENT
<blockquote> <p><strong>SOME</strong> <mark data-mark-id="a" id="a">MARKDOWN</mark> CONTENT</p> </blockquote>