Skip to content

Refactor footnotes and document option#105

Closed
leynos wants to merge 2 commits intomainfrom
codex/refactor-convert_inline-and-improve-tests
Closed

Refactor footnotes and document option#105
leynos wants to merge 2 commits intomainfrom
codex/refactor-convert_inline-and-improve-tests

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jul 20, 2025

Summary

  • document footnotes option and add usage example
  • add reference docs for footnote conversion
  • refactor footnote conversion helpers
  • rename variables in convert_block
  • expand unit tests for footnote edge cases
  • improve integration test docs and verify macro exports
  • add API docs for process_stream_opts

Testing

  • make lint
  • make test

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

Summary by Sourcery

Refactor and document the footnote conversion feature by reorganizing conversion helpers, updating variable names, and enhancing documentation and examples, while also expanding test coverage for various edge cases and exported macros.

Enhancements:

  • Refactor footnote conversion helpers and rename variables in convert_block for clarity

Documentation:

  • Add dedicated footnote conversion documentation with usage examples
  • Update README to reference the new footnote conversion guide
  • Document the footnotes parameter in the process_stream_opts API

Tests:

  • Add unit tests for multiple inline references, non-numeric identifiers, empty input, and mixed code content
  • Add integration test to verify macros are correctly exported from the prelude

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jul 20, 2025

Reviewer's Guide

This PR refactors the footnote conversion logic into reusable helpers, exposes and documents the optional footnotes flag in the processing API, and expands tests and reference documentation for footnote conversion.

Class diagram for refactored footnote conversion helpers

classDiagram
    class FootnoteConverter {
        +convert_inline(text: &str) String
        +convert_block(lines: &mut [String])
        +convert_footnotes(lines: &[String]) Vec<String>
    }
    FootnoteConverter : <<helper functions>>
Loading

Class diagram for process_stream_opts API with footnotes flag

classDiagram
    class ProcessStreamOpts {
        +footnotes: bool
        +process_stream_opts(input: Stream, opts: ProcessStreamOpts) Output
    }
    ProcessStreamOpts --> FootnoteConverter : uses if footnotes == true
Loading

File-Level Changes

Change Details Files
Refactored footnote conversion into inline and block helpers with renamed variables
  • Extract inline reference parsing into convert_inline
  • Extract block conversion into convert_block
  • Rename variables for clarity (end → trimmed_end, start → footnote_start)
  • Adjust looping bounds to use the new trimmed range
src/footnotes.rs
Exposed and documented the optional footnotes flag in the processing API
  • Add API doc comment for footnotes parameter in process_stream_opts
  • Update README with --footnotes usage example
  • Add detailed reference doc for footnote conversion
README.md
docs/footnote-conversion.md
src/lib.rs
Expanded unit and integration tests for footnote edge cases
  • Add unit tests for multiple inline refs, non-numeric identifiers, empty input, mixed content with code
  • Add integration test verifying prelude macros export
src/footnotes.rs
tests/footnotes.rs

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

    • Updated the README to include a reference link for detailed footnote conversion instructions.
    • Enhanced documentation comments in integration tests to clarify their purpose and usage.
  • Tests

    • Added new unit tests to improve coverage of footnote conversion scenarios.
    • Introduced an integration test to verify macro exports from the prelude module.
  • Style

    • Renamed local variables for clarity in the footnote conversion logic.

Walkthrough

Update the README to include a reference link for detailed footnote conversion instructions. Refactor variable names in the footnote conversion implementation for clarity and add a trailing comma in a macro call. Expand unit and integration test coverage, including new tests for inline references, identifier handling, and macro export validation. No changes to public interfaces.

Changes

File(s) Summary
README.md Add reference link to docs/footnote-conversion.md in the --footnotes option description.
src/footnotes.rs Rename local variables for clarity; add trailing comma in macro; introduce five new unit tests.
tests/footnotes.rs Add documentation comments; introduce integration test for macro exports; clarify test purpose and scope.

Possibly related PRs

Poem

In the land of docs and code so neat,
Footnotes now march with a README treat.
With variables renamed and tests galore,
Macros exported—what could you ask for more?
Markdown’s footnotes, now robust and bright,
March boldly on into the night!
✨📝


📜 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 2cee277 and a481f2f.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • src/footnotes.rs (3 hunks)
  • tests/footnotes.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.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

🪛 GitHub Actions: CI
src/footnotes.rs

[error] 66-66: Rust compiler error E0425: cannot find value footnote_start in this scope.


[error] 66-66: Rust compiler error E0425: cannot find value trimmed_end in this scope.


