-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathsync_counter_example_readme.py
More file actions
40 lines (30 loc) · 1.25 KB
/
sync_counter_example_readme.py
File metadata and controls
40 lines (30 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import re
# Read the content of counter.rs
with open('examples/counter.rs', 'r') as file:
lines = file.readlines()
# Remove the first 5 lines
lines = lines[5:]
# Join the lines into a single string
content = ''.join(lines)
# Replace `example_plugin` with `((DefaultPlugins, HaalkaPlugin::new()))`
content = re.sub(r'examples_plugin', '(DefaultPlugins, HaalkaPlugin::new())', content)
# Remove `#[rustfmt::skip]` lines
content = re.sub(r'#\[rustfmt::skip\]\n', '', content)
# Read the content of README.md
with open('README.md', 'r') as file:
readme_content = file.read()
# Insert the content after the marker
# Define the start and end markers for the Rust code block
start_marker = '```rust no_run'
end_marker = '```'
# Find the start and end positions of the Rust code block
start_pos = readme_content.find(start_marker)
end_pos = readme_content.find(end_marker, start_pos + len(start_marker))
# Replace the content between the markers
if start_pos != -1 and end_pos != -1:
new_readme_content = (readme_content[:start_pos + len(start_marker)] + '\n' + content + readme_content[end_pos:])
else:
new_readme_content = readme_content
# Write the updated content back to README.md
with open('README.md', 'w') as file:
file.write(new_readme_content)