Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nerd font glyphs in languages info #1395

Merged
merged 21 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ CSharp: # required, this will be the name of the enum variant for the language a
- "#803788"
- "#FFFFFF"
chip: "#178600" # required, this is used for the language breakdown bar, its value can be found in linguist (link 2).
icon: "\uE648" # optional, the UTF-16 code point of the nerd font icon if supported (link 3).
icon: "\\uE648" # optional, the UTF-16 code point of the nerd font icon if supported (link 3).
serialization: c# # required only if the Enum name `CSharp` doesn't match the display name `C#`
```

Expand Down
20 changes: 20 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut tera = Tera::default();
tera.register_filter("strip_color_tokens", strip_color_tokens_filter);
tera.register_filter("hex_to_rgb", hex_to_rgb_filter);
tera.register_filter("unicode_escape", unicode_escape_filter);

let lang_data: serde_json::Value = serde_yaml::from_reader(File::open("languages.yaml")?)?;

Expand All @@ -32,6 +33,25 @@ fn main() -> Result<(), Box<dyn Error>> {
Ok(())
}

/// Convert unicode escapes into ECMAScript 6-style
/// https://rust-lang.github.io/rfcs/0446-es6-unicode-escapes.html
fn unicode_escape_filter(
value: &tera::Value,
_args: &HashMap<String, tera::Value>,
) -> tera::Result<tera::Value> {
lazy_static! {
static ref UNICODE_ESCAPE_REGEX: Regex = Regex::new(r"\\u([0-9A-Fa-f]+)").unwrap();
}
let s = match value {
tera::Value::String(s) => s,
_ => return Err(tera::Error::msg("expected string")),
};

return Ok(tera::Value::String(
UNICODE_ESCAPE_REGEX.replace_all(s, "\\u{$1}").to_string(),
));
}

/// Strips out `{n}` from the given string.
fn strip_color_tokens_filter(
value: &tera::Value,
Expand Down
Loading