<commit_before>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import sanitize from 'sanitize-html';


export
interface ISanitizer {
  /**
   * Sanitize an HTML string.
   *
   * @param dirty - The dirty text.
   *
   * @param options - The optional sanitization options.
   *
   * @returns The sanitized string.
   */
  sanitize(dirty: string, options?: ISanitizer.IOptions): string;
}


/**
 * The namespace for `ISanitizer` related interfaces.
 */
export
namespace ISanitizer {
  /**
   * The options used to sanitize.
   */
  export
  interface IOptions {
    /**
     * The allowed tags.
     */
    allowedTags?: string[];

    /**
     * The allowed attributes for a given tag.
     */
    allowedAttributes?: { [key: string]: string[] };
  }
}



/**
 * A class to sanitize HTML strings.
 */
class Sanitizer implements ISanitizer {
  /**
   * Sanitize an HTML string.
   *
   * @param dirty - The dirty text.
   *
   * @param options - The optional sanitization options.
   *
   * @returns The sanitized string.
   */
  sanitize(dirty: string, options?: ISanitizer.IOptions): string {
    return sanitize(dirty, { ...this._options, ...options || {} });
  }

  private _options: sanitize.IOptions = {
    allowedTags: sanitize.defaults.allowedTags
      .concat('h1', 'h2', 'img', 'span', 'audio', 'video', 'del',
              'kbd', 'sup', 'sub', 'colspan', 'rowspan', 'input'),
    allowedAttributes: {
      // Allow the "rel" attribute for <a> tags.
      'a': sanitize.defaults.allowedAttributes['a'].concat('rel'),
      // Allow the "src" attribute for <img> tags.
      'img': ['src', 'height', 'width', 'alt'],
      // Allow the "type" attribute for <input> tags.
      'input': ['type', 'disabled'],
      // Allow "class" attribute for <code> tags.
      'code': ['class'],
      // Allow "class" attribute for <span> tags.
      'span': ['class'],
      // Allow "class" attribute for <div> tags.
      'div': ['class'],
      // Allow "class" attribute for <p> tags.
      'p': ['class'],
      // Allow "class" attribute for <pre> tags.
      'pre': ['class'],
      // Allow the "src" attribute for <audio> tags.
      'audio': ['src', 'autoplay', 'loop', 'muted', 'controls'],
      // Allow the "src" attribute for <video> tags.
      'video': ['src', 'height', 'width', 'autoplay',
                'loop', 'muted', 'controls']
    },
    transformTags: {
      // Set the "rel" attribute for <a> tags to "nofollow".
      'a': sanitize.simpleTransform('a', { 'rel': 'nofollow' }),
      // Set the "disabled" attribute for <input> tags.
      'input': sanitize.simpleTransform('input', { 'disabled': true })
    },
    allowedSchemesByTag: {
      // Allow 'attachment:' img src (used for markdown cell attachments).
      'img': sanitize.defaults.allowedSchemes.concat(['attachment']),
    }
  };
}


/**
 * The default instance of an `ISanitizer` meant for use by user code.
 */
export
const defaultSanitizer: ISanitizer = new Sanitizer();
<commit_msg>Use string value for disabled attribute<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
import sanitize from 'sanitize-html';


export
interface ISanitizer {
  /**
   * Sanitize an HTML string.
   *
   * @param dirty - The dirty text.
   *
   * @param options - The optional sanitization options.
   *
   * @returns The sanitized string.
   */
  sanitize(dirty: string, options?: ISanitizer.IOptions): string;
}


/**
 * The namespace for `ISanitizer` related interfaces.
 */
export
namespace ISanitizer {
  /**
   * The options used to sanitize.
   */
  export
  interface IOptions {
    /**
     * The allowed tags.
     */
    allowedTags?: string[];

    /**
     * The allowed attributes for a given tag.
     */
    allowedAttributes?: { [key: string]: string[] };
  }
}



/**
 * A class to sanitize HTML strings.
 */
class Sanitizer implements ISanitizer {
  /**
   * Sanitize an HTML string.
   *
   * @param dirty - The dirty text.
   *
   * @param options - The optional sanitization options.
   *
   * @returns The sanitized string.
   */
  sanitize(dirty: string, options?: ISanitizer.IOptions): string {
    return sanitize(dirty, { ...this._options, ...options || {} });
  }

  private _options: sanitize.IOptions = {
    allowedTags: sanitize.defaults.allowedTags
      .concat('h1', 'h2', 'img', 'span', 'audio', 'video', 'del',
              'kbd', 'sup', 'sub', 'colspan', 'rowspan', 'input'),
    allowedAttributes: {
      // Allow the "rel" attribute for <a> tags.
      'a': sanitize.defaults.allowedAttributes['a'].concat('rel'),
      // Allow the "src" attribute for <img> tags.
      'img': ['src', 'height', 'width', 'alt'],
      // Allow the "type" attribute for <input> tags.
      'input': ['type', 'disabled'],
      // Allow "class" attribute for <code> tags.
      'code': ['class'],
      // Allow "class" attribute for <span> tags.
      'span': ['class'],
      // Allow "class" attribute for <div> tags.
      'div': ['class'],
      // Allow "class" attribute for <p> tags.
      'p': ['class'],
      // Allow "class" attribute for <pre> tags.
      'pre': ['class'],
      // Allow the "src" attribute for <audio> tags.
      'audio': ['src', 'autoplay', 'loop', 'muted', 'controls'],
      // Allow the "src" attribute for <video> tags.
      'video': ['src', 'height', 'width', 'autoplay',
                'loop', 'muted', 'controls']
    },
    transformTags: {
      // Set the "rel" attribute for <a> tags to "nofollow".
      'a': sanitize.simpleTransform('a', { 'rel': 'nofollow' }),
      // Set the "disabled" attribute for <input> tags.
      'input': sanitize.simpleTransform('input', { 'disabled': 'true' })
    },
    allowedSchemesByTag: {
      // Allow 'attachment:' img src (used for markdown cell attachments).
      'img': sanitize.defaults.allowedSchemes.concat(['attachment']),
    }
  };
}


/**
 * The default instance of an `ISanitizer` meant for use by user code.
 */
export
const defaultSanitizer: ISanitizer = new Sanitizer();

{'fraction_non_alphanumeric': 0.16327868852459015, 'fraction_numerical': 0.0006557377049180328, 'mean_word_length': 2.670878459687124, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3811673', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1869, 'n_words': 585}