fixfilenameissue
BIN
assets/How_to_build_dashboards_in_Grafana/image_06a8395b.png
Normal file
|
After Width: | Height: | Size: 70 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_0730d859.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_1515a4dd.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_19e475a3.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_1d0e8fea.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_1eff81c7.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_1f866a33.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_20efab65.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_215b094c.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_388be087.png
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_3b157c3f.png
Normal file
|
After Width: | Height: | Size: 68 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_4d0fd9e9.png
Normal file
|
After Width: | Height: | Size: 46 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_4e99a4b9.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_4ed35339.png
Normal file
|
After Width: | Height: | Size: 42 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_599b3d60.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_5e724387.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_61fdebf2.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_63584cb6.png
Normal file
|
After Width: | Height: | Size: 243 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_67ceb203.png
Normal file
|
After Width: | Height: | Size: 5 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_69df746f.png
Normal file
|
After Width: | Height: | Size: 73 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_6fc42b49.png
Normal file
|
After Width: | Height: | Size: 57 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_72bb3b93.png
Normal file
|
After Width: | Height: | Size: 106 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_75c9ff24.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_7cfddcc0.png
Normal file
|
After Width: | Height: | Size: 4.2 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_7f68830e.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_7fa839fa.png
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_811d738b.png
Normal file
|
After Width: | Height: | Size: 105 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_8265f6f6.png
Normal file
|
After Width: | Height: | Size: 8.6 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_8728c323.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_9044743e.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_9789f438.png
Normal file
|
After Width: | Height: | Size: 30 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_992a81eb.png
Normal file
|
After Width: | Height: | Size: 4 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_a2cd3ad7.png
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_a35c985b.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_a4ec2340.png
Normal file
|
After Width: | Height: | Size: 50 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_a67af661.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_a6eb424e.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_a72a3119.png
Normal file
|
After Width: | Height: | Size: 27 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_b93b4896.png
Normal file
|
After Width: | Height: | Size: 177 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_bcb7990f.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_bddc6188.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_c67569b9.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_cb0adbe0.png
Normal file
|
After Width: | Height: | Size: 9.8 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_cf3e4717.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_cf65ef3a.png
Normal file
|
After Width: | Height: | Size: 2 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_d445d171.png
Normal file
|
After Width: | Height: | Size: 63 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_d5862bd6.png
Normal file
|
After Width: | Height: | Size: 58 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_edd31b93.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_ef721677.png
Normal file
|
After Width: | Height: | Size: 9.7 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_efe096c3.png
Normal file
|
After Width: | Height: | Size: 37 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_f27cf4b4.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_f3d0eaf9.png
Normal file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_f762deef.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_f89db983.png
Normal file
|
After Width: | Height: | Size: 34 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_f948c603.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_faf7a855.png
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
assets/How_to_build_dashboards_in_Grafana/image_fd0acdd3.png
Normal file
|
After Width: | Height: | Size: 18 KiB |
|
|
@ -1,6 +1,9 @@
|
|||
import sys
|
||||
import os
|
||||
import re
|
||||
import unicodedata
|
||||
from typing import BinaryIO, Any
|
||||
from io import BytesIO
|
||||
|
||||
from ._html_converter import HtmlConverter
|
||||
from ..converter_utils.docx.pre_process import pre_process_docx
|
||||
|
|
@ -51,6 +54,35 @@ class DocxConverter(HtmlConverter):
|
|||
return True
|
||||
|
||||
return False
|
||||
|
||||
def _sanitize_filename(self, filename: str) -> str:
|
||||
"""
|
||||
Sanitize a filename by removing or replacing problematic characters.
|
||||
|
||||
Args:
|
||||
filename: The original filename
|
||||
|
||||
Returns:
|
||||
A sanitized filename safe for filesystem use
|
||||
"""
|
||||
# Step 1: Normalize unicode characters
|
||||
filename = unicodedata.normalize('NFKD', filename)
|
||||
|
||||
# Step 2: Remove invalid characters and replace spaces with underscores
|
||||
# Keep alphanumeric characters, underscores, hyphens, and periods
|
||||
sanitized = re.sub(r'[^\w\-\.]', '_', filename)
|
||||
|
||||
# Step 3: Collapse multiple underscores
|
||||
sanitized = re.sub(r'_+', '_', sanitized)
|
||||
|
||||
# Step 4: Remove leading/trailing underscores
|
||||
sanitized = sanitized.strip('_')
|
||||
|
||||
# Step 5: Ensure we have a valid filename (default if empty)
|
||||
if not sanitized:
|
||||
sanitized = "unnamed"
|
||||
|
||||
return sanitized
|
||||
|
||||
def _get_document_name(self, stream_info: StreamInfo) -> str:
|
||||
"""
|
||||
|
|
@ -61,24 +93,21 @@ class DocxConverter(HtmlConverter):
|
|||
basename = os.path.basename(stream_info.filename)
|
||||
name, _ = os.path.splitext(basename)
|
||||
if name:
|
||||
print(f"[DEBUG] Extracted document name from filename: {name}")
|
||||
return name
|
||||
return self._sanitize_filename(name)
|
||||
|
||||
# If local_path exists, try to extract from local path
|
||||
if stream_info.local_path:
|
||||
basename = os.path.basename(stream_info.local_path)
|
||||
name, _ = os.path.splitext(basename)
|
||||
if name:
|
||||
print(f"[DEBUG] Extracted document name from local_path: {name}")
|
||||
return name
|
||||
return self._sanitize_filename(name)
|
||||
|
||||
# If URL exists, try to extract from URL
|
||||
if stream_info.url:
|
||||
basename = os.path.basename(stream_info.url)
|
||||
name, _ = os.path.splitext(basename)
|
||||
if name:
|
||||
print(f"[DEBUG] Extracted document name from URL: {name}")
|
||||
return name
|
||||
return self._sanitize_filename(name)
|
||||
|
||||
# Default name
|
||||
return "docx_document"
|
||||
|
|
@ -88,10 +117,7 @@ class DocxConverter(HtmlConverter):
|
|||
file_stream: BinaryIO,
|
||||
stream_info: StreamInfo,
|
||||
**kwargs: Any, # Options to pass to the converter
|
||||
) -> DocumentConverterResult:
|
||||
print(f"[DEBUG] DocxConverter.convert called with kwargs: {kwargs}")
|
||||
print(f"[DEBUG] StreamInfo: filename={stream_info.filename}, local_path={stream_info.local_path}, url={stream_info.url}")
|
||||
|
||||
) -> DocumentConverterResult:
|
||||
# Check dependencies
|
||||
if _dependency_exc_info is not None:
|
||||
raise MissingDependencyException(
|
||||
|
|
@ -110,7 +136,6 @@ class DocxConverter(HtmlConverter):
|
|||
if "conversion_name" not in kwargs:
|
||||
conversion_name = self._get_document_name(stream_info)
|
||||
kwargs["conversion_name"] = conversion_name
|
||||
print(f"[DEBUG] Setting conversion_name to: {conversion_name}")
|
||||
|
||||
style_map = kwargs.get("style_map", None)
|
||||
pre_process_stream = pre_process_docx(file_stream)
|
||||
|
|
@ -124,7 +149,6 @@ class DocxConverter(HtmlConverter):
|
|||
extension=".html"
|
||||
)
|
||||
|
||||
print(f"[DEBUG] Calling HTML converter with parameters: conversion_name={kwargs.get('conversion_name')}")
|
||||
# Use io.BytesIO to create binary stream
|
||||
from io import BytesIO
|
||||
return self._html_converter.convert(
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class _CustomMarkdownify(markdownify.MarkdownConverter):
|
|||
# Set default values for image-related options
|
||||
self.image_output_dir = options.get("image_output_dir", "assets")
|
||||
self.conversion_name = options.get("conversion_name")
|
||||
|
||||
|
||||
# Apply basic options
|
||||
options["heading_style"] = options.get("heading_style", markdownify.ATX)
|
||||
options["keep_data_uris"] = options.get("keep_data_uris", False)
|
||||
|
|
@ -155,6 +155,10 @@ class _CustomMarkdownify(markdownify.MarkdownConverter):
|
|||
|
||||
# Update src to relative path
|
||||
src = os.path.join(output_dir, filename).replace("\\", "/")
|
||||
|
||||
# If alt text is empty, use the image filename (without extension) as alt text
|
||||
if not alt:
|
||||
alt = f"image_{hashname}"
|
||||
|
||||
except Exception as e:
|
||||
error_msg = f"Error saving image: {str(e)}"
|
||||
|
|
|
|||