Skip to content

Commit 968bb63

Browse files
whitslackrustyrussell
authored andcommitted
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. [ Added shellcheck suppression for md2man.sh --RR ] Changelog-None
1 parent 5ef0ed3 commit 968bb63

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

contrib/msggen/msggen/schema.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28990,9 +28990,9 @@
2899028990
"description": [
2899128991
"Determines what action is taken:",
2899228992
" - *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':",
28993-
" ```shell.",
28994-
" lightning-cli -k plugin subcommand=start plugin=helloworld.py greeting='A crazy'.",
28995-
" ```.",
28993+
" ```shell",
28994+
" lightning-cli -k plugin subcommand=start plugin=helloworld.py greeting='A crazy'",
28995+
" ```",
2899628996
" - *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`.",
2899728997
" - *subcommand* **startdir** starts all executables it can find in *directory* (excl. subdirectories) as plugins. Checksum and timeout behavior as in **start** applies.",
2899828998
" - *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.",
@@ -33060,7 +33060,10 @@
3306033060
"relative_amount": {
3306133061
"type": "integer",
3306233062
"description": [
33063-
"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 ```."
33063+
"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:",
33064+
"```shell",
33065+
"lightning-cli splice_init -- $CHANNEL_ID -100000",
33066+
"```"
3306433067
]
3306533068
},
3306633069
"initialpsbt": {

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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ TITLELINE="$(head -n1 "$SOURCE")"
2828

2929
# Replace lightning-cli with $ lightning-cli but do not replace it if it is preceded with (
3030
# because it is used in the examples to run it in the shell, eg. $(lightning-cli listpeerchannels)
31+
# shellcheck disable=SC2016 # These are not variables, shellcheck!
3132
SOURCE=$(tail -n +3 "$SOURCE" | sed -E '
3233
:a;N;$!ba;
33-
s#EXAMPLES\n------------#\nEXAMPLES\n------------\n#g;
34-
s#Request:#Request:\n#g;
35-
s#Response:#Response:\n#g;
3634
s#(\(lightning-cli)#\x1#ig;
3735
s#lightning-cli#$ lightning-cli#g;
3836
s#\x1#(lightning-cli#g;
39-
s#\*\*Notification (1|2|3)\*\*:#**Notification \1**:\n#g;
37+
' |
38+
# Lowdown requires a blank line before every preformatted text block
39+
sed '
40+
/^$/{:0;N;/\n$/b0};s/^[[:blank:]]*```/\n\0/;
41+
/\n[[:blank:]]*```/{:1;n;/^[[:blank:]]*```/!b1}
4042
')
4143

4244
# Output to the target file

0 commit comments

Comments
 (0)