<commit_before>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import json2html = require('json-to-html');

import {
  simulate
} from 'simulate-event';

import {
  ServiceManager, utils
} from '@jupyterlab/services';

import {
  Widget
} from 'phosphor/lib/ui/widget';

import {
  TextModelFactory, DocumentRegistry, Context
} from '../../lib/docregistry';

import {
  INotebookModel
} from '../../lib/notebook/notebook/model';

import {
  NotebookModelFactory
} from '../../lib/notebook/notebook/modelfactory';

import {
  LatexRenderer, PDFRenderer, JavascriptRenderer,
  SVGRenderer, MarkdownRenderer, TextRenderer, HTMLRenderer, ImageRenderer
} from '../../lib/renderers';

import {
  RenderMime
} from '../../lib/rendermime';

import {
  defaultSanitizer
} from '../../lib/sanitizer';


/**
 * Get a copy of the default rendermime instance.
 */
export
function defaultRenderMime(): RenderMime {
  return Private.rendermime.clone();
}


/**
 * Create a context for a file.
 */
export
function createFileContext(path?: string, manager?: ServiceManager.IManager): Context<DocumentRegistry.IModel> {
  manager = manager || Private.manager;
  let factory = Private.textFactory;
  path = path || utils.uuid() + '.txt';
  return new Context({ manager, factory, path });
}


/**
 * Create a context for a notebook.
 */
export
function createNotebookContext(path?: string, manager?: ServiceManager.IManager): Context<INotebookModel> {
  manager = manager || Private.manager;
  let factory = Private.notebookFactory;
  path = path || utils.uuid() + '.ipynb';
  return new Context({ manager, factory, path });
}


/**
 * Wait for a dialog to be attached to an element.
 */
export
function waitForDialog(host: HTMLElement = document.body): Promise<void> {
  return new Promise<void>((resolve, reject) => {
    let refresh = () => {
      let node = host.getElementsByClassName('jp-Dialog')[0];
      if (node) {
        resolve(void 0);
        return;
      }
      setTimeout(refresh, 10);
    };
    refresh();
  });
}


/**
 * Accept a dialog after it is attached if it has an OK button.
 */
export
function acceptDialog(host: HTMLElement = document.body): Promise<void> {
  return waitForDialog(host).then(() => {
    let node = host.getElementsByClassName('jp-Dialog-okButton')[0];<commit_msg>Fix acceptDialog utility<commit_after>// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import json2html = require('json-to-html');

import {
  simulate
} from 'simulate-event';

import {
  ServiceManager, utils
} from '@jupyterlab/services';

import {
  Widget
} from 'phosphor/lib/ui/widget';

import {
  TextModelFactory, DocumentRegistry, Context
} from '../../lib/docregistry';

import {
  INotebookModel
} from '../../lib/notebook/notebook/model';

import {
  NotebookModelFactory
} from '../../lib/notebook/notebook/modelfactory';

import {
  LatexRenderer, PDFRenderer, JavascriptRenderer,
  SVGRenderer, MarkdownRenderer, TextRenderer, HTMLRenderer, ImageRenderer
} from '../../lib/renderers';

import {
  RenderMime
} from '../../lib/rendermime';

import {
  defaultSanitizer
} from '../../lib/sanitizer';


/**
 * Get a copy of the default rendermime instance.
 */
export
function defaultRenderMime(): RenderMime {
  return Private.rendermime.clone();
}


/**
 * Create a context for a file.
 */
export
function createFileContext(path?: string, manager?: ServiceManager.IManager): Context<DocumentRegistry.IModel> {
  manager = manager || Private.manager;
  let factory = Private.textFactory;
  path = path || utils.uuid() + '.txt';
  return new Context({ manager, factory, path });
}


/**
 * Create a context for a notebook.
 */
export
function createNotebookContext(path?: string, manager?: ServiceManager.IManager): Context<INotebookModel> {
  manager = manager || Private.manager;
  let factory = Private.notebookFactory;
  path = path || utils.uuid() + '.ipynb';
  return new Context({ manager, factory, path });
}


/**
 * Wait for a dialog to be attached to an element.
 */
export
function waitForDialog(host: HTMLElement = document.body): Promise<void> {
  return new Promise<void>((resolve, reject) => {
    let refresh = () => {
      let node = host.getElementsByClassName('jp-Dialog')[0];
      if (node) {
        resolve(void 0);
        return;
      }
      setTimeout(refresh, 10);
    };
    refresh();
  });
}


/**
 * Accept a dialog after it is attached if it has an OK button.
 */
export
function acceptDialog(host: HTMLElement = document.body): Promise<void> {
  return waitForDialog(host).then(() => {
    let node = host.getElementsByClassName('jp-Dialog-okButton')[0];
    if (!node) {
      node = host.getElementsByClassName('jp-Dialog-warningButton')[0];
    }
{'fraction_non_alphanumeric': 0.14238134887593673, 'fraction_numerical': 0.0027060782681099086, 'mean_word_length': 3.7621407333994052, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '7512367', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1444, 'n_words': 391}