Choose correct syntax lexer #1013

Closed
opened 2023-08-09 14:13:37 +00:00 by mih · 3 comments
mih commented 2023-08-09 14:13:37 +00:00 (Migrated from github.com)

With #1012 I looked a bit deeper. I think we should apply the following rules for selecting the language label (in code-block statements, but also in runrecord instances).

  • when there is only a script, pick the language (bash, python, ...)
  • when there is a mix of commands and output, pick console

for the latter it is important to keep in mind that this is expecting a live sessions log, meaning a rogue comment char (#) can never appear without a prompt at the start of the line. SO any use of

$ some command
# my comment
$ some more command

needs to become

$ some command
$ # my comment
$ some more command
With #1012 I looked a bit deeper. I think we should apply the following rules for selecting the `language` label (in `code-block` statements, but also in `runrecord` instances). - when there is only a script, pick the language (`bash`, `python`, ...) - when there is a mix of commands and output, pick `console` for the latter it is important to keep in mind that this is expecting a live sessions log, meaning a rogue comment char (`#`) can never appear without a prompt at the start of the line. SO any use of ``` $ some command # my comment $ some more command ``` needs to become ``` $ some command $ # my comment $ some more command ```
adswa commented 2023-10-10 13:06:09 +00:00 (Migrated from github.com)

for the latter it is important to keep in mind that this is expecting a live sessions log, meaning a rogue comment char (#) can never appear without a prompt at the start of the line. SO any use of

$ some command
# my comment
$ some more command

needs to become

$ some command
$ # my comment
$ some more command

This would somewhat "break" the copy-button configuration, because it would prevent people from copying only executable commands. At the moment, all lines with a leading $ are copied on click, which works nicely for copy-pasting.

> > for the latter it is important to keep in mind that this is expecting a live sessions log, meaning a rogue comment char (`#`) can never appear without a prompt at the start of the line. SO any use of > > ``` > $ some command > # my comment > $ some more command > ``` > > needs to become > > ``` > $ some command > $ # my comment > $ some more command > ``` This would somewhat "break" the copy-button configuration, because it would prevent people from copying only executable commands. At the moment, all lines with a leading ``$`` are copied on click, which works nicely for copy-pasting.
mih commented 2023-11-05 16:52:08 +00:00 (Migrated from github.com)

This should not be a problem. The lines would still be "executable". C&P'ed into a terminal they would also be "just comment".

This should not be a problem. The lines would still be "executable". C&P'ed into a terminal they would also be "just comment".
mih commented 2023-11-09 12:25:32 +00:00 (Migrated from github.com)

I looked into this again. I agree that it would be annoying to have the copy button copy comments. However, it seems that a straightforward regex adjustment in the button config can avoid that.

The more I think about prepending any command with $ the more I think it should be done.

Consider this example:

$ complex-command-that-does-echo-#-something-or-not
# something

We, or a reader could not tell whether this is console input (a supplied comment), or console output (a produced text with # prefix).

I looked into this again. I agree that it would be annoying to have the copy button copy comments. However, it seems that a straightforward regex adjustment in the button config can avoid that. The more I think about prepending any command with `$ ` the more I think it should be done. Consider this example: ``` $ complex-command-that-does-echo-#-something-or-not # something ``` We, or a reader could not tell whether this is console input (a supplied comment), or console output (a produced text with `#` prefix).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
handbook/book#1013
No description provided.