Skip to content

Add footnote docs and improve conversion helper#112

Merged
leynos merged 3 commits intomainfrom
0wib6f-codex/address-code-review-comments
Jul 20, 2025
Merged

Add footnote docs and improve conversion helper#112
leynos merged 3 commits intomainfrom
0wib6f-codex/address-code-review-comments

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 20, 2025

Summary

  • document footnote conversion with examples
  • add helper for trimmed block ranges
  • ensure inline numbers in code or parentheses are ignored

Testing

  • make fmt
  • make lint
  • make test
  • make markdownlint
  • make nixie

https://chatgpt.com/codex/tasks/task_e_687ceaa54214832288d664165df9eeda

Summary by Sourcery

Add documentation for footnote conversion, introduce a trimmed_range helper for block processing, and improve footnote detection by ignoring inline numbers in code or parentheses.

New Features:

  • Document footnote conversion with usage examples.

Bug Fixes:

  • Ignore numbers inside inline code or parentheses during footnote conversion.

Enhancements:

  • Introduce trimmed_range utility and refactor block conversion to use it.

Documentation:

  • Add footnote conversion documentation with before-and-after examples.

Tests:

  • Add tests to verify numbers in inline code and parentheses are ignored.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 20, 2025

Reviewer's Guide

Refactored block conversion by introducing a generic trimmed_range helper, improved footnote conversion helper with better trimming logic, documented the behavior with examples, and expanded tests to ignore numeric patterns in inline code and parentheses.

Class diagram for footnote conversion helpers

classDiagram
    class FootnoteConverter {
        +convert_inline(text: &str) -> String
        +convert_block(lines: &mut [String])
        +trimmed_range(lines: &[String], pred: F) -> (usize, usize)
    }

    FootnoteConverter : convert_inline
    FootnoteConverter : convert_block
    FootnoteConverter : trimmed_range

    %% Note: trimmed_range is a new generic helper used by convert_block
    convert_block --> trimmed_range : uses
Loading

File-Level Changes

Change Details Files
Refactor block conversion logic with trimmed_range helper
  • Added trimmed_range function to compute start/end indices of non-empty line spans based on a predicate
  • Updated convert_block to call trimmed_range with FOOTNOTE_LINE_RE instead of inline rfind logic
  • Retained guard early return when encountering existing footnote markers
src/footnotes.rs
Add tests to ignore numeric patterns in inline code and parentheses
  • Added test_ignores_numbers_in_inline_code to verify code spans aren’t misconverted
  • Added test_ignores_numbers_in_parentheses to verify parenthetical numbers are skipped
tests/footnotes.rs
Document footnote conversion behavior with examples
  • Created docs/footnote-conversion.md detailing inline and block conversion
  • Included usage examples for convert_footnotes and process_stream_opts
docs/footnote-conversion.md

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 20, 2025

Summary by CodeRabbit

  • Documentation

    • Added a new guide explaining how numeric references can be converted to GitHub-flavoured Markdown footnotes, including examples and usage notes.
  • Tests

    • Introduced tests to ensure numbers within inline code, parentheses, and code blocks are not incorrectly converted to footnotes.
  • Refactor

    • Improved internal logic for detecting and processing trailing blocks of numeric references for footnote conversion.

Walkthrough

Introduce a new documentation file explaining the footnote conversion feature, refactor the block detection logic in the footnote conversion module by adding a reusable helper function, and expand the test suite with cases ensuring numbers in code or parentheses are not incorrectly converted to footnotes.

Changes

File(s) Change Summary
docs/footnote-conversion.md Add documentation detailing the footnote conversion feature, usage, and examples.
src/footnotes.rs Refactor block detection logic with new trimmed_range helper; update convert_block to use it.
tests/footnotes.rs Add five tests verifying numbers in code blocks, inline code, and parentheses are ignored by conversion.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant mdtablefix
    participant convert_footnotes
    participant trimmed_range

    User->>mdtablefix: Run with footnote conversion enabled
    mdtablefix->>convert_footnotes: Process document lines
    convert_footnotes->>trimmed_range: Identify trailing footnote block
    trimmed_range-->>convert_footnotes: Return (start, end) range
    convert_footnotes->>mdtablefix: Convert references & definitions
    mdtablefix-->>User: Output with footnotes transformed
