|
4 | 4 |
|
5 | 5 | .globals <- new.env(parent = emptyenv()) |
6 | 6 |
|
7 | | -#' @exportS3Method reticulate::py_to_r |
8 | | -py_to_r.markitdown._markitdown.DocumentConverterResult <- function(x) { |
| 7 | +# ' @exportS3Method reticulate::py_to_r |
| 8 | +py_to_r.markitdown.DocumentConverterResult <- function(x) { |
9 | 9 | c(title = x$title, text = x$text_content) |
10 | 10 | } |
11 | 11 |
|
12 | 12 |
|
13 | 13 | .onLoad <- function(libname, pkgname) { |
14 | 14 | Sys.setenv(RETICULATE_PYTHON = "managed") |
15 | | - reticulate::py_require("markitdown") |
16 | | - reticulate:::py_register_load_hook("markitdown", function() { |
| 15 | + reticulate::py_require(c("markitdown" = "git+https://github.com/microsoft/markitdown.git@main#subdirectory=packages/markitdown")) |
17 | 16 |
|
18 | | - `_CustomMarkdownify` <- reticulate::import("markitdown._markitdown")$`_CustomMarkdownify` |
19 | | - og_convert_a <- `_CustomMarkdownify`$convert_a |
20 | | - `_CustomMarkdownify`$convert_a <- function(self, el, text, convert_as_inline) { |
21 | | - # patch to prevent generating links in the markdown if |
22 | | - # - if the link is in a pre-formatted code block |
23 | | - # - if the link is to rdrr.io/r (autogenerated by pkgdown) |
24 | | - tryCatch({ |
25 | | - if (el$get("href", "") |> startsWith("https://rdrr.io/r")) { |
26 | | - return(text) |
27 | | - } |
28 | | - |
29 | | - if (!is.null(el$find_parent("pre"))) { |
30 | | - return(text) |
31 | | - } |
32 | | - }, error = warning) |
33 | | - |
34 | | - og_convert_a(self, el, text, convert_as_inline) |
35 | | - } |
| 17 | + reticulate:::py_register_load_hook("markitdown", function() { |
36 | 18 |
|
| 19 | + registerS3method( |
| 20 | + "py_to_r", |
| 21 | + nameOfClass(reticulate::import("markitdown")$DocumentConverterResult), |
| 22 | + py_to_r.markitdown.DocumentConverterResult, |
| 23 | + environment(reticulate::py_to_r) |
| 24 | + ) |
| 25 | + |
| 26 | + # `_CustomMarkdownify` <- reticulate::import("markitdown._markitdown")$`_CustomMarkdownify` |
| 27 | + # og_convert_a <- `_CustomMarkdownify`$convert_a |
| 28 | + # `_CustomMarkdownify`$convert_a <- function(self, el, text, convert_as_inline) { |
| 29 | + # # patch to prevent generating links in the markdown if |
| 30 | + # # - if the link is in a pre-formatted code block |
| 31 | + # # - if the link is to rdrr.io/r (autogenerated by pkgdown) |
| 32 | + # tryCatch({ |
| 33 | + # if (el$get("href", "") |> startsWith("https://rdrr.io/r")) { |
| 34 | + # return(text) |
| 35 | + # } |
| 36 | + # |
| 37 | + # if (!is.null(el$find_parent("pre"))) { |
| 38 | + # return(text) |
| 39 | + # } |
| 40 | + # }, error = warning) |
| 41 | + # |
| 42 | + # og_convert_a(self, el, text, convert_as_inline) |
| 43 | + # } |
37 | 44 | }) |
38 | 45 | } |
39 | | - |
|
0 commit comments