Przeglądaj źródła

changelogs: avoid line breaks in the github release output

Pietro Albini 4 lat temu
rodzic
commit
92d931fba2
2 zmienionych plików z 25 dodań i 4 usunięć
  1. 21 1
      src/changelogs/mod.rs
  2. 4 3
      src/changelogs/rustc.rs

+ 21 - 1
src/changelogs/mod.rs

@@ -1,6 +1,6 @@
 mod rustc;
 
-use comrak::Arena;
+use comrak::{nodes::AstNode, Arena, ComrakOptions, ComrakRenderOptions};
 use std::collections::HashMap;
 
 #[derive(Copy, Clone, PartialEq, Eq, Debug, serde::Deserialize)]
@@ -24,3 +24,23 @@ impl Changelog {
         self.versions.get(version).map(|s| s.as_str())
     }
 }
+
+fn render_for_github_releases<'a>(document: &'a AstNode<'a>) -> anyhow::Result<String> {
+    let mut content = Vec::new();
+    comrak::format_commonmark(
+        document,
+        &ComrakOptions {
+            render: ComrakRenderOptions {
+                // Prevent column width line breaks from appearing in the generated release
+                // notes. GitHub Releases insert <br>s for every line break in the markdown,
+                // mangling the output.
+                width: std::usize::MAX,
+
+                ..ComrakRenderOptions::default()
+            },
+            ..ComrakOptions::default()
+        },
+        &mut content,
+    )?;
+    Ok(String::from_utf8(content)?)
+}

+ 4 - 3
src/changelogs/rustc.rs

@@ -57,9 +57,7 @@ impl<'a> RustcFormat<'a> {
             document.append(child);
         }
 
-        let mut content = Vec::new();
-        comrak::format_commonmark(document, &ComrakOptions::default(), &mut content)?;
-        let content = String::from_utf8(content)?;
+        let content = super::render_for_github_releases(document)?;
 
         if let Some(version) = h1.split(' ').nth(1) {
             self.result.versions.insert(version.to_string(), content);
@@ -81,6 +79,8 @@ Version 1.45.2 (2020-08-03)
 
 * [Fix bindings in tuple struct patterns][74954]
 * [Link in another section][69033]
+* Very very very very very very very very very very very long line that has some
+  linebreaks here and there
 
 [74954]: https://github.com/rust-lang/rust/issues/74954
 
@@ -131,6 +131,7 @@ related tools.
     const EXPECTED_1_45_2: &str = "\
 - [Fix bindings in tuple struct patterns](https://github.com/rust-lang/rust/issues/74954)
 - [Link in another section](https://github.com/rust-lang/rust/pull/69033/)
+- Very very very very very very very very very very very long line that has some linebreaks here and there
 ";
 
     #[test]