Socket
Book a DemoInstallSign in
Socket

@diplodoc/html-extension

Package Overview
Dependencies
Maintainers
10
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@diplodoc/html-extension

HTML plugin for Diplodoc transformer and builder

Source
npmnpm
Version
1.3.1
Version published
Weekly downloads
73
-22.34%
Maintainers
10
Weekly downloads
 
Created
Source

Diplodoc html extension

NPM version

This is an extension of the Diplodoc platform, which allows adding HTML in the documentation.

The extension contains some parts:

Quickstart

Attach the plugin to the transformer:

import htmlExtension from '@diplodoc/html-extension';
import transform from '@diplodoc/transform';
import * as sanitizeHtml from 'sanitize-html';

const {result} = await transform(`
::: html

<article class="forecast">
  <h1>Weather forecast for Seattle</h1>
  <article class="day-forecast">
    <h2>12 June 2024</h2>
    <p>Rain.</p>
  </article>
  <article class="day-forecast">
    <h2>13 June 2024</h2>
    <p>Periods of rain.</p>
  </article>
  <article class="day-forecast">
    <h2>14 June 2024</h2>
    <p>Heavy rain.</p>
  </article>
</article>

:::
`, {
    plugins: [
        htmlExtension.transform({
            sanitize: dirtyHtml => sanitizeHtml(dirtyHtml, {
                allowedTags: ['article', 'h1', 'h2', 'p', 'span'],
                allowedAttributes: {
                    '*': ['class']
                }
            }),
            containerClasses: 'my-own-class'
        })
    ]
});

Prepared runtime

It is necessary to add runtime scripts to make html interactive on your page.
You can add assets files which were generated by the MarkdownIt transform plugin.

<html>
    <head>
        <!-- Read more about '_assets/html-extension.js' and '_assets/html-extension.css' in 'Transform plugin' section -->
        <script src='_assets/html-extension.js' async></script>
    </head>
    <body>
        ${result.html}
    </body>
</html>

Or you can just include runtime's source code in your bundle.

import '@diplodoc/html-extension/runtime'

MarkdownIt transform plugin

Plugin for @diplodoc/transform package.

Options:

  • runtimeJsPath - name on runtime script which will be exposed in results script section.
    Default: _assets/html-extension.js

  • bundle - boolean flag to enable/disable copying of bundled runtime to target directory.
    Where target directore is <transformer output option>/<plugin runtime option>
    Default: true

  • containerClasses - additional classes which will be added to tab's container node. It allows to customize the html view.
    Example: my-own-class and-other-class
    Default: undefined

API

Syntax

This plugin uses the directive syntax proposed in the CommonMark community, indicated by a block-level double colon at the beginning and end of a block. This HTML directives use ::: html to open an HTML block, followed by your HTML content, and then ::: to close the block. The number of empty lines before or after the opening or closing block is not significant.

Please note:

  • Nested content within the block will not be parsed as Markdown.
  • Embedded directives within the block are not supported.
  • Inline directives are not yet supported.

Simple example:

::: html

<div>Your HTML code is here</div>

:::

Example with some styles:

::: html
<style>
<style>
  :root {
    --dark-bg-color: #000;
    --dark-text-color: #FFF;
  }
  .dark {
    background-color: var(--primary-bg-color);
    color: : var(--primary-text-color);
  }
</style>
<div class="dark">Some info is here</div>
:::

React hook for smart control

You can use the React hook to interact programmatically with the HTML content inside the block.

// TODO

FAQs

Package last updated on 08 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts