xml2 read_html removes closing tags from JSON-LD when using a single option

Aperta
#373 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
r, xml
Ambito
tooling

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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?

Lingua principale
R
Stelle
227
Fork
86
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di r-lib/xml2

Tutte le issue di r-lib/xml2

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.