<commit_before>/**
 * Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid functionality and to render
 * the diagrams to svg code.
 */

var Logger = require('./logger');

var log = new Logger.Log();
var mermaidAPI = require('./mermaidAPI');
var nextId = 0;

var he = require('he');

module.exports.mermaidAPI = mermaidAPI;
/**
 * ## init
 * Function that goes through the document to find the chart definitions in there and render them.
 *
 * The function tags the processed attributes with the attribute data-processed and ignores found elements with the
 * attribute already set. This way the init function can be triggered several times.
 *
 * Optionally, `init` can accept in the second argument one of the following:
 * - a DOM Node
 * - an array of DOM nodes (as would come from a jQuery selector)
 * - a W3C selector, a la `.mermaid`
 *
 * ```mermaid
 * graph LR;
 *  a(Find elements)-->b{Processed}
 *  b-->|Yes|c(Leave element)
 *  b-->|No |d(Transform)
 * ```
 * Renders the mermaid diagrams
 * @param nodes a css selector or an array of nodes
 */
var init = function () {
    var conf= mermaidAPI.getConfig();
    log.debug('Starting rendering diagrams');
    var nodes;
    if(arguments.length >= 2){
        /*! sequence config was passed as #1 */
        if(typeof arguments[0] !== 'undefined'){
            global.mermaid.sequenceConfig = arguments[0];
        }

        nodes = arguments[1];
    }
    else{
        nodes = arguments[0];
    }

    // if last argument is a function this is the callback function
    var callback;
    if(typeof arguments[arguments.length-1] === 'function'){
        callback = arguments[arguments.length-1];
        log.debug('Callback function found');
    }else{
        if(typeof conf.mermaid !== 'undefined'){
            if(typeof conf.mermaid.callback === 'function'){
                callback = conf.mermaid.callback;
                log.debug('Callback function found');
            }else{
                log.debug('No Callback function found');
            }
        }
    }
    nodes = nodes === undefined ? document.querySelectorAll('.mermaid')
        : typeof nodes === 'string' ? document.querySelectorAll(nodes)
        : nodes instanceof Node ? [nodes]
        /*! Last case  - sequence config was passed pick next */
        : nodes;

    var i;

    if(typeof mermaid_config !== 'undefined'){
        mermaidAPI.initialize(global.mermaid_config);
    }<commit_msg>Issue 297 - src/mermaid.js generates bad code<commit_after>/**
 * Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid functionality and to render
 * the diagrams to svg code.
 */

var Logger = require('./logger');

var log = new Logger.Log();
var mermaidAPI = require('./mermaidAPI');
var nextId = 0;

var he = require('he');

module.exports.mermaidAPI = mermaidAPI;
/**
 * ## init
 * Function that goes through the document to find the chart definitions in there and render them.
 *
 * The function tags the processed attributes with the attribute data-processed and ignores found elements with the
 * attribute already set. This way the init function can be triggered several times.
 *
 * Optionally, `init` can accept in the second argument one of the following:
 * - a DOM Node
 * - an array of DOM nodes (as would come from a jQuery selector)
 * - a W3C selector, a la `.mermaid`
 *
 * ```mermaid
 * graph LR;
 *  a(Find elements)-->b{Processed}
 *  b-->|Yes|c(Leave element)
 *  b-->|No |d(Transform)
 * ```
 * Renders the mermaid diagrams
 * @param nodes a css selector or an array of nodes
 */
var init = function () {
    var conf= mermaidAPI.getConfig();
    log.debug('Starting rendering diagrams');
    var nodes;
    if(arguments.length >= 2){
        /*! sequence config was passed as #1 */
        if(typeof arguments[0] !== 'undefined'){
            global.mermaid.sequenceConfig = arguments[0];
        }

        nodes = arguments[1];
    }
    else{
        nodes = arguments[0];
    }

    // if last argument is a function this is the callback function
    var callback;
    if(typeof arguments[arguments.length-1] === 'function'){
        callback = arguments[arguments.length-1];
        log.debug('Callback function found');
    }else{
        if(typeof conf.mermaid !== 'undefined'){
            if(typeof conf.mermaid.callback === 'function'){
                callback = conf.mermaid.callback;
                log.debug('Callback function found');
            }else{
                log.debug('No Callback function found');
            }
        }
    }
    nodes = nodes === undefined ? document.querySelectorAll('.mermaid')
        : typeof nodes === 'string' ? document.querySelectorAll(nodes)
        : nodes instanceof Node ? [nodes]
        : nodes;  // Last case  - sequence config was passed pick next

    var i;

    if(typeof mermaid_config !== 'undefined'){
        mermaidAPI.initialize(global.mermaid_config);
    }
{'fraction_non_alphanumeric': 0.11681772406847936, 'fraction_numerical': 0.004632426988922457, 'mean_word_length': 2.6949404761904763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5954184', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1373, 'n_words': 481}