Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

# Tarpaulin (https://github.com/xd009642/tarpaulin) HTML coverage report
tarpaulin-report.html

# This is autogenerated and does not need to be tracked by version control
Cargo.lock
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ If you don't feel comfortable writing user documentation, I will be happy to gui
## Release notes

[Towncrier](https://towncrier.readthedocs.io/en/stable/index.html) is used to generate release notes.
If you add a changelog fragment to the `changelog.d` directory with `just add-changelog` (requires [just](https://github.com/casey/just#installation)) it will automatically be picked up when a new release is made.

If you add a changelog fragment to the `changelog.d` directory with `just add-changelog`, it will automatically be picked up when a new release is made.

This requires
- [just](https://github.com/casey/just#installation)
- [uv](https://github.com/astral-sh/uv)
102 changes: 13 additions & 89 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pulldown-cmark-to-cmark = "21.0.0"
rayon = "1.10.0"
regex = "1.10.5"
serde_yaml = "0.9.34"
slug = "0.1.5"
github-slugger = "0.1.0"
snafu = "0.8.3"
unicode-normalization = "0.1.23"
filetime = "0.2.23"
Expand Down
3 changes: 3 additions & 0 deletions changelog.d/370.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fixed header id links being non-compliant with github and gitlab markdown viewers.

This allows links to heading anchors to follow under github and gitlab.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub use context::Context;
use filetime::set_file_mtime;
use frontmatter::{frontmatter_from_str, frontmatter_to_str};
pub use frontmatter::{Frontmatter, FrontmatterStrategy};
use github_slugger::slug;
use pathdiff::diff_paths;
use percent_encoding::{utf8_percent_encode, AsciiSet, CONTROLS};
use pulldown_cmark::{CodeBlockKind, CowStr, Event, HeadingLevel, Options, Parser, Tag, TagEnd};
use pulldown_cmark_to_cmark::cmark_with_options;
use rayon::prelude::*;
use references::{ObsidianNoteReference, RefParser, RefParserState, RefType};
use slug::slugify;
use snafu::{ResultExt, Snafu};
use unicode_normalization::UnicodeNormalization;
pub use walker::{vault_contents, WalkOptions};
Expand Down Expand Up @@ -780,7 +780,7 @@ impl<'a> Exporter<'a> {

if let Some(section) = reference.section {
link.push('#');
link.push_str(&slugify(section));
link.push_str(&slug(section));
}

let link_tag = Tag::Link {
Expand Down
23 changes: 23 additions & 0 deletions tests/export_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,26 @@ fn test_same_filename_different_directories() {
let actual = read_to_string(tmp_dir.path().join(PathBuf::from("Note.md"))).unwrap();
assert_eq!(expected, actual);
}

#[test]
fn test_github_flavored_markdown_heading_id_compliance() {
let tmp_dir = TempDir::new().expect("failed to make tempdir");

Exporter::new(
PathBuf::from("tests/testdata/input/gfm-heading-ids-compliance"),
tmp_dir.path().to_path_buf(),
)
.run()
.unwrap();

let expected = if cfg!(windows) {
read_to_string("tests/testdata/expected/gfm-heading-ids-compliance/Note.md")
.unwrap()
.replace('/', "\\")
} else {
read_to_string("tests/testdata/expected/gfm-heading-ids-compliance/Note.md").unwrap()
};

let actual = read_to_string(tmp_dir.path().join(PathBuf::from("Note.md"))).unwrap();
assert_eq!(expected, actual);
}
13 changes: 13 additions & 0 deletions tests/testdata/expected/gfm-heading-ids-compliance/Note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[A.B.C.D](Note.md#abcd)
[with a name](Note.md#abcd)
[1.2.3.4](Note.md#1234)
[this-or-that](Note.md#this-or-that)
[this--or-that](Note.md#this--or-that)

# A.B.C.D

# 1.2.3.4

# this-or-that

# this--or-that
10 changes: 10 additions & 0 deletions tests/testdata/input/gfm-heading-ids-compliance/Note.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[[#A.B.C.D]]
[[#A.B.C.D|with a name]]
[[#1.2.3.4]]
[[#this-or-that]]
[[#this--or-that]]

# A.B.C.D
# 1.2.3.4
# this-or-that
# this--or-that