gemtext: automatically prepend a space when rendering text nodes that look like non-text nodes #8

Closed
opened 2020-09-26 21:12:03 +00:00 by boringcactus · 0 comments
Contributor

if i do

let example = gemtext::Node::Text("#1 fav food: chocolate".to_string());
let mut result = Vec::<u8>::new();
gemtext::render(vec![example], &mut result).unwrap();
let result = String::from_utf8(result).unwrap();
let parsed = gemtext::parse(&result);
let not_what_i_asked_for = gemtext::Node::Heading {
    level: 1,
    body: "1 fav food: chocolate".to_string(),
};
assert_ne!(parsed[0], not_what_i_asked_for);

it fails. which is understandable, but counterintuitive.

in order to ensure nodes that are declared as text get rendered as text, i think it'd make sense to render text nodes that start with special characters by automatically prepending a space when needed. i asked on the irc and everybody said this was the way to do it.

if i do ```rust let example = gemtext::Node::Text("#1 fav food: chocolate".to_string()); let mut result = Vec::<u8>::new(); gemtext::render(vec![example], &mut result).unwrap(); let result = String::from_utf8(result).unwrap(); let parsed = gemtext::parse(&result); let not_what_i_asked_for = gemtext::Node::Heading { level: 1, body: "1 fav food: chocolate".to_string(), }; assert_ne!(parsed[0], not_what_i_asked_for); ``` it fails. which is understandable, but counterintuitive. in order to ensure nodes that are declared as text get rendered as text, i think it'd make sense to render text nodes that start with special characters by automatically prepending a space when needed. i asked on the irc and everybody said this was the way to do it.
cadey closed this issue 2020-09-26 23:09:24 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: cadey/maj#8
No description provided.