|
| 1 | +# HTML Stripper for Markdown Documentation |
| 2 | + |
| 3 | +This script strips HTML tags from markdown files and converts docstrings to clean markdown format. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Removes all HTML tags while preserving content |
| 8 | +- Converts docstring blocks to clean markdown with level 4 headers (`####`) |
| 9 | +- Extracts and formats: |
| 10 | + - Class/function names as headers (removes `class` and `def` prefixes) |
| 11 | + - Anchors in double square brackets format: `[[anchor]]` |
| 12 | + - Source links |
| 13 | + - Parameter descriptions (removes bullets and bold, uses `:` separator, adds blank lines between params) |
| 14 | + - Return types and descriptions |
| 15 | +- Preserves markdown code blocks and structure |
| 16 | +- Can process single files or entire directories |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +### Single File |
| 21 | + |
| 22 | +```bash |
| 23 | +python3 src/scripts/strip_html_from_md.py input.md -o output.md |
| 24 | +``` |
| 25 | + |
| 26 | +Or overwrite the input file: |
| 27 | + |
| 28 | +```bash |
| 29 | +python3 src/scripts/strip_html_from_md.py input.md |
| 30 | +``` |
| 31 | + |
| 32 | +### Directory Processing |
| 33 | + |
| 34 | +Process all markdown files in a directory: |
| 35 | + |
| 36 | +```bash |
| 37 | +python3 src/scripts/strip_html_from_md.py docs/ -o clean_docs/ |
| 38 | +``` |
| 39 | + |
| 40 | +Process recursively: |
| 41 | + |
| 42 | +```bash |
| 43 | +python3 src/scripts/strip_html_from_md.py docs/ -o clean_docs/ --recursive |
| 44 | +``` |
| 45 | + |
| 46 | +## Examples |
| 47 | + |
| 48 | +### Before (with HTML) |
| 49 | + |
| 50 | +```markdown |
| 51 | +<div class="docstring border-l-2 border-t-2 pl-4 pt-3.5"> |
| 52 | + |
| 53 | +<docstring><name>class transformers.BertConfig</name><anchor>transformers.BertConfig</anchor><source>https://github.com/huggingface/transformers/blob/v4.57.1/src/transformers/models/bert/configuration_bert.py#L29</source><paramsdesc>- **vocab_size** (`int`, *optional*, defaults to 30522) -- |
| 54 | + Vocabulary size of the BERT model.</paramsdesc></docstring> |
| 55 | + |
| 56 | +This is the configuration class to store the configuration of a BertModel. |
| 57 | + |
| 58 | +</div> |
| 59 | +``` |
| 60 | + |
| 61 | +### After (clean markdown) |
| 62 | + |
| 63 | +```markdown |
| 64 | +#### transformers.BertConfig[[transformers.BertConfig]] |
| 65 | + |
| 66 | +[Source](https://github.com/huggingface/transformers/blob/v4.57.1/src/transformers/models/bert/configuration_bert.py#L29) |
| 67 | + |
| 68 | +This is the configuration class to store the configuration of a BertModel. |
| 69 | + |
| 70 | +**Parameters:** |
| 71 | + |
| 72 | +vocab_size (`int`, *optional*, defaults to 30522) : Vocabulary size of the BERT model. |
| 73 | + |
| 74 | +hidden_size (`int`, *optional*, defaults to 768) : Dimensionality of the encoder layers and the pooler layer. |
| 75 | +``` |
| 76 | + |
| 77 | +## Command-line Options |
| 78 | + |
| 79 | +- `input` - Input markdown file or directory (required) |
| 80 | +- `-o, --output` - Output file or directory (optional, defaults to overwriting input) |
| 81 | +- `-r, --recursive` - Process directory recursively (optional) |
| 82 | + |
| 83 | +## What Gets Stripped |
| 84 | + |
| 85 | +The script removes: |
| 86 | +- `<div>` tags and their attributes |
| 87 | +- `<docstring>` and nested tags (`<name>`, `<anchor>`, `<source>`, etc.) |
| 88 | +- Component tags: `<Tip>`, `<ExampleCodeBlock>`, `<hfoptions>`, `<hfoption>`, etc. |
| 89 | +- `<EditOnGithub>` links |
| 90 | +- HTML comments |
| 91 | +- Any other HTML tags |
| 92 | + |
| 93 | +## What Gets Preserved |
| 94 | + |
| 95 | +- Markdown syntax (headers, lists, code blocks, links, etc.) |
| 96 | +- Text content from within HTML tags |
| 97 | +- Code blocks (backtick-fenced) |
| 98 | +- Link URLs and formatting |
| 99 | + |
0 commit comments