Loading

Possibly related PRs

Poem

In footnotes’ realm, a helper appears,
Trimming the lines, allaying our fears.
Docs now explain how numbers behave,
While tests ensure code blocks are safe.
Markdown transformed, confusion is gone—
Let clarity in documentation dawn!
📝✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cbefa1a and 63135c3.

📒 Files selected for processing (2)
  • docs/footnote-conversion.md (1 hunks)
  • src/footnotes.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
docs/**/*.md

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • AGENTS.md
**/*.md

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • AGENTS.md

⚙️ CodeRabbit Configuration File

**/*.rs

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • AGENTS.md

⚙️ CodeRabbit Configuration File

🪛 LanguageTool
docs/footnote-conversion.md

[typographical] ~37-~37: Consider inserting a comma for improved readability.
Context: ... When the final lines of a document form a numbered list they are replaced with fo...

(INITIAL_ADVP_COMMA)


[uncategorized] ~37-~37: Possible missing comma found.
Context: ...nal lines of a document form a numbered list they are replaced with footnote definit...

(AI_HYDRA_LEO_MISSING_COMMA)

🔇 Additional comments (3)
src/footnotes.rs (2)

49-61: Well-implemented helper function with clear separation of concerns.

The trimmed_range function properly abstracts the block detection logic with a clean interface. The implementation correctly handles edge cases and follows Rust best practices.


63-65: Excellent refactoring using the new helper function.

The convert_block function is now more readable and maintainable by delegating the range detection to trimmed_range. This follows the single responsibility principle and improves code reusability.

docs/footnote-conversion.md (1)

1-60: Excellent documentation with comprehensive examples.

The documentation clearly explains the footnote conversion feature with well-chosen before/after examples. The coverage of edge cases (inline code, parentheses) and the block conversion functionality aligns perfectly with the implementation. The writing follows en-GB conventions and maintains clarity throughout.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 0wib6f-codex/address-code-review-comments

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.

  • Consider adding a Rust doc comment on the new trimmed_range helper to explain its inputs, predicate and the meaning of the returned (start, end) tuple for maintainability.
  • It would be great to update the docs/footnote-conversion.md file with examples showing the new behavior of ignoring numbers inside inline code and parentheses so users can see those edge cases documented.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a Rust doc comment on the new `trimmed_range` helper to explain its inputs, predicate and the meaning of the returned (start, end) tuple for maintainability.
- It would be great to update the `docs/footnote-conversion.md` file with examples showing the new behavior of ignoring numbers inside inline code and parentheses so users can see those edge cases documented.

## Individual Comments

### Comment 1
<location> `tests/footnotes.rs:30` </location>
<code_context>
 }

+#[test]
+fn test_ignores_numbers_in_inline_code() {
+    let input = lines_vec!("Look at `code 1` for details.");
+    assert_eq!(convert_footnotes(&input), input);
+}
+
</code_context>

<issue_to_address>
Consider adding tests for numbers in multi-line code blocks.

Please add tests for numbers inside multi-line code blocks (e.g., triple backticks or indented blocks) to verify consistent handling.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH

#[test]
fn test_ignores_numbers_in_inline_code() {
    let input = lines_vec!("Look at `code 1` for details.");
    assert_eq!(convert_footnotes(&input), input);
}
=======

#[test]
fn test_ignores_numbers_in_inline_code() {
    let input = lines_vec!("Look at `code 1` for details.");
    assert_eq!(convert_footnotes(&input), input);
}

#[test]
fn test_ignores_numbers_in_fenced_code_block() {
    let input = lines_vec!(
        "Here is a code block:",
        "```",
        "let x = 42; // number 1",
        "let y = 2;",
        "```",
        "Outside code block (1)."
    );
    assert_eq!(convert_footnotes(&input), input);
}

#[test]
fn test_ignores_numbers_in_indented_code_block() {
    let input = lines_vec!(
        "    let a = 1;",
        "    let b = 2; // number 2",
        "",
        "Outside indented code block (2)."
    );
    assert_eq!(convert_footnotes(&input), input);
}
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/footnotes.rs
Comment on lines 28 to +33