[error] 66-66: Rust compiler error E0425: cannot find value footnote_start in this scope.


[error] 70-70: Rust compiler error E0425: cannot find value footnote_start in this scope.


[error] 70-70: Rust compiler error E0425: cannot find value trimmed_end in this scope.

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

23-26: Good addition of trailing comma.

The trailing comma in the format! macro improves consistency and makes future diffs cleaner.


136-160: Excellent test coverage expansion.

The new unit tests provide comprehensive coverage of edge cases:

  • Multiple inline references in a single line
  • Non-numeric identifiers with alphabetic suffixes
  • Empty input handling
  • Mixed content with inline code preservation

The test implementations are clear and follow good testing practices.

tests/footnotes.rs (2)

2-9: Excellent module documentation enhancement.

The comprehensive module comment clearly explains the purpose and scope of these integration tests, differentiates them from unit tests, and documents the helper macros. The documentation follows en-GB conventions and provides valuable context for maintainers.


93-97: Good verification test for macro exports.

The test effectively verifies that the prelude macros are properly exported and produce the expected Vec<String> types. The approach of using type annotations to verify compilation and types is appropriate for testing macro infrastructure.

README.md (1)

55-56: Good documentation reference addition.

Adding the reference link to detailed footnote conversion instructions improves user experience by providing easy access to comprehensive documentation. The link structure follows good documentation practices.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/refactor-convert_inline-and-improve-tests

🪧 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 they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/footnotes.rs:36` </location>
<code_context>
+    format!("{pre}{punc}{style}[^{num}]{boundary}")
+}
+
 fn convert_inline(text: &str) -> String {
     INLINE_FN_RE
         .replace_all(text, |caps: &Captures| {
</code_context>

<issue_to_address>
Consider inlining the footnote parsing and building logic directly into the closure to avoid unnecessary helper functions.

```suggestion
// You can simplify by inlining the parse + build logic back into the closure,
// removing the two trivial helpers `parse_inline_caps` and `build_inline_footnote`.
 fn convert_inline(text: &str) -> String {
     INLINE_FN_RE
         .replace_all(text, |caps: &Captures| {
-            let (pre, punc, style, num, boundary) = parse_inline_caps(caps);
-            build_inline_footnote(pre, punc, style, num, boundary)
+            format!(
+                "{}{}{}[^{}]{}",
+                &caps["pre"],
+                &caps["punc"],
+                &caps["style"],
+                &caps["num"],
+                &caps["boundary"],
+            )
         })
         .into_owned()
 }
