Skip to content

Add docstrings for HTML utilities#22

Merged
leynos merged 2 commits intomainfrom
codex/add-docstrings-to-src/html.rs
Jun 14, 2025
Merged

Add docstrings for HTML utilities#22
leynos merged 2 commits intomainfrom
codex/add-docstrings-to-src/html.rs

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Jun 14, 2025

Summary

  • document HTML table conversion helpers

Testing

  • cargo fmt --all
  • cargo clippy -- -D warnings
  • cargo test

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

Summary by Sourcery

Documentation:

  • Add Rustdoc comments to HTML utility functions for text extraction and table-to-Markdown conversion.

Summary by CodeRabbit

  • New Features
    • Added support for automatically converting HTML tables embedded in Markdown into Markdown table format, ensuring proper formatting and consistent column widths.
    • Conversion intelligently skips tables inside fenced code blocks, preserving original content in those sections.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Jun 14, 2025

Reviewer's Guide

This PR enhances the src/html.rs module by adding documentation comments to each HTML utility, clarifying their purpose and usage without altering existing logic.

Class Diagram: Functions Updated with Documentation in src/html.rs

classDiagram
class html_rs_Functions {
    <<Module: src/html.rs>>
    -node_text(handle: Handle) String
    -collect_text(handle: Handle, out: String, last_space: bool) void
    -collect_tables(handle: Handle, tables: Vec~Handle~) void
    -collect_rows(handle: Handle, rows: Vec~Handle~) void
    -table_node_to_markdown(table: Handle) Vec~String~
    -table_lines_to_markdown(lines: StringSlice) Vec~String~
    -push_html_line(line: String, buf: Vec~String~, out: Vec~String~, depth: i32) void
    ~html_table_to_markdown(lines: StringSlice) Vec~String~
    +convert_html_tables(lines: StringSlice) Vec~String~
}
Loading

File-Level Changes

Change Details Files
Added docstrings to HTML utility functions
  • Documented node_text functionality
  • Documented collect_text behavior
  • Documented collect_tables traversal
  • Documented collect_rows traversal
  • Documented table_node_to_markdown conversion
  • Documented table_lines_to_markdown parsing
  • Documented push_html_line buffering logic
  • Documented html_table_to_markdown integration
  • Documented convert_html_tables processing
src/html.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 Jun 14, 2025

Walkthrough

A new module has been introduced to convert HTML tables embedded within Markdown into Markdown table syntax. This module parses HTML table fragments, extracts text content, manages nested tables, and outputs Markdown tables with consistent column widths. The public API processes Markdown lines, converting HTML tables while preserving fenced code blocks.

Changes

File(s) Change Summary
src/html.rs Added functions to parse HTML tables, extract and normalise text, convert tables to Markdown with header detection, handle nesting, and provide a public API to convert embedded HTML tables in Markdown lines.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant HTMLModule
    participant DOMParser
    participant TableConverter
    participant ReflowTable

    Caller->>HTMLModule: convert_html_tables(lines)
    HTMLModule->>HTMLModule: Detect HTML tables (outside code blocks)
    loop For each HTML table found
        HTMLModule->>DOMParser: Parse HTML table fragment
        DOMParser-->>HTMLModule: DOM tree
        HTMLModule->>TableConverter: table_node_to_markdown(DOM)
        TableConverter-->>HTMLModule: Markdown lines
        HTMLModule->>ReflowTable: Format Markdown table
        ReflowTable-->>HTMLModule: Reflowed Markdown table
        HTMLModule->>Caller: Insert converted table into output
    end
    HTMLModule-->>Caller: Final Markdown lines with tables converted
Loading

Possibly related PRs

  • leynos/mdtablefix#13: Implements the same core feature of parsing HTML <table> elements and converting them into Markdown tables.
  • leynos/mdtablefix#8: Modifies the reflow_table function, which the new HTML-to-Markdown conversion relies on for formatting.
  • leynos/mdtablefix#7: Updates reflow_table to pad columns, directly affecting the output of the new conversion feature.

Poem

In Markdown fields where tables grow,
HTML once made them slow.
Now with clever parsing might,
Tables turn to Markdown right.
Rows and columns, neat and keen,
Rabbits hop where code is clean!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62df65d and b47e2cc.

📒 Files selected for processing (1)
  • src/html.rs (9 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/html.rs
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 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

@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: 0

🧹 Nitpick comments (3)
src/html.rs (3)

30-32: Minor nit: tighten wording

“…tracking whether the previous character was whitespace” can be shortened to “…tracking whether the previous output was whitespace”, which matches the last_space flag semantics a bit better.


94-95: Minor clarification could help

Consider mentioning that the returned lines are already re-flowed to uniform column width, as that happens at the end of the function.

-/// Converts a `<table>` DOM node into Markdown table lines.
+/// Converts a `<table>` DOM node into Markdown table lines and calls
+/// `reflow_table` so the columns are uniformly padded.

129-130: Edge-case behaviour not documented

The function returns the original input untouched when no <table> tags are found. Making this explicit prevents surprises.

-/// Parses HTML table markup and returns the equivalent Markdown lines.
+/// Parses HTML table markup and returns the equivalent Markdown lines.
+///
+/// If no `<table>` elements are present, the input is returned unchanged.
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 191c72f and 62df65d.

📒 Files selected for processing (1)
  • src/html.rs (9 hunks)
🔇 Additional comments (6)
src/html.rs (6)

1-7: Top-level module doc looks good

The overview is concise, clearly scoped, and uses en-GB spelling consistently.
No further action required.


21-23: Accurate one-liner – LGTM

The summary precisely matches the implementation.


70-71: Good docstring

Clear and unambiguous.


82-83: Header is fine

No issues.


158-160: Docs are spot-on

Nicely captures the side-effects and state management.


209-213: Public API docs read well

The fence-handling caveat is a valuable note.

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!


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.

@leynos leynos merged commit b266ced into main Jun 14, 2025
1 check passed
@leynos leynos deleted the codex/add-docstrings-to-src/html.rs branch June 14, 2025 11:53
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