@@ -23,14 +23,16 @@ def get_language(file_path):
2323
2424def process_file (filepath ):
2525 with open (filepath , 'r' ) as f :
26- content = f .read ()
26+ original_content = f .read ()
27+
28+ content = original_content
2729
2830 # Regex to find the gitbook embed tag
2931 # Pattern handles the example: {% @github-files/github-code-block url="..." ... %}
3032 # Using non-greedy match for the content inside the tag
31- pattern = r'\{%\s*@github-files/github-code-block\s+url="(https://github\.com/[^"]+)"[^%]*%\}'
33+ pattern_embed = r'\{%\s*@github-files/github-code-block\s+url="(https://github\.com/[^"]+)"[^%]*%\}'
3234
33- def replace_match (match ):
35+ def replace_embed (match ):
3436 url = match .group (1 )
3537 # Extract file path from URL. Assumes standard GitHub blob URL structure:
3638 # https://github.com/user/repo/blob/branch/path/to/file
@@ -60,12 +62,42 @@ def replace_match(match):
6062
6163 return f"```{ language } \n { file_content } \n ```"
6264
63- new_content = re .sub (pattern , replace_match , content )
65+ content = re .sub (pattern_embed , replace_embed , content )
66+
67+ # Regex to find GitBook hints
68+ # Pattern: {% hint style="style" %} ... {% endhint %}
69+ # Uses dotall matching to capture multiline content
70+ pattern_hint = r'\{%\s*hint\s+style="([^"]+)"\s*%\}(.*?)\{%\s*endhint\s*%\}'
71+
72+ hint_map = {
73+ 'info' : 'NOTE' ,
74+ 'success' : 'TIP' ,
75+ 'warning' : 'WARNING' ,
76+ 'danger' : 'CAUTION'
77+ }
78+
79+ def replace_hint (match ):
80+ style = match .group (1 )
81+ hint_content = match .group (2 ).strip ()
82+
83+ github_type = hint_map .get (style , 'NOTE' ) # Default to NOTE if style is unknown
84+
85+ # Format the content: add "> " to each line
86+ formatted_lines = []
87+ for line in hint_content .splitlines ():
88+ formatted_lines .append (f"> { line } " )
89+
90+ formatted_content = "\n " .join (formatted_lines )
91+
92+ return f"> [!{ github_type } ]\n { formatted_content } "
93+
94+ # Use re.DOTALL to allow dot to match newlines in hint content
95+ content = re .sub (pattern_hint , replace_hint , content , flags = re .DOTALL )
6496
65- if new_content != content :
97+ if content != original_content :
6698 print (f"Updated { filepath } " )
6799 with open (filepath , 'w' ) as f :
68- f .write (new_content )
100+ f .write (content )
69101
70102def main ():
71103 docs_dir = 'docs'
0 commit comments