posthtml-retag
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    PostHTML-ReTag

    NPM

    A PostHTML plugin for converting HTML tags to a specified target type.

    Useful as part of a post-export script for visual editors that don't support certain tags, among other things.

    Before:

    <html>
      <body>
        <!-- ... content -->
        <div retag="noscript">
          <div>
            <span>Noscript content</span>
          </div>
        </div>
        <div retag="template">
          <span>Some more content</span>
        </div>
      </body>
    </html>

    After:

    <html>
      <body>
        <!-- ... content -->
        <noscript>
          <div>
            <span>Noscript content</span>
          </div>
        </noscript>
        <template>
          <span>Some more content</span>
        </template>
      </body>
    </html>

    Install

    npm install --save-dev posthtml posthtml-retag

    Usage

    CommonJS format
    const fs = require('fs');
    const posthtml = require('posthtml');
    const retag = require('posthtml-retag');
    // Import additional plugins (if any)
    
    const html = fs.readFileSync('/path/to/input.html', 'utf8');
    
    posthtml(
      [
        retag({
          attr: 'retag',
          removeDisplayNone: false
        }),
        // Additional plugins
      ])
      .process(html)
      .then(result => fs.writeFileSync('/path/to/output.html', result.html));
    ES Module format
    import { readFileSync, writeFileSync } from 'fs';
    import posthtml from 'posthtml';
    import retag from 'posthtml-retag';
    // Import additional plugins (if any)
    
    const html = readFileSync('/path/to/input.html', 'utf8');
    
    posthtml(
      [
        retag({
          attr: 'retag',
          removeDisplayNone: false
        }),
        // Additional plugins
      ])
      .process(html)
      .then(result => writeFileSync('/path/to/output.html', result.html));

    Options

    attr

    Type: string

    Default: retag

    Specify the attribute that stores the name of the tag you want to convert to.

    removeDisplayNone

    Type: boolean

    Default: false

    Set to true to also remove display: none; from the style attribute of the element being converted. If it's the only value in the style attribute, the style attribute will be removed.

    <div retag="template" style="display: none"></div>
    <template></template>

    Install

    npm i posthtml-retag

    DownloadsWeekly Downloads

    5

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    6.22 kB

    Total Files

    5

    Last publish

    Collaborators

    • awsr