@@ -130,3 +130,61 @@ write_docx <- function(rtf, file) {
130130
131131 invisible (file )
132132}
133+
134+ # ' Write an RTF Table or Figure to an HTML File
135+ # '
136+ # ' @description
137+ # ' The write_html function writes an RTF encoding string to an .html file
138+ # ' by first writing to a temporary RTF file and then converting it to HTML
139+ # ' using LibreOffice.
140+ # '
141+ # ' @section Specification:
142+ # ' \if{latex}{
143+ # ' \itemize{
144+ # ' \item Write RTF encoding to a temporary RTF file.
145+ # ' \item Convert RTF to HTML using LibreOffice command-line tool via \code{rtf_convert_format()}.
146+ # ' }
147+ # ' }
148+ # ' \if{html}{The contents of this section are shown in PDF user manual only.}
149+ # '
150+ # ' @param rtf A character rtf encoding string rendered by `rtf_encode()`.
151+ # ' @param file A character string naming a file to save html file.
152+ # '
153+ # ' @details
154+ # ' This function requires LibreOffice to be installed on the system.
155+ # ' The function uses the internal \code{rtf_convert_format()} function
156+ # ' to perform the conversion from RTF to HTML format.
157+ # '
158+ # ' Currently only Unix/Linux/macOS systems are supported.
159+ # '
160+ # ' @export
161+ write_html <- function (rtf , file ) {
162+ # Normalize the output file path
163+ file <- normalizePath(file , mustWork = FALSE )
164+
165+ # Create output directory if it doesn't exist
166+ output_dir <- dirname(file )
167+ if (! dir.exists(output_dir )) {
168+ dir.create(output_dir , recursive = TRUE )
169+ }
170+
171+ # Create a temporary RTF file
172+ tmpdir <- tempfile(pattern = " r2rtf_" )
173+ dir.create(tmpdir )
174+ on.exit(unlink(tmpdir , recursive = TRUE ), add = TRUE )
175+
176+ file_basename <- tools :: file_path_sans_ext(basename(file ))
177+ rtf_path <- file.path(tmpdir , paste0(file_basename , " .rtf" ))
178+ write_rtf(rtf , rtf_path )
179+
180+ # Convert RTF to HTML using existing rtf_convert_format function
181+ rtf_convert_format(
182+ input = rtf_path ,
183+ output_file = basename(file ),
184+ output_dir = output_dir ,
185+ format = " html" ,
186+ overwrite = TRUE
187+ )
188+
189+ invisible (file )
190+ }
0 commit comments