<commit_before>﻿/*
 * ExportChapterAsIDML.jsx
 *
 *
 * Exports selected chapters from an INDB file to IDML and creates a result XML file.
 *
 *
 * Note: this script requires at least InDesign Version 6.0 (CS4).
 *
 * Authors: <NAME>, <NAME> (@mkraetke)
 *
 * Parts of this script originate from the work of <NAME>.
 */
#target indesign;

version = "v1.0.1";

lang = {
    pre: app.locale == 1279477613 ? 1 : 0 // en = 0, de = 1
}
panel = {
  title:["le-tex – Export INDB as IDML", "le-tex – INDB als IDML exportieren"][lang.pre],
  selectDirTitle:["Select output directory", "Speicherort auswählen"][lang.pre],
  buttonDirSelect:["Select", "Auswählen"][lang.pre],
  selectChaptersTitle:["Select book parts", "Buchteile auswählen"][lang.pre],
  buttonSelectAll:["Select all", "Alle markieren"][lang.pre],
  buttonDeselect:["Deselect all", "Auswahl aufheben"][lang.pre],
  buttonInvertSelection:["Invert selection", "Auswahl umkehren"][lang.pre],
  buttonOk:"OK",
  buttonCancel:["Cancel", "Abbrechen"][lang.pre],
  exportMsg:["Exporting...", "Exportiere..."][lang.pre],
  versionErrorMsg:["InDesign versions prior to CS4 are not supported.", "InDesign-Versionen vor CS4 werden nicht unterstützt."][lang.pre],
  finishedMsg:["Finished!", "Fertig!"][lang.pre],
  selectBookTitle:["Select INDB file", "INDB-Datei auswählen"][lang.pre],
  selectBookErrorMsg:["No INDB file selected", "Keine INDB-Datei geöffnet"][lang.pre]
}
values = {
  outputDir:null,
  selectedChapters:null
}
// Nur ausführbar, ab CS4 aufwärts
var myVersion = app.scriptPreferences.version;
if(Number(myVersion.slice(0, myVersion.indexOf("."))) > 5) {
  export_to_idml (app.books.item (get_book ()));
} else {
  alert(panel.versionErrorMsg)
}
function export_to_idml (book) {
  var win = draw_window(book);
  var myDefaultInteraction = app.scriptPreferences.userInteractionLevel;
  app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
  chapters_to_idml (book, values.selectedChapters.chapters, values.outputDir);
  app.scriptPreferences.userInteractionLevel = myDefaultInteraction;
}
function chapters_to_idml (thisbook, chapters, dir) {
  var myScriptFileName = app.activeScript;
  var myScriptFile = File(myScriptFileName);
  var myFolder = Folder(dir);
  if(myFolder != null){
    var myFolderName = myFolder.fsName; // Windows-spezifische Namenskonvention ( /f/TEMP/  ==>  F:\TEMP )
    var myDefaultViewPDF = app.pdfExportPreferences.viewPDF;
    var f;
    var myDocList = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r";
    var myFolderPath = "";
    if (myFolder.fullName.match(/^\/\w\//g)) myFolderPath = "/" + myFolder.fullName.substr(1, 1) + ":" + myFolder.fullName.slice(2,); // A) Netzlaufwerk (z.B. "/i/indesign")
    else if (myFolder.fullName.match(/^~/g)) myFolderPath = "/" + myFolder.fsName.replace(/\\/g, "/"); // B) Nutzerverzeichnis (z.B. "~/Desktop/...")
    else myFolderPath = myFolder.fullName; // C) Serverpfad (z.B. "//Rennratte/indesign/...")
    myDocList += "<collection stable=\"true\" xml:base=\"file:" + myFolderPath + "/\">\r";
    var p_list = progress_list (create_list (chapters), panel.exportMsg);
    for (var i = 0; i < chapters.length; i++){
      try{
        p_list[i].text = '+';
        var myDoc = app.open (chapters[i], false);
        f = new File (myFolderName + "\\" + chapters[i].name.replace(/indd$/, 'idml'));
        myDoc.exportFile(ExportFormat.INDESIGN_MARKUP, f, false);
        myDoc.close(SaveOptions.NO);
        myDocList += "	<doc href=\"" + chapters[i].name.replace(/indd$/, 'idml') + "\"/>\r";
      } catch(e) {
        alert(e);
      }
    }
    p_list[0].parent.parent.close ();
    myDocList += "</collection>";<commit_msg>replace special chars in dir path<commit_after>﻿/*
 * ExportChapterAsIDML.jsx
 *
 *
 * Exports selected chapters from an INDB file to IDML and creates a result XML file.
 *
 *
 * Note: this script requires at least InDesign Version 6.0 (CS4).
 *
 * Authors: <NAME>, <NAME> (@mkraetke)
 *
 * Parts of this script originate from the work of <NAME>.
 */
#target indesign;

version = "v1.0.2";

lang = {
    pre: app.locale == 1279477613 ? 1 : 0 // en = 0, de = 1
}
panel = {
  title:["le-tex – Export INDB as IDML", "le-tex – INDB als IDML exportieren"][lang.pre],
  selectDirTitle:["Select output directory", "Speicherort auswählen"][lang.pre],
  buttonDirSelect:["Select", "Auswählen"][lang.pre],
  selectChaptersTitle:["Select book parts", "Buchteile auswählen"][lang.pre],
  buttonSelectAll:["Select all", "Alle markieren"][lang.pre],
  buttonDeselect:["Deselect all", "Auswahl aufheben"][lang.pre],
  buttonInvertSelection:["Invert selection", "Auswahl umkehren"][lang.pre],
  buttonOk:"OK",
  buttonCancel:["Cancel", "Abbrechen"][lang.pre],
  exportMsg:["Exporting...", "Exportiere..."][lang.pre],
  versionErrorMsg:["InDesign versions prior to CS4 are not supported.", "InDesign-Versionen vor CS4 werden nicht unterstützt."][lang.pre],
  finishedMsg:["Finished!", "Fertig!"][lang.pre],
  selectBookTitle:["Select INDB file", "INDB-Datei auswählen"][lang.pre],
  selectBookErrorMsg:["No INDB file selected", "Keine INDB-Datei geöffnet"][lang.pre]
}
values = {
  outputDir:null,
  selectedChapters:null
}
// Nur ausführbar, ab CS4 aufwärts
var myVersion = app.scriptPreferences.version;
if(Number(myVersion.slice(0, myVersion.indexOf("."))) > 5) {
  export_to_idml (app.books.item (get_book ()));
} else {
  alert(panel.versionErrorMsg)
}
function export_to_idml (book) {
  var win = draw_window(book);
  var myDefaultInteraction = app.scriptPreferences.userInteractionLevel;
  app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
  chapters_to_idml (book, values.selectedChapters.chapters, values.outputDir);
  app.scriptPreferences.userInteractionLevel = myDefaultInteraction;
}
function chapters_to_idml (thisbook, chapters, dir) {
  var myScriptFileName = app.activeScript;
  var myScriptFile = File(myScriptFileName);
  var myFolder = Folder(dir);
  if(myFolder != null){
    var myFolderName = myFolder.fsName; // Windows-spezifische Namenskonvention ( /f/TEMP/  ==>  F:\TEMP )
    var myDefaultViewPDF = app.pdfExportPreferences.viewPDF;
    var f;
    var myDocList = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r";
    var myFolderPath = "";
    if (myFolder.fullName.match(/^\/\w\//g)) myFolderPath = "/" + myFolder.fullName.substr(1, 1) + ":" + myFolder.fullName.slice(2,); // A) Netzlaufwerk (z.B. "/i/indesign")
    else if (myFolder.fullName.match(/^~/g)) myFolderPath = "/" + myFolder.fsName.replace(/\\/g, "/"); // B) Nutzerverzeichnis (z.B. "~/Desktop/...")
    else myFolderPath = myFolder.fullName; // C) Serverpfad (z.B. "//Rennratte/indesign/...")
    myFolderPath = myFolderPath.replace(/[%&,; \(\)]/g, '_');
    myDocList += "<collection stable=\"true\" xml:base=\"file:" + myFolderPath + "/\">\r";
    var p_list = progress_list (create_list (chapters), panel.exportMsg);
    for (var i = 0; i < chapters.length; i++){
      try{
        p_list[i].text = '+';
        var myDoc = app.open (chapters[i], false);
        f = new File (myFolderName + "\\" + chapters[i].name.replace(/indd$/, 'idml'));
        myDoc.exportFile(ExportFormat.INDESIGN_MARKUP, f, false);
        myDoc.close(SaveOptions.NO);
        myDocList += "	<doc href=\"" + chapters[i].name.replace(/indd$/, 'idml') + "\"/>\r";
      } catch(e) {
        alert(e);
      }
    }
    p_list[0].parent.parent.close ();
    myDocList += "</collection>";
{'fraction_non_alphanumeric': 0.17309753483386925, 'fraction_numerical': 0.008842443729903537, 'mean_word_length': 4.071331521739131, 'pattern_counts': {'":': 2, '<': 19, '<?xml version=': 2, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1656226', 'n_tokens_mistral': 2650, 'n_tokens_neox': 2624, 'n_words': 545}