<commit_before>const blockC = require('./region-matchers/block-c');
const html = require('./region-matchers/html');
const inlineC = require('./region-matchers/inline-c');
const inlineCOnly = require('./region-matchers/inline-c-only');
const inlineHash = require('./region-matchers/inline-hash');
const DEFAULT_PLASTER = '. . .';
const {mapObject} = require('../../helpers/utils');

module.exports = function regionParser() {
  return regionParserImpl;
};

regionParserImpl.regionMatchers = {
  ts: inlineC,
  js: inlineC,
  es6: inlineC,
  dart: inlineC,
  html: html,
  css: blockC,
  yaml: inlineHash,
  jade: inlineCOnly,
  json: inlineC,
  'json.annotated': inlineC
};

/**
 * @param contents string
 * @param fileType string
 * @returns {contents: string, regions: {[regionName: string]: string}}
 */
function regionParserImpl(contents, fileType) {
  const regionMatcher = regionParserImpl.regionMatchers[fileType];
  const openRegions = [];
  const regionMap = {};

  if (regionMatcher) {
    let plaster = regionMatcher.createPlasterComment(DEFAULT_PLASTER);
    const lines = contents.split(/\r?\n/).filter((line, index) => {
      const startRegion = line.match(regionMatcher.regionStartMatcher);
      const endRegion = line.match(regionMatcher.regionEndMatcher);
      const updatePlaster = line.match(regionMatcher.plasterMatcher);

      // start region processing
      if (startRegion) {
        // open up the specified region
        const regionNames = getRegionNames(startRegion[1]);
        if (regionNames.length === 0) {
          regionNames.push('');<commit_msg>fix(docs-infra): detect docregions on more file types (`pug`, `svg`, `yml`) (#30559)<commit_after>const blockC = require('./region-matchers/block-c');
const html = require('./region-matchers/html');
const inlineC = require('./region-matchers/inline-c');
const inlineCOnly = require('./region-matchers/inline-c-only');
const inlineHash = require('./region-matchers/inline-hash');
const DEFAULT_PLASTER = '. . .';
const {mapObject} = require('../../helpers/utils');

module.exports = function regionParser() {
  return regionParserImpl;
};

regionParserImpl.regionMatchers = {
  ts: inlineC,
  js: inlineC,
  es6: inlineC,
  dart: inlineC,
  html: html,
  svg: html,
  css: blockC,
  yaml: inlineHash,
  yml: inlineHash,
  jade: inlineCOnly,
  pug: inlineCOnly,
  json: inlineC,
  'json.annotated': inlineC
};

/**
 * @param contents string
 * @param fileType string
 * @returns {contents: string, regions: {[regionName: string]: string}}
 */
function regionParserImpl(contents, fileType) {
  const regionMatcher = regionParserImpl.regionMatchers[fileType];
  const openRegions = [];
  const regionMap = {};

  if (regionMatcher) {
    let plaster = regionMatcher.createPlasterComment(DEFAULT_PLASTER);
    const lines = contents.split(/\r?\n/).filter((line, index) => {
      const startRegion = line.match(regionMatcher.regionStartMatcher);
      const endRegion = line.match(regionMatcher.regionEndMatcher);
      const updatePlaster = line.match(regionMatcher.plasterMatcher);

      // start region processing
      if (startRegion) {
        // open up the specified region
        const regionNames = getRegionNames(startRegion[1]);
        if (regionNames.length === 0) {
          regionNames.push('');
{'fraction_non_alphanumeric': 0.14233687405159332, 'fraction_numerical': 0.003338391502276176, 'mean_word_length': 4.039755351681957, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3401663', 'n_tokens_mistral': 1002, 'n_tokens_neox': 977, 'n_words': 223}