diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-10-06 11:43:26 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-10-06 11:43:26 +0200 |
commit | b75d7976cfe8db43783b930c1f4774f2ad4936f5 (patch) | |
tree | d8c38c5bc6d1427b408d0b6b53aeb33f39e8d704 /src/to_mdast.rs | |
parent | c12c31e1b2d55fa407217c0e14c51c8693f919ae (diff) | |
download | markdown-rs-b75d7976cfe8db43783b930c1f4774f2ad4936f5.tar.gz markdown-rs-b75d7976cfe8db43783b930c1f4774f2ad4936f5.tar.bz2 markdown-rs-b75d7976cfe8db43783b930c1f4774f2ad4936f5.zip |
Add support for HTML 4 character references in JSX attributes
Diffstat (limited to 'src/to_mdast.rs')
-rw-r--r-- | src/to_mdast.rs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/to_mdast.rs b/src/to_mdast.rs index c47eb22..4db76e6 100644 --- a/src/to_mdast.rs +++ b/src/to_mdast.rs @@ -10,7 +10,9 @@ use crate::mdast::{ }; use crate::unist::{Point, Position}; use crate::util::{ - decode_character_reference::{decode_named, decode_numeric}, + character_reference::{ + decode as decode_character_reference, parse as parse_character_reference, + }, infer::{gfm_table_align, list_item_loose, list_loose}, normalize_identifier::normalize_identifier, slice::{Position as SlicePosition, Slice}, @@ -892,14 +894,9 @@ fn on_exit_character_reference_value(context: &mut CompileContext) { context.bytes, &SlicePosition::from_exit_event(context.events, context.index), ); - let value = slice.as_str(); - - let value = match context.character_reference_marker { - b'#' => decode_numeric(value, 10), - b'x' => decode_numeric(value, 16), - b'&' => decode_named(value), - _ => panic!("impossible"), - }; + let value = + decode_character_reference(slice.as_str(), context.character_reference_marker, true) + .expect("expected to parse only valid named references"); if let Node::Text(node) = context.tail_mut() { node.value.push_str(value.as_str()); @@ -1558,8 +1555,9 @@ fn on_exit_mdx_jsx_tag_attribute_value_literal(context: &mut CompileContext) { .attributes .last_mut() { - // To do: character references. - node.value = Some(AttributeValue::Literal(value.to_string())); + node.value = Some(AttributeValue::Literal(parse_character_reference( + &value.to_string(), + ))); } else { unreachable!("expected property") } |