### Install strip-tags Dependencies Source: https://github.com/simonw/strip-tags/blob/main/README.md This command installs the project's dependencies, including testing dependencies, in editable mode. The `-e` flag allows the project to be installed directly from the source directory, which is useful during development. The `.[test]` syntax specifies that both the main package and its test extras should be installed. ```bash pip install -e '.[test]' ``` -------------------------------- ### Install strip-tags using pip Source: https://github.com/simonw/strip-tags/blob/main/README.md This command installs the strip-tags package using pip, making it available for use in your Python environment. Ensure you have pip installed and configured. ```bash pip install strip-tags ``` -------------------------------- ### Strip all tags from HTML via stdin Source: https://github.com/simonw/strip-tags/blob/main/README.md This example demonstrates piping HTML content from a file (`input.html`) into the `strip-tags` command-line tool, which then outputs the content with all HTML tags removed to `output.txt`. This is a common use case for cleaning HTML. ```bash cat input.html | strip-tags > output.txt ``` -------------------------------- ### Keep tag bundles Source: https://github.com/simonw/strip-tags/blob/main/README.md This example shows how to use predefined bundles of tags with the `-t` option in `strip-tags`. For instance, `-t hs` keeps all heading tags (`

` through `

`). ```bash strip-tags -t hs ``` -------------------------------- ### Remove blank lines with strip-tags Source: https://github.com/simonw/strip-tags/blob/main/README.md This Python example shows how to use the `remove_blank_lines=True` argument with the `strip_tags` function to eliminate any remaining empty lines in the processed HTML output. ```python from strip_tags import strip_tags html = """

This has tags

And whitespace too

Ignore this bit. """ stripped = strip_tags(html, remove_blank_lines=True) print(stripped) ``` -------------------------------- ### Get only the first matching element's content Source: https://github.com/simonw/strip-tags/blob/main/README.md This command uses the `--first` flag with `strip-tags` to extract and return the content of only the first HTML element that matches the provided CSS selector (`.content`). The output is redirected to `output.txt`. ```bash cat input.html | strip-tags .content --first > output.txt ``` -------------------------------- ### Strip tags from specific CSS selectors Source: https://github.com/simonw/strip-tags/blob/main/README.md This usage example demonstrates stripping HTML tags only from elements that match the specified CSS selector (e.g., `.content`). It reads from `input.html` and writes the result to `output.txt`. ```bash strip-tags '.content' -i input.html > output.txt ``` -------------------------------- ### Remove content within specified tags Source: https://github.com/simonw/strip-tags/blob/main/README.md This example uses the `-r` or `--remove` flag with `strip-tags` to remove entire sections of HTML identified by a tag name (e.g., `nav`). The content is piped in and the result is saved to `output.txt`. ```bash cat input.html | strip-tags -r nav > output.txt ``` -------------------------------- ### Set Up Python Virtual Environment for strip-tags Source: https://github.com/simonw/strip-tags/blob/main/README.md This code demonstrates the steps to set up a Python virtual environment for the strip-tags project. It includes navigating to the project directory, creating a virtual environment, and activating it. This is a standard practice for managing project dependencies. ```bash cd strip-tags python -m venv venv source venv/bin/activate ``` -------------------------------- ### Run strip-tags module using python -m Source: https://github.com/simonw/strip-tags/blob/main/README.md This shows an alternative way to execute the `strip-tags` functionality by calling it as a Python module using `python -m strip_tags`. The `--help` flag is used to display available options. ```bash python -m strip_tags --help ``` -------------------------------- ### Run Tests for strip-tags Source: https://github.com/simonw/strip-tags/blob/main/README.md This command executes the test suite for the strip-tags project using the pytest framework. Running tests is crucial for verifying the correctness of the code and ensuring that new changes do not introduce regressions. Pytest is a popular choice for Python testing due to its simplicity and powerful features. ```bash pytest ``` -------------------------------- ### Display strip-tags CLI Help Information Source: https://github.com/simonw/strip-tags/blob/main/README.md This snippet shows the help message for the strip-tags command-line tool. It demonstrates the available options for stripping HTML tags and filtering content using CSS selectors. It's useful for understanding the tool's capabilities and usage patterns. ```text Usage: strip-tags [OPTIONS] [SELECTORS]... Strip tags from HTML, optionally from areas identified by CSS selectors Example usage: cat input.html | strip-tags > output.txt To run against just specific areas identified by CSS selectors: cat input.html | strip-tags .entry .footer > output.txt Options: --version Show the version and exit. -r, --remove TEXT Remove content in these selectors -i, --input FILENAME Input file -m, --minify Minify whitespace -t, --keep-tag TEXT Keep these --all-attrs Include all attributes on kept tags --first First element matching the selectors --help Show this message and exit. ``` -------------------------------- ### Strip tags from HTML using a filename input Source: https://github.com/simonw/strip-tags/blob/main/README.md This shows how to use the `strip-tags` command-line tool by providing the input HTML file directly using the `-i` flag. The output, with tags stripped, is redirected to `output.txt`. ```bash strip-tags -i input.html > output.txt ``` -------------------------------- ### Use strip-tags as a Python library Source: https://github.com/simonw/strip-tags/blob/main/README.md This Python code snippet demonstrates how to import and use the `strip_tags` function from the `strip_tags` library. It shows stripping tags from an HTML string, applying CSS selectors, minifying whitespace, and keeping specific tags. ```python from strip_tags import strip_tags html = """

This has tags

And whitespace too

Ignore this bit. """ stripped = strip_tags(html, ["div"], minify=True, keep_tags=["h1"]) print(stripped) ``` -------------------------------- ### Minify whitespace in HTML content Source: https://github.com/simonw/strip-tags/blob/main/README.md This demonstrates the `--minify` or `-m` flag for `strip-tags`, which reduces multiple spaces and tabs to single spaces and removes blank lines, cleaning up whitespace. Input is piped and output is saved to `output.txt`. ```bash cat input.html | strip-tags -m > output.txt ``` -------------------------------- ### Strip tags from multiple CSS selectors Source: https://github.com/simonw/strip-tags/blob/main/README.md This shows how to provide multiple CSS selectors to `strip-tags` to strip tags from different sections of an HTML document, read from `input.html` and output to `output.txt`. ```bash cat input.html | strip-tags '.content' '.sidebar' > output.txt ``` -------------------------------- ### strip-tags Python function signature Source: https://github.com/simonw/strip-tags/blob/main/README.md This displays the function signature for `strip_tags` when used as a Python library. It outlines the available parameters for input, selectors, removal, minification, and tag keeping. ```python def strip_tags( input: str, selectors: Optional[Iterable[str]]=None, *, removes: Optional[Iterable[str]]=None, minify: bool=False, remove_blank_lines: bool=False, first: bool=False, keep_tags: Optional[Iterable[str]]=None, all_attrs: bool=False ) -> str: ``` -------------------------------- ### Keep specific tags using -t flag Source: https://github.com/simonw/strip-tags/blob/main/README.md This command demonstrates how to use the `-t` or `--keep-tag` option with `strip-tags` to preserve specific HTML tags (e.g., `

`, `
  • `) while stripping others. It fetches content from a URL and processes it. ```bash curl -s https://datasette.io/ | strip-tags header -t h1 -t li ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.