From e3b1484571550a4b79a4267047ec6945ddbec3f8 Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:34:05 +0300 Subject: [PATCH 1/4] Rename `plaintext` to `text_markdown` --- src/response.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index 64ef9bd..d49cabd 100644 --- a/src/response.rs +++ b/src/response.rs @@ -66,7 +66,7 @@ impl Response { } #[getter] - fn plaintext(&mut self, py: Python) -> PyResult { + fn text_markdown(&mut self, py: Python) -> PyResult { let raw_bytes = self.content.bind(py).as_bytes(); let text = from_read(raw_bytes, 1080); Ok(text) From ac26941af6b05c2bc030d4f809775202d0cd3bec Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:35:23 +0300 Subject: [PATCH 2/4] fn text_markdown: `width`=usize::MAX --- src/response.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index d49cabd..d70bc2d 100644 --- a/src/response.rs +++ b/src/response.rs @@ -68,7 +68,7 @@ impl Response { #[getter] fn text_markdown(&mut self, py: Python) -> PyResult { let raw_bytes = self.content.bind(py).as_bytes(); - let text = from_read(raw_bytes, 1080); + let text = from_read(raw_bytes, usize::MAX); Ok(text) } } From 71130c715b03e08f405946f38cf7b2f2f1e87d30 Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:36:46 +0300 Subject: [PATCH 3/4] Response: add attrib `text_plain` --- src/response.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/response.rs b/src/response.rs index d70bc2d..3e35d6a 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,5 +1,5 @@ use encoding_rs::Encoding; -use html2text::from_read; +use html2text::{from_read, from_read_with_decorator, render::text_renderer::TrivialDecorator}; use pyo3::exceptions; use pyo3::prelude::*; use pyo3::types::{PyBytes, PyDict, PyString}; @@ -71,4 +71,11 @@ impl Response { let text = from_read(raw_bytes, usize::MAX); Ok(text) } + + #[getter] + fn text_plain(&mut self, py: Python) -> PyResult { + let raw_bytes = self.content.bind(py).as_bytes(); + let text = from_read_with_decorator(raw_bytes, usize::MAX, TrivialDecorator::new()); + Ok(text) + } } From b184a6f876cb806bb5d60c4a6cb11261b07e34db Mon Sep 17 00:00:00 2001 From: deedy5 <65482418+deedy5@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:53:01 +0300 Subject: [PATCH 4/4] README: add `resp.text_markdown`, `resp.text_plain` to `Response object` section --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index adf0b4c..bebce7f 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,10 @@ resp.cookies resp.encoding resp.headers resp.json() -resp.plaintext # html is converted to markdown text resp.status_code resp.text +resp.text_markdown # html is converted to markdown text +resp.text_plain # html is converted to plain text resp.url ```