Page MenuHomePhabricator

help: when replacing placeholders in help files, insert indented text
AbandonedPublic

Authored by valentin.gatienbaron on Oct 23 2018, 3:28 PM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

So one can add text without hardcoding the indentation it will need.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

yuja added a subscriber: yuja.Oct 24 2018, 7:45 AM
  • a/mercurial/help.py

+++ b/mercurial/help.py
@@ -391,6 +391,12 @@

single documentation block and use it to overwrite the marker in doc.
"""
entries = []

+ markerindent = 0
+ markerpos = doc.find(marker)
+ if markerpos >= 0:
+ newlinepos = doc.rfind('\n', 0, markerpos)
+ if newlinepos >= 0:
+ markerindent = markerpos - newlinepos - 1

Perhaps, it's simpler to use re.sub() instead of doc.replace(...), something
like:

markerre = re.compile(br'^(\s*)%s' % re.escape(marker), re.MULTILINE)
markerre.sub(builditemsdoc, doc)