Skip to content

Commit 0b87292

Browse files
authored
gitbook page link cleanup (#1231)
1 parent 090481f commit 0b87292

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pgml-dashboard/src/utils/markdown.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,7 @@ pub fn mkdocs<'a>(root: &'a AstNode<'a>, arena: &'a Arena<AstNode<'a>>) -> anyho
917917

918918
iter_nodes(root, &mut |node| {
919919
match &mut node.data.borrow_mut().value {
920+
// Strip .md extensions that gitbook includes in page link urls
920921
&mut NodeValue::Link(ref mut link) => {
921922
let path = Path::new(link.url.as_str());
922923

@@ -932,6 +933,21 @@ pub fn mkdocs<'a>(root: &'a AstNode<'a>, arena: &'a Arena<AstNode<'a>>) -> anyho
932933
}
933934

934935
&mut NodeValue::Text(ref mut text) => {
936+
937+
// Strip .md extensions that gitbook includes in page link text
938+
if text.ends_with(".md") {
939+
if let Some(parent) = node.parent() {
940+
match parent.data.borrow().value {
941+
NodeValue::Link(ref link) => {
942+
for _ in 0..".md".len() {
943+
text.pop();
944+
}
945+
}
946+
_ => {}
947+
}
948+
}
949+
}
950+
935951
if text.starts_with("=== \"") {
936952
let mut parent = {
937953
match node.parent() {

0 commit comments

Comments
 (0)