xml2 read_html removes closing tags from JSON-LD when using a single option
还没有人认领这个 Issue。
评估
调研方向
Start with the read_html(options=...) entry point and reproduce the difference between default parsing and a single option using the issue's JSON-LD example. Trace option handling and add a regression test; done means closing tags inside the JSON-LD description remain intact while the requested option still works.
由索引模型根据 Issue 内容生成。
描述
xml2::read_html(x) returns the HTML within a linked data JSON object as expected:
library(xml2)
library(magrittr)
library(rvest)
test_ld <- '<script type="application/ld+json">{"@context":"http://schema.org","@type":"ReproducibleExample", "description":"<p><strong>text within tags</strong>text after closing tag</p>"'
# tags preserved
test_ld %>%
read_html() %>%
html_node('script[type="application/ld+json"]') %>%
as.character()
[1] "<script type=\"application/ld+json\">{\"@context\":\"http://schema.org\",\"@type\":\"ReproducibleExample\", \"description\":\"<p><strong>text within tags</strong>text after closing tag</p>\"</script>"
Where description contains the HTML <p><strong>text within tags</strong>text after closing tag</p>
But if using xml2::read_html(x, options = 'HUGE') or with any single option (I've tested 5 or 6), the closing tags are removed from the HTML text in a JSON-LD object.
# tags removed
test_ld %>%
read_html(options = 'HUGE') %>%
html_node('script[type="application/ld+json"]') %>%
as.character()
# removed
test_ld %>%
read_html(options = "NOBLANKS") %>%
html_node('script[type="application/ld+json"]') %>%
as.character()
# removed
test_ld %>%
read_html(options = '') %>%
html_node('script[type="application/ld+json"]') %>%
as.character()
# all return:
[1] "<script type=\"application/ld+json\">{\"@context\":\"http://schema.org\",\"@type\":\"ReproducibleExample\", \"description\":\"<p><strong>text within tagstext after closing tag\"</script
description now becomes <p><strong>text within tagstext after closing tag
Setting options is necessary for some of the HTML I'm parsing. Is it possible to use options and preserve properly formatted HTML from a linked data object?
- 主要语言
- R
- 星标
- 227
- 派生
- 86
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
r-lib/xml2 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 67/100
-
难度 4/5 3-5 天 新手友好度 48/100
-
Optimize xml_path() and xml_find_all() for large node sets可能已有人在做 @astruebi 于 182 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 45/100
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 3/5 1-2 天 新手友好度 45/100
相似的 Issue
-
num_ode_rk4_adaptive rejects atol = 0 while accepting rtol = 0 and while num_ode_dopri5 accepts both未关闭area/ode-pde good first issue help wanted kind/contract severity/4-minor
难度 2/5 1-3 小时 新手友好度 78/100
Apich-Organization/rssn#383 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
PRL-PRG/r-compile-server#70 · 1 条评论 ·
-
dependencies docker enhancement
难度 2/5 1-3 小时 新手友好度 74/100
posit-dev/images-workbench#257 ·
维护者通常 1 天内回复
-
dependencies docker enhancement
难度 2/5 1-3 小时 新手友好度 72/100
posit-dev/images-package-manager#188 ·
维护者通常 1 天内回复
-
dependencies docker enhancement
难度 2/5 1-3 小时 新手友好度 68/100
posit-dev/images-connect#222 ·
维护者通常 1 天内回复