Skip to content

Commit

Permalink
Merge branch 'feature/make-span-clearer' into feature/combined-fix-on…
Browse files Browse the repository at this point in the history
…-same-line
  • Loading branch information
ryanpeach committed Dec 17, 2024
2 parents 08e0c39 + 13e0912 commit 081b091
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 36 deletions.
40 changes: 18 additions & 22 deletions src/file/content/wikilink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Alias {
self.0.is_empty()
}
#[must_use]
pub fn len(&self) -> usize {
pub fn char_len(&self) -> usize {
self.0.chars().count()
}
}
Expand Down Expand Up @@ -104,28 +104,24 @@ impl Visitor for WikilinkVisitor {
.expect("Otherwise the regex wouldn't match")
.as_str(),
);
self.wikilinks.push(
Wikilink::builder()
.alias(alias.clone())
.span(repair_span_due_to_frontmatter(
SourceSpan::new(
(SourceOffset::from_location(
remove_frontmatter_from_source(source, node),
sourcepos.start.line,
sourcepos.start.column,
)
.offset()
+ captures
.get(1)
.expect("The regex has 2 capture groups")
.start())
.into(),
alias.len(),
),
node,
))
.build(),
let capture_start_byte = captures
.get(1)
.expect("The regex has 2 capture groups")
.start();
let text_without_frontmatter = remove_frontmatter_from_source(source, node);
let sourcepos_start_offset_bytes = SourceOffset::from_location(
text_without_frontmatter,
sourcepos.start.line,
sourcepos.start.column,
)
.offset();
let span = SourceSpan::new(
(sourcepos_start_offset_bytes + capture_start_byte).into(),
alias.char_len(),
);
let span = repair_span_due_to_frontmatter(span, node);
self.wikilinks
.push(Wikilink::builder().alias(alias.clone()).span(span).build());
}
};
match data {
Expand Down
25 changes: 11 additions & 14 deletions src/rules/unlinked_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,17 @@ impl Visitor for UnlinkedTextVisitor {
continue;
}
let alias = Alias::new(&patterns[found.pattern().as_usize()]);
let span = repair_span_due_to_frontmatter(
SourceSpan::new(
(SourceOffset::from_location(
remove_frontmatter_from_source(source, node),
sourcepos.start.line,
sourcepos.start.column,
)
.offset()
+ found.start())
.into(),
found.end() - found.start(),
),
node,
);
let text_without_frontmatter = remove_frontmatter_from_source(source, node);
let sourcepos_start_offset_bytes = SourceOffset::from_location(
text_without_frontmatter,
sourcepos.start.line,
sourcepos.start.column,
)
.offset();
let byte_length = found.end() - found.start();
let offset_bytes = sourcepos_start_offset_bytes + found.start();
let span = SourceSpan::new(offset_bytes.into(), byte_length);
let span = repair_span_due_to_frontmatter(span, node);

// Dont match inside wikilinks
if let Some(parent) = parent {
Expand Down

0 comments on commit 081b091

Please sign in to comment.