Skip to content

Commit

Permalink
Add rst-header-replace script.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jun 21, 2023
1 parent 364b0b7 commit 15f635c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v7.22.0
=======

* Added ``rst-header-replace`` script.

v7.21.0
=======

Expand Down
26 changes: 26 additions & 0 deletions jaraco/develop/rst-header-replace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import re
import sys

import autocommand


def replace_len(char):
def replacer(match):
size = len(match.group('heading'))
return char * size

return replacer


@autocommand.autocommand(__name__)
def run(before, after):
assert len(before) == 1
assert len(after) == 1
for line in sys.stdin:
repl = re.sub(
f'^(?P<heading>({re.escape(before)})+)$',
replace_len(after),
line,
flags=re.MULTILINE,
)
sys.stdout.write(repl)

0 comments on commit 15f635c

Please sign in to comment.