#[test]
fn test_ignores_numbers_in_inline_code() {
let input = lines_vec!("Look at `code 1` for details.");
assert_eq!(convert_footnotes(&input), input);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Consider adding tests for numbers in multi-line code blocks.

Please add tests for numbers inside multi-line code blocks (e.g., triple backticks or indented blocks) to verify consistent handling.

Suggested change
#[test]
fn test_ignores_numbers_in_inline_code() {
let input = lines_vec!("Look at `code 1` for details.");
assert_eq!(convert_footnotes(&input), input);
}
#[test]
fn test_ignores_numbers_in_inline_code() {
let input = lines_vec!("Look at `code 1` for details.");
assert_eq!(convert_footnotes(&input), input);
}
#[test]
fn test_ignores_numbers_in_fenced_code_block() {
let input = lines_vec!(
"Here is a code block:",
"```",
"let x = 42; // number 1",
"let y = 2;",
"```",
"Outside code block (1)."
);
assert_eq!(convert_footnotes(&input), input);
}
#[test]
fn test_ignores_numbers_in_indented_code_block() {
let input = lines_vec!(
" let a = 1;",
" let b = 2; // number 2",
"",
"Outside indented code block (2)."
);
assert_eq!(convert_footnotes(&input), input);
}

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

♻️ Duplicate comments (2)
tests/footnotes.rs (2)

41-51: Approve the fenced code block test but note partial coverage.

The test correctly verifies that numbers within fenced code blocks are ignored. This addresses part of the past review comment requesting tests for multi-line code blocks.


53-62: Approve the indented code block test.

The test appropriately validates that numbers in indented code blocks are not converted. This completes the coverage for different code block types alongside the fenced code block test.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b41d7f and cbefa1a.

📒 Files selected for processing (3)
  • docs/footnote-conversion.md (1 hunks)
  • src/footnotes.rs (1 hunks)
  • tests/footnotes.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
docs/**/*.md

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • AGENTS.md
**/*.md

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • AGENTS.md

⚙️ CodeRabbit Configuration File

**/*.rs

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • AGENTS.md

⚙️ CodeRabbit Configuration File

🧬 Code Graph Analysis (1)
tests/footnotes.rs (1)
src/footnotes.rs (1)
  • convert_footnotes (80-101)
🪛 LanguageTool
docs/footnote-conversion.md

[typographical] ~37-~37: Consider inserting a comma for improved readability.
Context: ... When the final lines of a document form a numbered list, they are replaced with f...

(INITIAL_ADVP_COMMA)

🔇 Additional comments (7)
src/footnotes.rs (1)

64-66: Approve the refactoring to use the helper function.

The refactoring improves code organisation by extracting the trailing block detection logic into a reusable helper function. The implementation correctly delegates to trimmed_range with the footnote line regex predicate.

tests/footnotes.rs (2)

29-33: Approve the inline code test.

The test correctly verifies that numbers inside inline code spans are not converted to footnotes. This aligns with the documented behaviour and addresses the conversion logic's need to preserve code content.


35-39: Approve the parentheses test.

The test properly validates that numbers enclosed in parentheses remain unchanged during footnote conversion. This prevents false positives for mathematical expressions and citations.

docs/footnote-conversion.md (4)

1-6: Approve the introduction and overview.

The documentation clearly introduces the footnote conversion feature and explains how to access it via the public API. The description accurately reflects the functionality provided by convert_footnotes.


7-20: Approve the inline conversion example.

The before/after example accurately demonstrates how bare numeric references following punctuation are converted to footnote links. The example aligns with the actual behaviour of the convert_inline function.


21-36: Approve the exclusion examples.

The documentation correctly explains that numbers in inline code and parentheses are ignored, with appropriate examples that match the test cases added to verify this behaviour.


58-59: Approve the final clarification.

The explanation that only the final contiguous list is processed accurately describes the behaviour implemented by the trimmed_range helper function in the refactored code.

Comment thread docs/footnote-conversion.md Outdated
Comment thread src/footnotes.rs
Comment thread src/footnotes.rs Outdated
@leynos leynos merged commit 735f011 into main Jul 20, 2025
2 checks passed
@leynos leynos deleted the 0wib6f-codex/address-code-review-comments branch July 20, 2025 21:34
@coderabbitai coderabbitai Bot mentioned this pull request Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant