Skip to content

Commit

Permalink
add linkifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jul 9, 2024
1 parent 1abf0d9 commit 8b2c635
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
5 changes: 5 additions & 0 deletions book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ command = "cargo run -p mdbook-goals --"
"Team" = "https://img.shields.io/badge/Team%20ask-red"
"Not funded" = "https://img.shields.io/badge/Not%20yet%20funded-red"

[preprocessor.goals.linkifiers]
"RFC #([0-9]+)" = "https://github.com/rust-lang/rfcs/pull/$1"
"([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)#([0-9]+)" = "https://github.com/$1/$2/issue/$3"
"#([0-9]+)" = "https://github.com/rust-lang/rust/issue/$1"

[output.html]
git-repository-url = "https://github.com/rust-lang/rust-project-goals"
edit-url-template = "https://github.com/rust-lang/rust-project-goals/edit/main/{path}"
Expand Down
51 changes: 48 additions & 3 deletions mdbook-goals/src/mdbook_preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ use anyhow::Context;
use mdbook::book::{Book, Chapter};
use mdbook::preprocess::{Preprocessor, PreprocessorContext};
use mdbook::BookItem;
use regex::Regex;
use regex::{Captures, Regex};
use walkdir::WalkDir;

use crate::goal::{self, format_team_asks, Status};
use crate::util::GithubUserInfo;

const LINKS: &str = "links";
const LINKIFIERS: &str = "linkifiers";

pub struct GoalPreprocessor;

Expand All @@ -35,15 +36,17 @@ pub struct GoalPreprocessorWithContext<'c> {
goal_list: Regex,
username: Regex,
ctx: &'c PreprocessorContext,
links: BTreeMap<String, String>,
links: Vec<(String, String)>,
linkifiers: Vec<(Regex, String)>,
display_names: BTreeMap<String, Rc<String>>,
}

impl<'c> GoalPreprocessorWithContext<'c> {
pub fn new(ctx: &'c PreprocessorContext) -> anyhow::Result<Self> {
// In testing we want to tell the preprocessor to blow up by setting a
// particular config value
let mut links = Default::default();
let mut links: Vec<(String, String)> = Default::default();
let mut linkifiers = Default::default();
if let Some(config) = ctx.config.get_preprocessor(GoalPreprocessor.name()) {
if let Some(value) = config.get(LINKS) {
links = value
Expand All @@ -59,6 +62,24 @@ impl<'c> GoalPreprocessorWithContext<'c> {
})
.collect::<Result<_, _>>()?;
}

if let Some(value) = config.get(LINKIFIERS) {
linkifiers = value
.as_table()
.with_context(|| format!("`{}` must be a table", LINKIFIERS))?
.iter()
.map(|(k, v)| {
if let Some(v) = v.as_str() {
Ok((Regex::new(&format!(r"\[{}\]", k))?, v.to_string()))
} else {
Err(anyhow::anyhow!(
"linkifier value for `{}` must be a string",
k
))
}
})
.collect::<Result<_, _>>()?;
}
}

Ok(GoalPreprocessorWithContext {
Expand All @@ -67,6 +88,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
goal_list: Regex::new(r"<!-- GOALS `(.*)` -->")?,
username: Regex::new(r"@([-a-zA-Z0-9])+")?,
links,
linkifiers,
display_names: Default::default(),
})
}
Expand All @@ -77,6 +99,7 @@ impl<'c> GoalPreprocessorWithContext<'c> {
self.replace_team_asks(chapter)?;
self.replace_goal_lists(chapter)?;
self.link_users(chapter)?;
self.linkify(chapter)?;
self.insert_links(chapter)?;

for sub_item in &mut chapter.sub_items {
Expand Down Expand Up @@ -241,4 +264,26 @@ impl<'c> GoalPreprocessorWithContext<'c> {
}
}
}

fn linkify(&self, chapter: &mut Chapter) -> anyhow::Result<()> {
for (regex, string) in &self.linkifiers {
chapter.content = regex
.replace_all(&chapter.content, |c: &Captures<'_>| -> String {
// we add `[]` around it
assert!(c[0].starts_with("[") && c[0].ends_with("]"));

eprintln!("c[0] = {}", &c[0]);

let mut href = String::new();
href.push_str(&c[0]);
href.push('(');
c.expand(string, &mut href);
href.push(')');
dbg!(href)
})
.to_string();
}

Ok(())
}
}
4 changes: 1 addition & 3 deletions src/2024h2/async.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ We have also identified two "stretch goals" that we believe could be completed:

#### Resolve the ["send bound"][sb] problem

Although async functions in traits were stabilized, there is currently no way to write a generic function that requires impls where the returned futures are `Send`. This blocks the use of async function in traits in some core ecosystem crates, such as [tower](https://crates.io/crates/tower), which want to work across all kinds of async executors. This problem is called the ["send bound"][sb] problem and there has been extensive discussion of the various ways to solve it. [RFC #3654][] has been opened proposing one solution and describing why that path is preferred. Our goal for the year is to adopt *some* solution on stable.

[RFC #3654]: https://github.com/rust-lang/rfcs/pull/3654
Although async functions in traits were stabilized, there is currently no way to write a generic function that requires impls where the returned futures are `Send`. This blocks the use of async function in traits in some core ecosystem crates, such as [tower](https://crates.io/crates/tower), which want to work across all kinds of async executors. This problem is called the ["send bound"][sb] problem and there has been extensive discussion of the various ways to solve it. [RFC #3654] has been opened proposing one solution and describing why that path is preferred. Our goal for the year is to adopt *some* solution on stable.

#### Reorganize the Async WG

Expand Down
1 change: 0 additions & 1 deletion src/2024h2/parallel-front-end.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ The parallel front end should be:
## Frequently asked questions


[Parallel Rustc WG]: https://www.rust-lang.org/governance/teams/compiler#team-wg-parallel-rustc
[ICE]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+label%3AWG-compiler-parallel+ice
[deadlock]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+label%3AWG-compiler-parallel+deadlock
[test]: https://github.com/rust-lang/rust/issues/118698
Expand Down

0 comments on commit 8b2c635

Please sign in to comment.