```

After applying this, you can delete the now‐unused `parse_inline_caps` and `build_inline_footnote` helpers. This keeps the logic in one place and reduces indirection without losing any functionality.
</issue_to_address>

### Comment 2
<location> `docs/footnote-conversion.md:3` </location>
<code_context>
+# Footnote Conversion
+
+`mdtablefix` can optionally convert bare numeric references into
+GitHub-flavoured Markdown footnotes. The `convert_footnotes` function performs
+this operation and is exposed via the higher level `process_stream_opts` helper.
</code_context>

<issue_to_address>
Some paragraphs exceed the 80 column wrapping limit.

Lines such as 'GitHub-flavoured Markdown footnotes. The `convert_footnotes` function performs this operation and is exposed via the higher level `process_stream_opts` helper.' exceed 80 columns. Please wrap paragraphs to 80 columns as per the instructions.
</issue_to_address>

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 src/footnotes.rs
Comment thread docs/footnote-conversion.md
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e3395a and b5a537a.

📒 Files selected for processing (5)
  • README.md (3 hunks)
  • docs/footnote-conversion.md (1 hunks)
  • src/footnotes.rs (2 hunks)
  • src/process.rs (1 hunks)
  • tests/footnotes.rs (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.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

docs/**/*.md

Instructions used from:

Sources:
📄 CodeRabbit Inference Engine

  • AGENTS.md
🪛 LanguageTool
docs/footnote-conversion.md

[uncategorized] ~9-~9: Use a comma before ‘so’ if it connects two independent clauses (unless they are closely connected and short).
Context: ...put is transformed into a footnote block so the document remains readable on GitHub...

(COMMA_COMPOUND_SENTENCE_2)

🔇 Additional comments (11)
README.md (3)

51-52: Excellent documentation enhancement.

The reference link to the detailed footnote conversion guide improves discoverability and provides users with comprehensive information about the feature.


124-124: Good example update demonstrating the footnotes feature.

Changing the example to enable footnotes shows users how to use this optional feature in practice.


133-135: Clear and informative parameter documentation.

The expanded description properly explains the footnotes parameter's default behaviour and functionality, helping users understand when and how to use it.

src/process.rs (1)

100-105: Excellent API documentation addition.

The documentation comment clearly explains the function's purpose and each parameter, following Rust documentation standards. This improves the public API's usability and aligns with the coding guidelines requiring clear documentation for public APIs.

docs/footnote-conversion.md (1)

1-13: Comprehensive and clear documentation.

The documentation effectively explains the footnote conversion feature, its purpose, and how to enable it. The explanations are concise yet thorough, making it easy for users to understand the functionality.

tests/footnotes.rs (2)

2-9: Excellent module documentation.

The comprehensive documentation clearly explains the purpose of integration tests, distinguishes them from unit tests, and describes the helper macros. This follows the coding guideline requiring module-level comments explaining purpose and utility.


58-62: Good verification of macro exports.

The test ensures that the helper macros are properly exported and accessible, which is important for the public API's reliability.

src/footnotes.rs (4)

20-34: Excellent refactoring for clarity.

Extracting the regex capture parsing and footnote building into separate helper functions improves readability and follows the single responsibility principle. The functions are well-documented and have clear purposes.


39-40: Clean integration of helper functions.

The refactored convert_inline function is now more readable and easier to understand, demonstrating good use of the extracted helper functions.


46-58: Improved variable naming for clarity.

The variable renames (end to trimmed_end, start to footnote_start) make the code more self-documenting and easier to understand without changing the logic.


124-148: Comprehensive test coverage enhancements.

The new unit tests cover important edge cases including multiple inline references, non-numeric identifiers, empty input, and mixed content with code. This improves the robustness of the footnote conversion functionality.

Comment thread docs/footnote-conversion.md Outdated
@leynos leynos force-pushed the codex/refactor-convert_inline-and-improve-tests branch from c25803f to 2cee277 Compare July 20, 2025 12:58
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 20, 2025

@sourcery-ai review

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 - here's some feedback:

  • Consider extracting the trimmed-range logic in convert_block (the rposition/rfind steps for start/end) into a shared helper to reduce duplication and improve readability.
  • The new footnote conversion docs would benefit from a minimal before-and-after example directly in docs/footnote-conversion.md to illustrate both inline rewriting and the final block transformation.
  • The inline regex could still catch numbers inside code spans or parentheses; consider adding tests and/or adjusting the pattern to explicitly skip backticked sections and common delimiters.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the trimmed-range logic in convert_block (the rposition/rfind steps for start/end) into a shared helper to reduce duplication and improve readability.
- The new footnote conversion docs would benefit from a minimal before-and-after example directly in docs/footnote-conversion.md to illustrate both inline rewriting and the final block transformation.
- The inline regex could still catch numbers inside code spans or parentheses; consider adding tests and/or adjusting the pattern to explicitly skip backticked sections and common delimiters.

## Individual Comments

### Comment 1
<location> `docs/footnote-conversion.md:4` </location>
<code_context>
+# Footnote Conversion
+
+`mdtablefix` can optionally convert bare numeric references into
+GitHub-flavoured Markdown footnotes. The `convert_footnotes` function performs
+this operation and is exposed via the higher level `process_stream_opts` helper.
+
</code_context>

<issue_to_address>
Consider hyphenating 'higher level' to 'higher-level' as it is a compound adjective.

In this context, 'higher-level' should be hyphenated as it modifies 'helper.'
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
this operation and is exposed via the higher level `process_stream_opts` helper.
=======
this operation and is exposed via the higher-level `process_stream_opts` helper.
>>>>>>> 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 docs/footnote-conversion.md Outdated

`mdtablefix` can optionally convert bare numeric references into
GitHub-flavoured Markdown footnotes. The `convert_footnotes` function performs
this operation and is exposed via the higher level `process_stream_opts` helper.
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 (typo): Consider hyphenating 'higher level' to 'higher-level' as it is a compound adjective.

In this context, 'higher-level' should be hyphenated as it modifies 'helper.'

Suggested change
this operation and is exposed via the higher level `process_stream_opts` helper.
this operation and is exposed via the higher-level `process_stream_opts` helper.

leynos added 2 commits July 21, 2025 00:37
Address review comment by inlining footnote parsing logic and remove the helpers. Fix grammar in documentation.
@leynos leynos force-pushed the codex/refactor-convert_inline-and-improve-tests branch from 2cee277 to a481f2f Compare July 20, 2025 23:38
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Jul 20, 2025

B0rked

@leynos leynos closed this Jul 20, 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