Skip to content

Commit 3e419f0

Browse files
committed
doc: properly handle preformatted blocks
Lowdown requires a blank line before all preformatted blocks, or it doesn't recognize them. `tools/md2man.sh` contained some ad-hoc efforts at fixing up some locations where these required blank lines are absent from the output of `tools/fromschema.py`, but it missed some. Instead of playing Whack-a-Mole, use a blanket sed expression to ensure that a blank line precedes _every_ opening ```. `esc_underscores(…)` in `tools/fromschema.py` did not work correctly on strings containing an odd number of backticks, notably the ``` delimiters surrounding preformatted text blocks. Specifically, it was dropping the last backtick since none of the alternatives in the regex matched it. Add a new alternative that matches a whole preformatted block as a single unit. `output_member(…)` in `tools/fromschema.py` was passing each line of a member's description through `esc_underscores(…)` individually, but that breaks preformatted text blocks that are naturally multi-line and leads to mistakenly escaping underscores inside such blocks. Rewrite the code to make use of the `outputs(…)` utility function that joins all the provided lines together before passing the whole text through `esc_underscores(…)`. Drive-by fix a couple of flubbed preformatted blocks in schemas. Changelog-None
1 parent 2d703fc commit 3e419f0

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

doc/schemas/plugin.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
"description": [
3232
"Determines what action is taken:",
3333
" - *subcommand* **start** takes a *path* to an executable as argument and starts it as plugin. *path* may be an absolute path or a path relative to the plugins directory (default *~/.lightning/plugins*). If the plugin is already running and the executable (checksum) has changed, the plugin is killed and restarted except if its an important (or builtin) plugin. If the plugin doesn't complete the 'getmanifest' and 'init' handshakes within 60 seconds, the command will timeout and kill the plugin. Additional *options* may be passed to the plugin, but requires all parameters to be passed as keyword=value pairs using the `-k|--keyword` option which is recommended. For example the following command starts the plugin helloworld.py (present in the plugin directory) with the option greeting set to 'A crazy':",
34-
" ```shell.",
35-
" lightning-cli -k plugin subcommand=start plugin=helloworld.py greeting='A crazy'.",
36-
" ```.",
34+
" ```shell",
35+
" lightning-cli -k plugin subcommand=start plugin=helloworld.py greeting='A crazy'",
36+
" ```",
3737
" - *subcommand* **stop** takes a plugin executable *path* or *name* as argument and stops the plugin. If the plugin subscribed to 'shutdown', it may take up to 30 seconds before this command returns. If the plugin is important and dynamic, this will shutdown `lightningd`.",
3838
" - *subcommand* **startdir** starts all executables it can find in *directory* (excl. subdirectories) as plugins. Checksum and timeout behavior as in **start** applies.",
3939
" - *subcommand* **rescan** starts all plugins in the default plugins directory (default *~/.lightning/plugins*) that are not already running. Checksum and timeout behavior as in **start** applies.",

doc/schemas/splice_init.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"relative_amount": {
2525
"type": "integer",
2626
"description": [
27-
"A positive or negative amount of satoshis to add or subtract from the channel. Note you may need to add a double dash (--) after splice_init if using a negative *relative_amount* so it is not interpretted as a command modifier. For example: ```shell lightning-cli splice_init -- $CHANNEL_ID -100000 ```."
27+
"A positive or negative amount of satoshis to add or subtract from the channel. Note you may need to add a double dash (--) after splice_init if using a negative *relative_amount* so it is not interpretted as a command modifier. For example:",
28+
"```shell",
29+
"lightning-cli splice_init -- $CHANNEL_ID -100000",
30+
"```"
2831
]
2932
},
3033
"initialpsbt": {

tools/fromschema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def output_title(title, underline='-', num_leading_newlines=1, num_trailing_newl
2121

2222
def esc_underscores(s):
2323
"""Backslash-escape underscores outside of backtick-enclosed spans"""
24-
return ''.join(['\\_' if x == '_' else x for x in re.findall(r'[^`_\\]+|`(?:[^`\\]|\\.)*`|\\.|_', s)])
24+
return ''.join(['\\_' if x == '_' else x for x in re.findall(r'(?ms:^[ \t]*```.*?^[ \t]*```)|[^`_\\\n]++|`(?:[^`\\]|\\.)*`|\\.|[_\n]', s)])
2525

2626

2727
def json_value(obj):
@@ -165,8 +165,8 @@ def output_member(propname, properties, is_optional, indent, print_type=True, pr
165165
output_range(properties)
166166

167167
if 'description' in properties:
168-
for i in range(0, len(properties['description'])):
169-
output('{} {}{}'.format(':' if i == 0 else '', esc_underscores(properties['description'][i]), '' if i + 1 == len(properties['description']) else '\n'))
168+
output(': ')
169+
outputs(properties['description'], '\n ')
170170

171171
if 'default' in properties:
172172
output(' The default is {}.'.format(esc_underscores(properties['default']) if isinstance(properties['default'], str) else properties['default']))

tools/md2man.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ TITLELINE="$(head -n1 "$SOURCE")"
3030
# because it is used in the examples to run it in the shell, eg. $(lightning-cli listpeerchannels)
3131
SOURCE=$(tail -n +3 "$SOURCE" | sed -E '
3232
:a;N;$!ba;
33-
s#EXAMPLES\n------------#\nEXAMPLES\n------------\n#g;
34-
s#Request:#Request:\n#g;
35-
s#Response:#Response:\n#g;
3633
s#(\(lightning-cli)#\x1#ig;
3734
s#lightning-cli#$ lightning-cli#g;
3835
s#\x1#(lightning-cli#g;
39-
s#\*\*Notification (1|2|3)\*\*:#**Notification \1**:\n#g;
36+
' |
37+
# Lowdown requires a blank line before every preformatted text block
38+
sed '
39+
/^$/{:0;N;/\n$/b0};s/^[[:blank:]]*```/\n\0/;
40+
/\n[[:blank:]]*```/{:1;n;/^[[:blank:]]*```/!b1}
4041
')
4142

4243
# Output to the target file

0 commit comments

Comments
 (0)