Skip to content

Commit 79901f1

Browse files
committed
fix(ids): more on dl ids
1 parent f2fa543 commit 79901f1

File tree

9 files changed

+65
-6
lines changed

9 files changed

+65
-6
lines changed

Diff for: crates/diff-test/src/main.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,17 @@ fn is_html(s: &str) -> bool {
160160
s.starts_with('<') && s.ends_with('>')
161161
}
162162

163-
const IGNORE: &[&str] = &["doc.flaws", "blogMeta.readTime"];
163+
const IGNORE: &[&str] = &[
164+
"doc.flaws",
165+
"blogMeta.readTime",
166+
"doc.modified",
167+
"doc.popularity",
168+
"doc.source.github_url",
169+
"doc.source.last_commit_url",
170+
"doc.sidebarHTML",
171+
];
172+
173+
static LOWER_CASE: &[&str] = &[];
164174
static WS_DIFF: Lazy<Regex> = Lazy::new(|| Regex::new(r#"(?<x>>)[\n ]+|[\n ]+(?<y></)"#).unwrap());
165175

166176
fn full_diff(lhs: &Value, rhs: &Value, path: &[PathIndex], diff: &mut BTreeMap<String, String>) {
@@ -203,12 +213,23 @@ fn full_diff(lhs: &Value, rhs: &Value, path: &[PathIndex], diff: &mut BTreeMap<S
203213
(Value::String(lhs), Value::String(rhs)) => {
204214
let mut lhs = lhs.to_owned();
205215
let mut rhs = rhs.to_owned();
216+
let key = make_key(path);
217+
match key.as_str() {
218+
"doc.sidebarMacro" => {
219+
lhs = lhs.to_lowercase();
220+
rhs = rhs.to_lowercase();
221+
}
222+
"doc.summary" => {
223+
lhs = lhs.replace("\n ", "\n");
224+
rhs = rhs.replace("\n ", "\n");
225+
}
226+
_ => {}
227+
};
206228
if is_html(&lhs) && is_html(&rhs) {
207229
lhs = html_minifier::minify(WS_DIFF.replace_all(&lhs, "$x$y")).unwrap();
208230
rhs = html_minifier::minify(WS_DIFF.replace_all(&rhs, "$x$y")).unwrap();
209231
}
210232
if lhs != rhs {
211-
let key = make_key(path);
212233
if IGNORE.contains(&key.as_str()) {
213234
return;
214235
}

Diff for: crates/rari-doc/src/html/rewriter.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,13 @@ pub fn post_process_html<T: PageLike>(
117117
el.remove_attribute("data-add-link");
118118
if let Some(id) = el.get_attribute("id") {
119119
el.prepend(&format!("<a href=\"#{id}\">"), ContentType::Html);
120-
el.append("</a>", ContentType::Html);
121120
}
122121
Ok(())
123122
}),
123+
element!("dt[data-add-link] *:first-child", |el| {
124+
el.append("</a>", ContentType::Html);
125+
Ok(())
126+
}),
124127
element!("pre[class*=brush]:not(.hidden)", |el| {
125128
let class = el.get_attribute("class");
126129
let class = class.as_deref().unwrap_or_default();

Diff for: crates/rari-doc/src/templ/api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl RariApi {
7474
}
7575

7676
pub fn interactive_examples_base_url() -> &'static str {
77-
"https://interactive-examples.mdn.mozilla.net/"
77+
&settings().interactive_examples_base_url
7878
}
7979

8080
pub fn link(

Diff for: crates/rari-doc/src/templ/macros/badges.rs

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ pub fn deprecated() -> Result<String, DocError> {
2424
Ok(out)
2525
}
2626

27+
#[rari_f]
28+
pub fn optional() -> Result<String, DocError> {
29+
let str = rari_l10n::l10n("optional", env.locale);
30+
Ok(format!(
31+
r#"<span class="badge inline optional">{str}</span>"#
32+
))
33+
}
34+
2735
pub fn write_experimental(out: &mut impl std::fmt::Write, locale: Locale) -> std::fmt::Result {
2836
let title = rari_l10n::l10n("experimental_badge_title", locale);
2937
let abbreviation = rari_l10n::l10n("experimental_badge_abbreviation", locale);

Diff for: crates/rari-doc/src/templ/macros/embedinteractiveexample.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::templ::api::RariApi;
1414
#[rari_f]
1515
pub fn embed_interactive_example(path: String, height: Option<String>) -> Result<String, DocError> {
1616
let title = l10n("interactive_example_cta", env.locale);
17-
let url = format!("{}{path}", RariApi::interactive_examples_base_url());
17+
let url = format!("{}/{path}", RariApi::interactive_examples_base_url());
1818
let height_class = match height.as_deref() {
1919
h @ Some("shorter" | "taller" | "tabbed-shorter" | "tabbed-standard" | "tabbed-taller") => {
2020
h.unwrap()

Diff for: crates/rari-doc/src/templ/macros/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn invoke(env: &RariEnv, ident: &str, args: Vec<Option<Arg>>) -> Result<Stri
3131
"experimentalbadge" | "experimental_inline" => badges::experimental_any,
3232
"nonstandardbadge" | "non-standard_inline" => badges::non_standard_any,
3333
"deprecated_inline" => badges::deprecated_any,
34+
"optional_inline" => badges::optional_any,
3435

3536
// links
3637
"jsxref" => jsxref::jsxref_any,

Diff for: crates/rari-l10n/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ pub fn l10n(key: &str, locale: Locale) -> &'static str {
7272
Locale::ZhTw => "嘗試一下",
7373
},
7474

75+
"optional" => match locale {
76+
Locale::Fr => "Facultatif",
77+
Locale::Ja => "省略可",
78+
Locale::Ru => "Необязательный",
79+
Locale::ZhCn => "可选",
80+
Locale::ZhTw => "選擇性",
81+
Locale::Es => "Opcional",
82+
Locale::EnUs | _ => "Optional",
83+
},
84+
7585
_ => "l10n missing",
7686
}
7787
}

Diff for: crates/rari-md/src/html.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,21 @@ impl<'o> HtmlFormatter<'o> {
473473
}
474474
}
475475

476+
fn collect_first_child_text<'a>(node: &'a AstNode<'a>, output: &mut Vec<u8>) {
477+
if let Some(child) = node.children().next() {
478+
if matches!(child.data.borrow().value, NodeValue::Paragraph) {
479+
if let Some(child) = child.children().next() {
480+
if !matches!(child.data.borrow().value, NodeValue::HtmlInline(_)) {
481+
return Self::collect_text(child, output);
482+
}
483+
}
484+
}
485+
Self::collect_text(child, output)
486+
} else {
487+
Self::collect_text(node, output)
488+
}
489+
}
490+
476491
fn next_is_link<'a>(node: &'a AstNode<'a>) -> bool {
477492
if let Some(child) = node.children().next() {
478493
if matches!(child.data.borrow().value, NodeValue::Link(_)) {
@@ -587,7 +602,7 @@ impl<'o> HtmlFormatter<'o> {
587602
if entering {
588603
self.cr()?;
589604
let mut text_content = Vec::with_capacity(20);
590-
Self::collect_text(node, &mut text_content);
605+
Self::collect_first_child_text(node, &mut text_content);
591606
let mut id = String::from_utf8(text_content).unwrap();
592607
id = self.anchorizer.anchorize(id);
593608
write!(self.output, "<dt id=\"{}\"", id)?;

Diff for: crates/rari-types/src/settings.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct Settings {
1616
pub base_url: String,
1717
pub live_samples_base_url: String,
1818
pub legacy_live_samples_base_url: String,
19+
pub interactive_examples_base_url: String,
1920
}
2021

2122
impl Settings {

0 commit comments

Comments
 (0)