Skip to content

Commit 56f17ce

Browse files
authored
Expose tag and attribute names with the original case. (#190)
* Expose tag and attribute names with the original case. * Expose tag and attribute names with the original case through the FFI. * Release 1.1.0.
1 parent 8946bfc commit 56f17ce

File tree

10 files changed

+64
-3
lines changed

10 files changed

+64
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.1.0
4+
5+
### Added
6+
7+
- Added ability to get the tag and attribute names with the original casing.
8+
39
## v1.0.1
410

511
### Fixed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lol_html"
3-
version = "1.0.1"
3+
version = "1.1.0"
44
authors = ["Ivan Nikulin <inikulin@cloudflare.com, ifaaan@gmail.com>"]
55
license = "BSD-3-Clause"
66
description = "Streaming HTML rewriter/parser with CSS selector-based API"

c-api/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lolhtml"
3-
version = "1.0.1"
3+
version = "1.1.0"
44
authors = ["Ivan Nikulin <inikulin@cloudflare.com>", "Joshua Nelson <jnelson@cloudflare.com>"]
55
edition = "2021"
66

c-api/include/lol_html.h

+9
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,9 @@ void *lol_html_text_chunk_user_data_get(const lol_html_text_chunk_t *chunk);
483483
// Returns the tag name of the element.
484484
lol_html_str_t lol_html_element_tag_name_get(const lol_html_element_t *element);
485485

486+
// Returns the tag name of the element, preserving its case.
487+
lol_html_str_t lol_html_element_tag_name_get_preserve_case(const lol_html_element_t *element);
488+
486489
// Sets the tag name of the element.
487490
//
488491
// Name should be a valid UTF8-string.
@@ -528,6 +531,9 @@ const lol_html_attribute_t *lol_html_attributes_iterator_next(
528531
// Returns the attribute name.
529532
lol_html_str_t lol_html_attribute_name_get(const lol_html_attribute_t *attribute);
530533

534+
// Returns the attribute name, preserving its case.
535+
lol_html_str_t lol_html_attribute_name_get_preserve_case(const lol_html_attribute_t *attribute);
536+
531537
// Returns the attribute value.
532538
lol_html_str_t lol_html_attribute_value_get(const lol_html_attribute_t *attribute);
533539

@@ -746,6 +752,9 @@ void lol_html_end_tag_remove(lol_html_end_tag_t *end_tag);
746752
// Returns the end tag name.
747753
lol_html_str_t lol_html_end_tag_name_get(const lol_html_end_tag_t *end_tag);
748754

755+
// Returns the end tag name, preserving its case.
756+
lol_html_str_t lol_html_end_tag_name_get_preserve_case(const lol_html_end_tag_t *end_tag);
757+
749758
// Sets the tag name of the end tag.
750759
//
751760
// Name should be a valid UTF8-string.

c-api/src/element.rs

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ pub extern "C" fn lol_html_element_tag_name_get(element: *const Element) -> Str
88
Str::new(element.tag_name())
99
}
1010

11+
#[no_mangle]
12+
pub extern "C" fn lol_html_element_tag_name_get_preserve_case(element: *const Element) -> Str {
13+
let element = to_ref!(element);
14+
15+
Str::new(element.tag_name_preserve_case())
16+
}
17+
1118
#[no_mangle]
1219
pub extern "C" fn lol_html_element_tag_name_set(
1320
element: *mut Element,
@@ -67,6 +74,13 @@ pub extern "C" fn lol_html_attribute_name_get(attribute: *const Attribute) -> St
6774
Str::new(attribute.name())
6875
}
6976

77+
#[no_mangle]
78+
pub extern "C" fn lol_html_attribute_name_get_preserve_case(attribute: *const Attribute) -> Str {
79+
let attribute = to_ref!(attribute);
80+
81+
Str::new(attribute.name_preserve_case())
82+
}
83+
7084
#[no_mangle]
7185
pub extern "C" fn lol_html_attribute_value_get(attribute: *const Attribute) -> Str {
7286
let attribute = to_ref!(attribute);
@@ -281,6 +295,12 @@ pub extern "C" fn lol_html_end_tag_name_get(end_tag: *mut EndTag) -> Str {
281295
Str::new(tag.name())
282296
}
283297

298+
#[no_mangle]
299+
pub extern "C" fn lol_html_end_tag_name_get_preserve_case(end_tag: *mut EndTag) -> Str {
300+
let tag = to_ref_mut!(end_tag);
301+
Str::new(tag.name_preserve_case())
302+
}
303+
284304
#[no_mangle]
285305
pub extern "C" fn lol_html_end_tag_name_set(
286306
end_tag: *mut EndTag,

js-api/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "lol-html-js-api"
3-
version = "1.0.1"
3+
version = "1.1.0"
44
authors = ["Ivan Nikulin <inikulin@cloudflare.com>"]
55
edition = "2021"
66

src/rewritable_units/element.rs

+6
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ impl<'r, 't> Element<'r, 't> {
105105
self.start_tag.name()
106106
}
107107

108+
/// Returns the tag name of the element, preserving its case.
109+
#[inline]
110+
pub fn tag_name_preserve_case(&self) -> String {
111+
self.start_tag.name_preserve_case()
112+
}
113+
108114
/// Sets the tag name of the element.
109115
#[inline]
110116
pub fn set_tag_name(&mut self, name: &str) -> Result<(), TagNameError> {

src/rewritable_units/tokens/attributes.rs

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ impl<'i> Attribute<'i> {
9494
self.name.as_lowercase_string(self.encoding)
9595
}
9696

97+
/// Returns the name of the attribute, preserving its case.
98+
#[inline]
99+
pub fn name_preserve_case(&self) -> String {
100+
self.name.as_string(self.encoding)
101+
}
102+
97103
/// Returns the value of the attribute.
98104
#[inline]
99105
pub fn value(&self) -> String {

src/rewritable_units/tokens/end_tag.rs

+7
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@ impl<'i> EndTag<'i> {
2525
})
2626
}
2727

28+
/// Returns the name of the tag.
2829
#[inline]
2930
pub fn name(&self) -> String {
3031
self.name.as_lowercase_string(self.encoding)
3132
}
3233

34+
/// Returns the name of the tag, preserving its case.
35+
#[inline]
36+
pub fn name_preserve_case(&self) -> String {
37+
self.name.as_string(self.encoding)
38+
}
39+
3340
#[inline]
3441
pub fn set_name(&mut self, name: Bytes<'static>) {
3542
self.name = name;

src/rewritable_units/tokens/start_tag.rs

+7
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ impl<'i> StartTag<'i> {
4141
self.encoding
4242
}
4343

44+
/// Returns the name of the tag.
4445
#[inline]
4546
pub fn name(&self) -> String {
4647
self.name.as_lowercase_string(self.encoding)
4748
}
4849

50+
/// Returns the name of the tag, preserving its case.
51+
#[inline]
52+
pub fn name_preserve_case(&self) -> String {
53+
self.name.as_string(self.encoding)
54+
}
55+
4956
#[inline]
5057
pub fn set_name(&mut self, name: Bytes<'static>) {
5158
self.name = name;

0 commit comments

Comments
 (0)