mdcleaner


Namemdcleaner JSON
Version 0.1.4.1 PyPI version JSON
download
home_page
SummaryA utility to clean and convert MD files to ASCII.
upload_time2023-08-30 23:05:24
maintainer
docs_urlNone
authorDevon White
requires_python>=3.6
licenseMIT
keywords markdown cleaner ascii
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# MDCleaner

A utility to clean and convert MD files to ASCII.

## Installation

You can install MDCleaner via pip:

```bash
pip install mdcleaner
```

## Usage

After installation, you can use the package in your Python scripts:

```python
from mdcleaner import clean_md

cleaned_content = clean_md("path_to_md_file.md")
print(cleaned_content)
```

## Features

- **Encoding Detection**: The utility can automatically detect the file's encoding to ensure compatibility with various text files.
- **ASCII Conversion**: Converts non-ASCII characters to their closest ASCII representation using the `unidecode` library.
- **Template Replacements**: Provides an easy way to replace placeholders within the MD files with specific content.
- **Graceful Error Handling**: Provides warnings for unmatched templates, ensuring placeholders without corresponding replacements are retained as-is. Additionally, handles improperly formatted templates and gives clear warnings.

### Using templates in your Markdown file

Imagine you have an MD file named `sample.md` with the following content:

```markdown
This is a test: {my_variable}
```

In your script, you can replace the `{my_variable}` placeholder with a specific value:

```python
from mdcleaner import clean_md

replacements = {'my_variable': 'Hello, World!'}
cleaned_content = clean_md("sample.md", contexts=replacements)
print(cleaned_content)  # This will print: "This is a test: Hello, World!"
```

By passing the `contexts` parameter with a dictionary, any placeholders inside `{}` in your MD file will be replaced by the corresponding values.

### Encoding Detection

MDCleaner reads a certain number of bytes from the file to determine its encoding:

- By default, it reads the first 1024 bytes.
- You can specify a different number of bytes using the `encoding_detection_bytes` parameter.
- If you set `encoding_detection_bytes` to 'auto', the entire file will be read to determine its encoding.
- If no encoding is specified, the default option used is `utf-8`.

Example:

```python
clean_md("sample.md", encoding_detection_bytes=500)
```

### Manual Encoding

If you're certain about the encoding of your file, you can specify it directly using the `encoding` parameter, which bypasses the automatic detection process:

```python
clean_md("sample.md", encoding="utf-8")
```

## Contributing

If you find any bugs or want to propose a new feature, please open an issue or submit a pull request.

## License

