Skip to content

Commit 38c2c67

Browse files
committed
Handle inline math
1 parent 1dce807 commit 38c2c67

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

__test__/index.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ test('extractAnchors: code in headings', (t) => {
175175
t.deepEqual(extractAnchors('# My `heading`'), ['#my-heading'])
176176
})
177177

178+
test('extractAnchors: math in headings', (t) => {
179+
t.deepEqual(extractAnchors('## Gates $\\rightarrow$ quantum gates'), ['#gates-rightarrow-quantum-gates'])
180+
t.deepEqual(
181+
extractAnchors(
182+
'### Template circuits for calculating matrix elements of $\\tilde{S}$ and $\\tilde{H}$ via Hadamard test',
183+
),
184+
['#template-circuits-for-calculating-matrix-elements-of-tildes-and-tildeh-via-hadamard-test'],
185+
)
186+
})
187+
178188
test('extractAnchors: mdx in headings', (t) => {
179189
t.deepEqual(extractAnchors('# My <B>heading</B>`'), ['#my-heading'])
180190
})

src/anchors/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub fn get_text<'a>(node: &'a Node, s: &mut String) {
6363
let maybe_text = match node {
6464
Node::Text(text) => Some(&text.value),
6565
Node::InlineCode(text) => Some(&text.value),
66+
Node::InlineMath(text) => Some(&text.value),
6667
_ => None,
6768
};
6869
if let Some(text) = maybe_text {
@@ -95,6 +96,8 @@ fn heading_to_anchor(heading: String) -> String {
9596
')' => None,
9697
'"' => None,
9798
'\'' => None,
99+
'{' => None,
100+
'}' => None,
98101
x => Some(x),
99102
})
100103
.collect()

0 commit comments

Comments
 (0)