1# 2# SessionQuarto.R 3# 4# Copyright (C) 2021 by RStudio, PBC 5# 6# Unless you have received this program directly from RStudio pursuant 7# to the terms of a commercial license agreement with RStudio, then 8# this program is licensed to you under the terms of version 3 of the 9# GNU Affero General Public License. This program is distributed WITHOUT 10# ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, 11# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the 12# AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. 13# 14# 15 16.rs.addFunction("quarto.servePort", function() { 17 if (requireNamespace("quarto", quietly = TRUE)) { 18 if (!is.null(quarto:::quarto$serve_ps) && quarto:::quarto$serve_ps$is_alive()) { 19 if (is.numeric(quarto:::quarto$serve_port)) { 20 quarto:::quarto$serve_port 21 } else { 22 0 23 } 24 } else { 25 0 26 } 27 } else { 28 0 29 } 30}) 31 32.rs.addFunction("quarto.renderPreview", function(port) { 33 utils::download.file(paste0("http://localhost:", port, "/quarto-render/"), 34 destfile = tempfile(), 35 quiet = TRUE, 36 cacheOK = FALSE) 37}) 38