This project is licensed under the MIT License. See the LICENSE.txt file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "mdcleaner",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "markdown cleaner ASCII",
    "author": "Devon White",
    "author_email": "devon.white@signalwire.com",
    "download_url": "https://files.pythonhosted.org/packages/4c/c3/e5586577abcf154f0f4543ed2969f7c048d93dacfe06d8dbdd00c647d5c9/mdcleaner-0.1.4.1.tar.gz",
    "platform": null,
    "description": "\r\n# MDCleaner\r\n\r\nA utility to clean and convert MD files to ASCII.\r\n\r\n## Installation\r\n\r\nYou can install MDCleaner via pip:\r\n\r\n```bash\r\npip install mdcleaner\r\n```\r\n\r\n## Usage\r\n\r\nAfter installation, you can use the package in your Python scripts:\r\n\r\n```python\r\nfrom mdcleaner import clean_md\r\n\r\ncleaned_content = clean_md(\"path_to_md_file.md\")\r\nprint(cleaned_content)\r\n```\r\n\r\n## Features\r\n\r\n- **Encoding Detection**: The utility can automatically detect the file's encoding to ensure compatibility with various text files.\r\n- **ASCII Conversion**: Converts non-ASCII characters to their closest ASCII representation using the `unidecode` library.\r\n- **Template Replacements**: Provides an easy way to replace placeholders within the MD files with specific content.\r\n- **Graceful Error Handling**: Provides warnings for unmatched templates, ensuring placeholders without corresponding replacements are retained as-is. Additionally, handles improperly formatted templates and gives clear warnings.\r\n\r\n### Using templates in your Markdown file\r\n\r\nImagine you have an MD file named `sample.md` with the following content:\r\n\r\n```markdown\r\nThis is a test: {my_variable}\r\n```\r\n\r\nIn your script, you can replace the `{my_variable}` placeholder with a specific value:\r\n\r\n```python\r\nfrom mdcleaner import clean_md\r\n\r\nreplacements = {'my_variable': 'Hello, World!'}\r\ncleaned_content = clean_md(\"sample.md\", contexts=replacements)\r\nprint(cleaned_content)  # This will print: \"This is a test: Hello, World!\"\r\n```\r\n\r\nBy passing the `contexts` parameter with a dictionary, any placeholders inside `{}` in your MD file will be replaced by the corresponding values.\r\n\r\n### Encoding Detection\r\n\r\nMDCleaner reads a certain number of bytes from the file to determine its encoding:\r\n\r\n- By default, it reads the first 1024 bytes.\r\n- You can specify a different number of bytes using the `encoding_detection_bytes` parameter.\r\n- If you set `encoding_detection_bytes` to 'auto', the entire file will be read to determine its encoding.\r\n- If no encoding is specified, the default option used is `utf-8`.\r\n\r\nExample:\r\n\r\n```python\r\nclean_md(\"sample.md\", encoding_detection_bytes=500)\r\n```\r\n\r\n### Manual Encoding\r\n\r\nIf you're certain about the encoding of your file, you can specify it directly using the `encoding` parameter, which bypasses the automatic detection process:\r\n\r\n```python\r\nclean_md(\"sample.md\", encoding=\"utf-8\")\r\n```\r\n\r\n## Contributing\r\n\r\nIf you find any bugs or want to propose a new feature, please open an issue or submit a pull request.\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the LICENSE.txt file for details.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A utility to clean and convert MD files to ASCII.",
    "version": "0.1.4.1",
    "project_urls": null,
    "split_keywords": [
        "markdown",
        "cleaner",
        "ascii"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "59890e7764a3d7d05ef4679af04a91109302aa341a3241606eeb89ac7fab03a4",
                "md5": "d022be647e1d1d83ff7d6df6017872ea",
                "sha256": "1372a9cc1364802bc5b3f271611fa7c466cb0abcc99544eff7eb1990c61c9f6f"
            },
            "downloads": -1,
            "filename": "mdcleaner-0.1.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d022be647e1d1d83ff7d6df6017872ea",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 4652,
            "upload_time": "2023-08-30T23:05:23",
            "upload_time_iso_8601": "2023-08-30T23:05:23.696964Z",
            "url": "https://files.pythonhosted.org/packages/59/89/0e7764a3d7d05ef4679af04a91109302aa341a3241606eeb89ac7fab03a4/mdcleaner-0.1.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4cc3e5586577abcf154f0f4543ed2969f7c048d93dacfe06d8dbdd00c647d5c9",
                "md5": "91fdf9b67ff724f1b58c0ef8df24b065",
                "sha256": "e40d31c6da28b41d21cb63aad511a8a723a32320b00bda18a65e8986edafb27b"
            },
            "downloads": -1,
            "filename": "mdcleaner-0.1.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "91fdf9b67ff724f1b58c0ef8df24b065",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4481,
            "upload_time": "2023-08-30T23:05:24",
            "upload_time_iso_8601": "2023-08-30T23:05:24.966200Z",
            "url": "https://files.pythonhosted.org/packages/4c/c3/e5586577abcf154f0f4543ed2969f7c048d93dacfe06d8dbdd00c647d5c9/mdcleaner-0.1.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-30 23:05:24",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "mdcleaner"
}
        
Elapsed time: 0.10754s