sharedScripts

This is an outline of Drummer scripts to share
Thanks to Frank McPherson for the idea
testRendererC
  tab.openFile ("rendertest01.opml")
  var s = "";
  var htmlText = "";
  const htmltextHeader = "";
  const htmltextFooter = "";
  op.firstSummit()
  dialog.alert(op.getLineText())
  while (true) {

    s = s + op.getLineText() + "
    "

    if (!op.go (down, 1)) {
      break;
      }
    }
  console.log (s)
  htmlText = htmltextHeader + s + htmltextFooter;
  console.log (htmlText )
  file.writeWholeFile ("render03.html", htmlText );
  const url = file.makeFilePublic ("render03.html");
  webBrowser.openUrl (url)
twoLevelOutlineRenderer
  Script Header
    Author: Andy Sylvester
    URL: http://oldschool.scripting.com/AndySylvester99/
    Github repo: https://github.com/andysylvester/drummer-outline-renderers
    Revision History:
      Revision: C
        Date: 1/8/2022
        Added ability for user to specify file name of rendered file as an attribute in the OPML file header
        Corrected a bug on rendering of the first headline in the OPML file if there are subs present
        Closes issue 5 (https://github.com/andysylvester/drummer-outline-renderers/issues/5)
      Revision: B
        Date: 11/1/2021
        Changed the .replace statement to replace double-quotes with single quotes, URL links now work (https://stackoverflow.com/questions/8207297/how-to-replace-all-double-quotes-to-single-quotes-using-jquery/8207316#8207316)
        Closes issue 2 (https://github.com/andysylvester/drummer-outline-renderers/issues/2)
      Revision: A
        Date: 11/1/2021
        Added logic to read the first headline/summit (I thought it was getting read, but my test file (ledes.opml) had a blank summit headline, so I missed it)
        Closes issue 1 (https://github.com/andysylvester/drummer-outline-renderers/issues/1)
      Revision: Original
        Date: 11/1/2021
        First release of script
    Instructions:
      1. Copy this script to your Scripts menu outline
      2. Open a new tab with the outline to be rendered or select an open tab
      3. Select "twoLevelOutlineRenderer" from Scripts menu
      4. Drummer will open a new tab with your rendered outline
      5. If the new tab contains "object Object" as the rendered text, do a reload of the page. If that does not display the rendered text, go back to the Drummer tab and run the script again. A new tab will open and should have the rendered outline.
      6. To specify the file name of the rendered file, open the source OPML file in a tab, click on the suitcase icon, click on the plus sign to add an attribute, enter "htmlFileName" in the first column text field (without quotes), then enter the name of the filename in the second column text field (for example, "essay.html") without quotes.
      7. If a public/Instant Outline OPML file is being rendered, the rendered file name will be "myOutline.html".
      8. If a private OPML file is being rendered without the OPML file header attribute, the rendered file name will be "myOutline.html"
  var s = "";
  var mytest = "";
  var url = "";
  var isTabActive = false;
  var isInstantOutline = false;
  var isHtmlFileNamePresent= false;
  var myPrefsString = file.readWholeFile ("prefs.json");
  var myPrefs = JSON.parse(myPrefsString);
  var numOfTabs = myPrefs.tabs.length;
  var headers = opml.getHeaders ();
  var tabCount = 0;
  var activeTab = 0;
  var tabFilename = "";
  var testString2 = "REPLACEME";
  var urlTemplate = "https://andysylvester.com/files/rendertest/renderTemplate.html";
  var htmltext = http.readUrl (urlTemplate);
  op.expandAllLevels ()
  op.firstSummit()
  var clearQuoteFirst = op.getLineText();
  var htmltextNewFirst = clearQuoteFirst .replace (/"/g, "'");

  s = s + htmltextNewFirst + "
  "

  if (op.hasSubs()) {
    var total = op.countSubs();
    var count = 0;
    op.go (right, 1)
    while (count < total) {
      var clearQuote2 = op.getLineText();
      var htmltextNewB2 = clearQuote2 .replace (/"/g, "'");
      console.log (htmltextNewB2);

      s = s + htmltextNewB2 + "
      "

      op.go(down, 1)
      count = count + 1;
      }
    op.go (flatup, 1)
    }
  while (op.go (down, 1)) {
    var clearQuote = op.getLineText();
    var htmltextNewB = clearQuote .replace (/"/g, "'");

    s = s + htmltextNewB + "
    "

    if (op.hasSubs()) {
      var total = op.countSubs();
      var count = 0;
      op.go (right, 1)
      while (count < total) {
        var clearQuote2 = op.getLineText();
        var htmltextNewB2 = clearQuote2 .replace (/"/g, "'");
        console.log (htmltextNewB2);

        s = s + htmltextNewB2 + "
        "

        op.go(down, 1)
        count = count + 1;
        }
      op.go (flatup, 1)
      }
    }
  console.log (s)
  var htmltextNewA = htmltext.replace (testString2, s);
  console.log (htmltextNewA );
  Read htmlFileName from OPML header for specified file
  while (tabCount < numOfTabs) {
    console.log ("tabCount = ", tabCount);
    console.log ("flInstantOutline = ", myPrefs.tabs[tabCount].flInstantOutline);
    console.log ("flActive = ", myPrefs.tabs[tabCount].flActive);
    isTabActive = myPrefs.tabs[tabCount].flActive;
    isInstantOutline = myPrefs.tabs[tabCount].flInstantOutline;
    console.log ("isTabActive = ", isTabActive);
    console.log ("isInstantOutine = ", isInstantOutline);
    tabFilename = myPrefs.tabs[tabCount].fname;
    console.log ("tabFilename = ", tabFilename);
    isHtmlFileNamePresent= opml.attributes.exists(tabFilename, "htmlFileName");
    isHtmlFileNamePresent = headers.hasOwnProperty('htmlFileName');
    console.log ("isHtmlFileNamePresent= ", isHtmlFileNamePresent);
    tabCount = tabCount + 1;
    if (isTabActive) {
      console.log ("Got inside loop");
      if (isInstantOutline) {
        console.log ("Got inside Instant Outline loop");
        if (isHtmlFileNamePresent) {
          mytest = headers.htmlFileName;
          console.log ("mytest = ", mytest);
          }
          else {
            mytest = "myOutline.html";
            console.log ("mytest = ", mytest);
            console.log ("tabFilename = ", tabFilename);
            }
        mytest = "myOutline.html";
        console.log ("mytest = ", mytest);
        }
        else {
          if (isHtmlFileNamePresent) {
            mytest = opml.attributes.getOne (tabFilename, "htmlFileName");
            mytest = headers.htmlFileName;
            console.log ("mytest = ", mytest);
            }
            else {
              mytest = "myOutline.html";
              console.log ("mytest = ", mytest);
              console.log ("tabFilename = ", tabFilename);
              }
          }
        }
      }
    }
  while (tabCount < numOfTabs) { // OLD
    console.log ("flInstantOutline = ", myPrefs.tabs[tabCount].flInstantOutline);
    console.log ("flActive = ", myPrefs.tabs[tabCount].flActive);
    isTabActive = myPrefs.tabs[tabCount].flActive;
    console.log ("isTabActive = ", isTabActive);
    console.log ("tabCount = ", tabCount);
    if (isTabActive === true) {
      activeTab = tabCount;
      console.log ("flActive =" myPrefs.tabs[tabCount].flActive);
      }
    if (myPrefs.tabs[tabCount].flActive === true) {
      activeTab = tabCount;
      console.log ("flActive =" myPrefs.tabs[tabCount].flActive);
      }
      if (myPrefs.tabs[tabCount].flInstantOutline) === false)
        tabFilename = myPrefs.tabs[tabCount].fname;
        if (opml.attributes.exists (tabFilename, "htmlFileName") === true) {
          mytest = opml.attributes.getOne (tabFilename, "htmlFileName");
          }
          else {
            mytest = "myOutline.html";
            }
        else {
          mytest = "myOutline.html";
          }
      if (myPrefs.tabs[tabCount].flInstantOutline === false) {
        tabFilename = myPrefs.tabs[tabCount].fname;
        if (opml.attributes.exists (tabFilename, "htmlFileName") === true) {
          mytest = opml.attributes.getOne (tabFilename, "htmlFileName");
          }
          else {
            mytest = "myOutline.html";
            }
        else {
          mytest = "myOutline.html";
          }
      }
    console.log (myPrefs.tabs[tabCount].flInstantOutline))
      tabFilename = myPrefs.tabs[tabCount].fname;
      if (opml.attributes.exists (tabFilename, "htmlFileName") === true) {
        mytest = opml.attributes.getOne (tabFilename, "htmlFileName");
        }
        else {
          mytest = "myOutline.html";
          }
      else {
        mytest = "myOutline.html";
        }
    tabCount = tabCount + 1;
    }
  console.log(activeTab);
  console.log(tabFilename);
  mytest = opml.attributes.getOne (tabFilename, "htmlFileName");
  console.log("mytest =", mytest);
  file.writeWholeFile ("myOutline.html", htmltextNewA );
  file.writeWholeFile (mytest, htmltextNewA );
  const url = file.makeFilePublic ("myOutline.html");
  url = file.makeFilePublic (mytest);
  console.log(url);
  webBrowser.openUrl (url)