Render hyperlinks with hyperref green colour

This commit is contained in:
gloamxun committed 2026-10-19 18:29:24 +08:00
1 parent a8b20563fb
commit 09781d40e9
12 files changed
+158 -11

No files matched your search

+25
View File
@@ -464,6 +464,7 @@ struct Parser {
text_style_stack: Vec<(expanded::TextStyle, bool, bool, bool, bool, bool)>,
style_declarations: Vec<(usize, expanded::TextStyle)>,
group_depth: usize,
link_depth: usize,
section_numbers: [u32; 4],
has_chapters: bool,
equation_number: u32,
@@ -575,6 +576,7 @@ impl Parser {
text_style_stack: Vec::new(),
style_declarations: Vec::new(),
group_depth: 0,
link_depth: 0,
section_numbers: [0; 4],
has_chapters: false,
equation_number: 0,
@@ -885,6 +887,7 @@ impl Parser {
monospace,
sans,
small_caps,
link: self.link_depth > 0,
paragraph_indent: false,
alignment: None,
};
@@ -932,6 +935,7 @@ impl Parser {
sans: false,
small_caps: false,
link: false,
y_offset: None,
@@ -1148,6 +1152,12 @@ impl Parser {
}
expanded::FrontendEventKind::LiteralAmpersand
| expanded::FrontendEventKind::MathCell => self.append_literal_ampersand(),
expanded::FrontendEventKind::LinkStart => {
self.link_depth = self.link_depth.saturating_add(1);
}
expanded::FrontendEventKind::LinkEnd => {
self.link_depth = self.link_depth.saturating_sub(1);
}
expanded::FrontendEventKind::LiteralCharacter(character) => {
self.append_text(&character.to_string())
}
@@ -1410,6 +1420,7 @@ impl Parser {
sans: false,
small_caps: false,
link: false,
y_offset: None,
@@ -1503,6 +1514,7 @@ impl Parser {
let monospace = self.monospace;
let sans = self.sans;
let small_caps = self.small_caps;
let link = self.link_depth > 0;
if self.table.is_some() {
let mut pieces = text.split('&').peekable();
while let Some(piece) = pieces.next() {
@@ -1514,6 +1526,7 @@ impl Parser {
monospace,
sans,
small_caps,
link,
);
if pieces.peek().is_some() {
self.finish_table_cell();
@@ -1528,6 +1541,7 @@ impl Parser {
monospace,
sans,
small_caps,
link,
);
}
let alignment = self.paragraph_alignment;
@@ -1576,6 +1590,7 @@ impl Parser {
sans: false,
small_caps: false,
link: false,
y_offset: None,
@@ -1614,6 +1629,7 @@ impl Parser {
sans: false,
small_caps: false,
link: false,
y_offset: None,
@@ -1657,6 +1673,7 @@ impl Parser {
sans: false,
small_caps: false,
link: false,
y_offset: None,
@@ -1710,6 +1727,7 @@ impl Parser {
sans: false,
small_caps: false,
link: false,
y_offset: None,
@@ -1804,6 +1822,7 @@ impl Parser {
let monospace = self.monospace;
let sans = self.sans;
let small_caps = self.small_caps;
let link = self.link_depth > 0;
append_run(
self.target_runs(),
"&".to_string(),
@@ -1812,6 +1831,7 @@ impl Parser {
monospace,
sans,
small_caps,
link,
);
}
@@ -1850,6 +1870,7 @@ impl Parser {
sans: false,
small_caps: false,
link: true,
y_offset: None,
@@ -2368,6 +2389,7 @@ fn indent_run(indent: common::Scaled) -> Run {
monospace: false,
sans: false,
small_caps: false,
link: false,
y_offset: None,
footnote_number: None,
paragraph_indent: true,
@@ -2415,6 +2437,7 @@ fn append_run(
monospace: bool,
sans: bool,
small_caps: bool,
link: bool,
) {
if text.is_empty() {
return;
@@ -2438,6 +2461,7 @@ fn append_run(
&& last.monospace == monospace
&& last.sans == sans
&& last.small_caps == small_caps
&& last.link == link
{
last.text.push_str(&text);
return;
@@ -2456,6 +2480,7 @@ fn append_run(
monospace,
sans,
small_caps,
link,
paragraph_indent: false,
alignment: None,