# Code Comment Extractor

Paste source code and list or remove comments across JavaScript, Python, Rust, SQL, HTML, CSS, shell, YAML and more. Filters, JSON, markdown and stats included.

## Run it

- **CLI:** `gizza tool code-comment-extractor "function total(items) {
  // Add every price.
  return items.reduce((sum, item) => sum + item.price, 0); /* cents */
}"`
- **Web:** https://gizza.ai/tools/code-comment-extractor/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/code-comment-extractor/tool.json

## Inputs

- `code` — Source code _(field)_
- `language` — Language _(field)_
- `output` — Output _(field)_
- `kind` — Comment kind _(field)_
- `strip_markers` — Remove comment markers _(field)_
- `line_numbers` — Show line numbers in list output _(field)_
- `min_length` — Minimum comment length _(field)_
- `docstrings` — Treat Python docstrings as comments _(field)_

## Output

- Comments / stripped code (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `code` — Source code
- `language` — Language
- `output` — Output
- `kind` — Comment kind
- `strip_markers` — Remove comment markers
- `line_numbers` — Show line numbers in list output
- `min_length` — Minimum comment length
- `docstrings` — Treat Python docstrings as comments

Example: `https://gizza.ai/tools/code-comment-extractor/?code=function%20total%28items%29%20%7B%0A%20%20%2F%2F%20Add%20every%20price.%0A%20%20return%20items.reduce%28%28sum%2C%20item%29%20%3D%3E%20sum%20%2B%20item.price%2C%200%29%3B%20%2F%2A%20cents%20%2A%2F%0A%7D&language=auto&output=comments&kind=all&strip_markers=true&line_numbers=true&min_length=0&docstrings=true`

---

## About this tool

Paste a source snippet and extract the comments as a plain list, JSON records, a Markdown table, or a statistics summary. You can also choose **Source with comments removed** to strip the matched comments while preserving newlines so code line numbers stay recognizable.

The scanner covers common comment syntaxes used by JavaScript, TypeScript, Python, Java, C#, C, C++, Go, Rust, PHP, Ruby, shell, SQL, HTML/XML, CSS, Lua and YAML-style files. It is string-aware, so `//`, `/* */` and `#` inside ordinary strings, Go backtick strings, Rust raw strings and Python triple-quoted strings are not treated as comments.

### Worked example

Input:

```js
// File header
const url = "https://example.com//path"; // Real trailing comment
/* Multi-line
   block note */
console.log(url);
```

With `language = javascript`, `output = comments`, `strip_markers = true`, and `line_numbers = true`, the result is:

```text
[L1] File header
[L2] Real trailing comment
[L3] Multi-line
block note
```

Use `kind = doc` to keep only documentation comments such as `/** ... */`, `///`, `//!`, `##` and Python docstrings. Use `min_length` to drop short noise comments before listing or stripping.

## Limits and edge cases

This is a deterministic tokenizer, not a full language parser. Unterminated block comments run to the end of the input, shell here-doc bodies are not parsed as a separate grammar, and custom comment syntaxes are not configurable. Output is capped at 50,000 comments to keep browser and CLI runs bounded.

## FAQ

<details>
<summary>Can it remove comments as well as list them?</summary>

Yes. Set `output` to `stripped` to return the original source with the selected comment kind removed. Newlines inside removed comments are kept so remaining code stays close to its original line numbers.

</details>

<details>
<summary>Will URLs or comment markers inside strings be extracted by mistake?</summary>

No for the supported string forms. The tokenizer skips quoted strings, character literals, JavaScript template strings, Go backtick strings and Rust raw strings before looking for comment openers, so `"https://example.com//path"` is left alone.

</details>

<details>
<summary>How does Python docstring handling work?</summary>

When `docstrings` is enabled, a triple-quoted Python string that starts its own line is classified as a documentation comment. Turn `docstrings` off if you only want real `#` comments from Python code.

</details>

<details>
<summary>Why not scan a whole repository?</summary>

This block runs in the browser and CLI on one pasted input at a time. Repository traversal, git revisions and per-file rollups belong in a filesystem-aware tool; this one focuses on a portable single-snippet workflow.

</details>

## Related tools

- [Code metrics analyzer](https://gizza.ai/tools/code-metrics-analyzer/): Paste source code and get line counts, function counts, approximate cyclomatic complexity, maintainability, and risk bands. Runs locally in your browser.
- [Extract Action Items from Meeting Notes](https://gizza.ai/tools/action-item-extractor/): Extract action items, owners, and decisions from meeting notes or daily notes with deterministic rules. Markdown checklist or JSON, private in-browser.
- [Add Line Numbers](https://gizza.ai/tools/add-line-numbers/): Add line numbers to every line of text online, like nl or cat -n — custom start, step, separator, and alignment. Free and private, runs in your browser.
- [ANSI Log Renderer](https://gizza.ai/tools/ansi-log-renderer/): Paste ANSI-colored terminal output or CI logs and render them as HTML, or strip escape codes to plain text. Handles 16-color, 256-color, and truecolor SGR codes.
- [API response diff](https://gizza.ai/tools/api-response-diff/): Compare two JSON API responses and see only the meaningful changes: ignore request ids, timestamps and UUIDs, match arrays by key or as sets, export a JSON Patch.
