OpenInIAWriterAsNewFile

Open in iA Writer as New File
  This Drumkit sample sends the text from the current outline to iA Writer as a new document.
  This can be useful for previewing Markdown.
  Created by Gary Teter.
  To install this
    Open the latest version of this Drumkit in Drummer
      File → Open URL...
      https://raw.githubusercontent.com/PostMonsterG/drumkit-samples/main/OpenInIAWriterAsNewFile/OpenInIAWriterAsNewFile.opml
    Add this Drumkit to your scripts menu in Drummer
      Select the entire outline, i.e., the above Open in iA Writer as New File node that contains all this
      Copy it (⌘C)
      File → Special Files... → Scripts menu...
      Paste this outline (⌘V)
      There should be a new Open in iA Writer as New File entry in your scripts menu.
  To use this
    Select Open in iA Writer as New File from your scripts menu
    The text from the current outline will be sent to iA Writer as a new document.
    Indentation and node structure is ignored.
    Each node becomes a new line of text.
    There is a 4,000-character limit to the amount of text which can be sent this way.
  // Here is the code
    const text = GetOutlineContents()
    const url = BuildURL( text )
    webBrowser.openUrl( url )
    // Functions
      // Get the contents of the outline
        function GetOutlineContents() {
          var Buffer = "";
          const cursor = op.getCursor()
          op.firstSummit()
          op.visitAll(
            function(node, level) {
              const line = node.getLineText()
              Buffer = Buffer + line + "\n"
              })
          op.setCursor( cursor )
          return Buffer
          }
      // Construct the URL
        function BuildURL(Text) {
          var encoded = encodeURI( Text )
          encoded = string.multipleReplaceAll( encoded, {
            "#" : "%23"
            })
          const URL = "ia-writer://new?edit=true&text=" + encoded
          return URL
          }