Skip to content

Commit 33ccd90

Browse files
committed
use dev markitdown
- contains fix for `pre` microsoft/markitdown#322 - DocumentConverterResult moved
1 parent 2e9eb5b commit 33ccd90

File tree

2 files changed

+29
-24
lines changed

2 files changed

+29
-24
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
S3method(reticulate::py_to_r,markitdown._markitdown.DocumentConverterResult)
43
export(RagnarStore)
54
export(embed_ollama)
65
export(embed_openai)

R/ragnar-package.R

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,42 @@
44

55
.globals <- new.env(parent = emptyenv())
66

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) {
99
c(title = x$title, text = x$text_content)
1010
}
1111

1212

1313
.onLoad <- function(libname, pkgname) {
1414
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"))
1716

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() {
3618

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+
# }
3744
})
3845
}
39-

0 commit comments

Comments
 (0)