Render ORCID author links as green badges

This commit is contained in:
gloamxun committed 2026-10-19 19:01:12 +08:00
1 parent 7c4edbb1f1
commit d9befd4d87
5 files changed
+38 -14

No files matched your search

+2 -1
View File
@@ -74,7 +74,8 @@ const PRELUDE: &str = r#"
\def\nocite#1{}
\def\newblock{ }
\def\caption#1{\texrracaptionstart#1\texrracaptionend}
\def\href#1#2{\texrrahref{#2}}
\def\href#1#2{\texrrahref{#1}{#2}}
\def\texrraorcibadge{iD\ }
\def\hline{\texrratablerule}
\def\toprule{\texrratablerule}
\def\midrule{\texrratablerule}
+18 -6
View File
@@ -1901,15 +1901,27 @@ pub(super) fn build_positioned_pages(
for lines in &blocks {
let mut measured_lines = Vec::with_capacity(lines.len());
for (index, text) in lines.iter().enumerate() {
let mut run = Run::plain(text.clone());
if index == 0 {
run.bold = true;
let mut runs = Vec::new();
let mut rest = text.as_str();
if let Some(after_badge) = text.strip_prefix("iD ") {
let mut badge = Run::plain("iD ".to_string());
badge.bold = true;
badge.link = true;
runs.push(badge);
rest = after_badge;
}
if text.contains('@') && !text.contains(' ') {
run.monospace = true;
if !rest.is_empty() {
let mut run = Run::plain(rest.to_string());
if index == 0 {
run.bold = true;
}
if rest.contains('@') && !rest.contains(' ') {
run.monospace = true;
}
runs.push(run);
}
if let Some(line) = measure_positioned_lines(
&[run],
&runs,
base_font_size,
column_width - 2.0,
metrics,
+9 -3
View File
@@ -3661,13 +3661,19 @@ fn href_primitive(
token: token::Token,
input: &mut vm::ExecutionInput<CompilerState>,
) -> texlang::prelude::Result<()> {
// The prelude macro consumes the URL argument; this primitive only sees the
// visible link text, which is wrapped in a link span for hyperref colour.
let url = read_unexpanded_argument(input, token, "expects a link URL")?;
let content = read_unexpanded_argument(input, token, "expects link text")?;
let inner = strip_braced_tokens(&content).to_vec();
write_event(input, token, FrontendEventKind::LinkStart);
let trace_key = token.trace_key();
let mut expansion = inner;
let mut expansion = Vec::new();
if simple_token_text(&url)
.to_ascii_lowercase()
.contains("orcid.org")
{
expansion.push(control_sequence_token(input, "texrraorcibadge", trace_key));
}
expansion.extend(inner);
expansion.push(control_sequence_token(input, "texrralinkend", trace_key));
input
.as_mut()