-
-
Notifications
You must be signed in to change notification settings - Fork 83
Description
I am using fluent for internationalizing a web app. I will allow translators to put Markdown into the translations, because that gives greater flexibility in layout and allows inline emphasis and stuff like that.
This mostly works, but there's one catch: fluent inserts special isolating unicode markers (U+2068 and U+2069) around all substituted text (to fix substituted left-to-right content in right-to-left translations and vice versa). That however breaks when passing URLs into fluent and then pass the resulting text through markdown, because the isolating markers render the links invalid. For example:
use markdown::{to_html, to_mdast, ParseOptions};
fn main() {
println!("path w/ marks: {}", to_html("[Testlink](\u{2068}/privacy\u{2069})"));
println!(" url w/ marks: {}", to_html("[Testlink](\u{2068}http://localhost:3000/privacy\u{2069})"));
println!(" url no marks: {}", to_html("[Testlink](http://localhost:3000/privacy)"));
println!("{:#?}", to_mdast("[Testlink](%E2%81%A8http://localhost:3000/privacy%E2%81%A9)", &ParseOptions::default()).unwrap());
}path w/ marks: <p><a href="%E2%81%A8/privacy%E2%81%A9">Testlink</a></p>
url w/ marks: <p><a href="">Testlink</a></p>
url no marks: <p><a href="http://localhost:3000/privacy">Testlink</a></p>
Root {
<.. elided for brevity ..>
url: "%E2%81%A8http://localhost:3000/privacy%E2%81%A9",
<.. elided for brevity ..>
}
Two problematic behaviors occur here:
- The isolation markers render the relative link invalid, as the browser will take the percent-encoded markers at face value.
- The absolute link gets completely erased by
markdown.
I can see that adding support for this in markdown may not be correct, in which case I would like to have a way to convert an mdast to HTML. The AST does contain the original URL, so I could walk the AST to strip the markers from the URL and then hand it to an imaginary mdast_to_html function.