Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix markdown image syntax in raster tools #5092

Merged
merged 5 commits into from
Feb 13, 2025

Conversation

petrasovaa
Copy link
Contributor

@petrasovaa petrasovaa commented Feb 12, 2025

Fixing image syntax in raster tools after automatic conversion.

This was processed by an AI generated script with manual review and adjustments. The script is not perfect but could be useful for processing addons. But I don't think it's worth storing more permanently.

import os
import re

def convert_img_tags(md_file):
    """Converts <img> tags to Markdown image syntax, handling both wrapped and standalone cases."""
    with open(md_file, "r", encoding="utf-8") as f:
        content = f.read()

    # Regex to match <img> tags wrapped in Markdown links
    markdown_img_link_pattern = re.compile(
        r'\[<img\s+[^>]*src=["\']([^"\']+)["\'][^>]*alt=["\']([^"\']+)["\'][^>]*>\]\(\1\)',
        re.IGNORECASE
    )
    # Convert wrapped <img> to Markdown: ![alt](src)
    content = markdown_img_link_pattern.sub(r'![\2](\1)', content)

    # Regex to match standalone <img> tags (without link)
    standalone_img_pattern = re.compile(
        r'<img\s+[^>]*src=["\']([^"\']+)["\'][^>]*alt=["\']([^"\']+)["\'][^>]*>',
        re.IGNORECASE
    )
    # Convert standalone <img> to Markdown: ![alt](src)
    content = standalone_img_pattern.sub(r'![\2](\1)', content)

    # Overwrite the file with updated content
    with open(md_file, "w", encoding="utf-8") as f:
        f.write(content)

def process_markdown_files(directory):
    """Recursively searches for .md files and processes them."""
    for root, _, files in os.walk(directory):
        for file in files:
            if file.endswith(".md"):
                md_path = os.path.join(root, file)
                print(f"Processing: {md_path}")
                convert_img_tags(md_path)

# Set the path to the root folder containing Markdown files
root_folder = "path/here"

process_markdown_files(root_folder)
print("Conversion completed!")

@petrasovaa petrasovaa added this to the 8.5.0 milestone Feb 12, 2025
@github-actions github-actions bot added raster Related to raster data processing module docs labels Feb 12, 2025
raster/r.terraflow/r.terraflow.md Outdated Show resolved Hide resolved
@petrasovaa petrasovaa enabled auto-merge (squash) February 13, 2025 15:25
@petrasovaa petrasovaa merged commit ffc0b8c into OSGeo:main Feb 13, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs module raster Related to raster data processing
Projects
Development

Successfully merging this pull request may close these issues.

2 participants