docs: protected String buildCorePublicanCfgFile(final BuildData buildData, final String publicanCfgTemplate) {
          final ContentSpec contentSpec = buildData.getContentSpec();
          final Map<String, String> overrides = buildData.getBuildOptions().getOverrides();
  
          final String brandOverride = overrides.containsKey(CSConstants.BRAND_OVERRIDE) ? overrides.get(
                  CSConstants.BRAND_OVERRIDE) : (overrides.containsKey(CSConstants.BRAND_ALT_OVERRIDE) ? overrides.get(
                  CSConstants.BRAND_ALT_OVERRIDE) : null);
          final String brand = brandOverride != null ? brandOverride : (contentSpec.getBrand() == null ? getDefaultBrand(
                  buildData) : contentSpec.getBrand());
  
          // Setup publican.cfg
          String publicanCfg = publicanCfgTemplate.replaceAll(BuilderConstants.BRAND_REGEX, brand);
          publicanCfg = publicanCfg.replaceFirst("type\\s*:\\s*.*($|\\r\\n|\\n)",
                  "type: " + contentSpec.getBookType().toString().replaceAll("-Draft", "") + "\n");
          publicanCfg = publicanCfg.replaceAll("xml_lang\\s*:\\s*.*?($|\\r\\n|\\n)", "xml_lang: " + buildData.getOutputLocale() + "\n");
  
          // Remove the image width
          publicanCfg = publicanCfg.replaceFirst("max_image_width\\s*:\\s*\\d+\\s*(\\r)?\\n", "");
          publicanCfg = publicanCfg.replaceFirst("toc_section_depth\\s*:\\s*\\d+\\s*(\\r)?\\n", "");
  
          // Minor formatting cleanup
          publicanCfg = publicanCfg.trim() + "\n";
  
          // Add the dtdver property
          if (buildData.getDocBookVersion() == DocBookVersion.DOCBOOK_50) {
              publicanCfg += "dtdver: \"5.0\"\n";
          }
  
          if (contentSpec.getPublicanCfg() != null) {
              // If the user publican.cfg doesn't contain a chunk_section_depth, then add a calculated one
              if (buildData.getBuildOptions().getCalculateChunkDepth() && !contentSpec.getPublicanCfg().contains("chunk_section_depth")) {
                  publicanCfg += "chunk_section_depth: " + calcChunkSectionDepth(buildData) + "\n";
              }
  
              // Remove the git_branch if the content spec contains a git_branch
              if (contentSpec.getPublicanCfg().contains("git_branch")) {
                  publicanCfg = publicanCfg.replaceFirst("git_branch\\s*:\\s*.*(\\r)?(\\n)?", "");
              }
  
              publicanCfg += DocBookBuildUtilities.cleanUserPublicanCfg(contentSpec.getPublicanCfg());
          } else if (buildData.getBuildOptions().getCalculateChunkDepth()) {
              publicanCfg += "chunk_section_depth: " + calcChunkSectionDepth(buildData) + "\n";
          }
  
          if (buildData.getBuildOptions().getPublicanShowRemarks()) {
              // Remove any current show_remarks definitions
              if (publicanCfg.contains("show_remarks")) {
                  publicanCfg = publicanCfg.replaceAll("show_remarks\\s*:\\s*\\d+\\s*(\\r)?(\\n)?", "");
              }
              publicanCfg += "show_remarks: 1\n";
          }
  
          // Add docname if it wasn't specified and the escaped title is valid
          Matcher m = null;
          if (BuilderConstants.VALID_PUBLICAN_DOCNAME_PATTERN.matcher(buildData.getEscapedBookTitle()).matches()) {
              m = DOCNAME_PATTERN.matcher(publicanCfg);
              if (!m.find()) {
                  publicanCfg += "docname: " + buildData.getEscapedBookTitle().replaceAll("_", " ") + "\n";
              }
          }
  
          // Add product if it wasn't specified
          m = PRODUCT_PATTERN.matcher(publicanCfg);
          if (!m.find()) {
              publicanCfg += "product: " + escapeProduct(buildData.getOriginalBookProduct()) + "\n";
          }
  
          // Add the mainfile attribute
          publicanCfg += "mainfile: " + buildData.getRootBookFileName() + "\n";
  
          // Add a version if one wasn't specified
          m = VERSION_PATTERN.matcher(publicanCfg);
          if (!m.find()) {
              String version = contentSpec.getBookVersion();
              if (isNullOrEmpty(version)) {
                  version = DocBookBuildUtilities.getKeyValueNodeText(buildData, contentSpec.getVersionNode());
              }
              if (isNullOrEmpty(version)) {
                  version = BuilderConstants.DEFAULT_VERSION;
              }
              publicanCfg += "version: " + escapeVersion(version) + "\n";
          }
  
          return applyPublicanCfgOverrides(buildData, publicanCfg);
      }