Skip to content

Commit d2611bb

Browse files
committed
[misc] some grinding on markdown/textinput
1 parent 0864f8b commit d2611bb

11 files changed

+91
-69
lines changed

src/internals/cmd-ref.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@
222222
:comment *text*
223223
^^^^^^^^^^^^^^^
224224

225-
Attach a comment to the focused log line. The comment will be displayed right below the log message it is associated with. The comment can be formatted using markdown and you can add new-lines with '\n'.
225+
Attach a comment to the focused log line. The comment will be displayed right below the log message it is associated with. The comment can contain Markdown directives for styling and linking.
226226

227227
**Parameters**
228228
* **text\*** --- The comment text

src/lnav_commands.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4142,9 +4142,8 @@ readline_context::command_t STD_COMMANDS[] = {
41424142
"comment will be "
41434143
"displayed right below the log message it is "
41444144
"associated with. "
4145-
"The comment can be formatted using markdown and "
4146-
"you can add "
4147-
"new-lines with '\\n'.")
4145+
"The comment can contain Markdown directives for "
4146+
"styling and linking.")
41484147
.with_parameter(
41494148
help_text("text", "The comment text")
41504149
.with_format(help_parameter_format_t::HPF_MULTILINE_TEXT))

src/textfile_highlighters.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,11 +630,33 @@ setup_highlights_int()
630630
.with_nestable(true)
631631
.with_text_format(text_format_t::TF_MARKDOWN)
632632
.with_role(role_t::VCR_LIST_GLYPH);
633-
hm[{highlight_source_t::INTERNAL, "md.blockquote"}]
634-
= highlighter(xpcre_compile(R"(^\s*(>\s+.*))"))
633+
hm[{highlight_source_t::INTERNAL, "md.link"}]
634+
= highlighter(xpcre_compile(R"((\[).+(\]\()[^\)]+(\)))"))
635+
.with_nestable(true)
636+
.with_text_format(text_format_t::TF_MARKDOWN)
637+
.with_role(role_t::VCR_FOOTNOTE_BORDER);
638+
hm[{highlight_source_t::INTERNAL, "md.directive"}]
639+
= highlighter(
640+
xpcre_compile(
641+
R"(^\s*>[ \t](\[!(?:NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]))"))
635642
.with_nestable(true)
636643
.with_text_format(text_format_t::TF_MARKDOWN)
644+
.with_role(role_t::VCR_DOC_DIRECTIVE);
645+
hm[{highlight_source_t::INTERNAL, "md.blockquote"}]
646+
= highlighter(xpcre_compile(R"(^\s*(>[ \t]+.*))"))
647+
.with_nestable(false)
648+
.with_text_format(text_format_t::TF_MARKDOWN)
637649
.with_role(role_t::VCR_QUOTED_TEXT);
650+
hm[{highlight_source_t::INTERNAL, "md.table-hr"}]
651+
= highlighter(xpcre_compile(R"((\|)?(:?-+:?)(\|))"))
652+
.with_nestable(true)
653+
.with_text_format(text_format_t::TF_MARKDOWN)
654+
.with_role(role_t::VCR_DOC_DIRECTIVE);
655+
hm[{highlight_source_t::INTERNAL, "md.table-row"}]
656+
= highlighter(xpcre_compile(R"((\|)?(?:[^\\|]|\\.)+(\|))"))
657+
.with_nestable(true)
658+
.with_text_format(text_format_t::TF_MARKDOWN)
659+
.with_role(role_t::VCR_DOC_DIRECTIVE);
638660
hm[{highlight_source_t::INTERNAL, "md.strikethrough"}]
639661
= highlighter(xpcre_compile(R"((?:^|\s+|\pP)(~[^~]+~)(?:$|\s+|\pP))"))
640662
.with_nestable(true)

src/textinput_curses.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ bool
730730
textinput_curses::handle_key(const ncinput& ch)
731731
{
732732
static const auto PREFIX_RE = lnav::pcre2pp::code::from_const(
733-
R"(^\s*((?:-|\*|1\.)\s+(?:\[( |x|X)\]\s+)?)?)");
733+
R"(^\s*((?:-|\*|1\.|>)\s+(?:\[( |x|X)\]\s+)?)?)");
734734
thread_local auto md = lnav::pcre2pp::match_data::unitialized();
735735

736736
if (this->tc_notice) {
@@ -1229,7 +1229,9 @@ textinput_curses::handle_key(const ncinput& ch)
12291229
.matches()
12301230
.ignore_error();
12311231

1232-
if (match_opt && !match_opt->f_all.empty()) {
1232+
if (match_opt && !match_opt->f_all.empty()
1233+
&& match_opt->f_all.sf_end == this->tc_cursor.x)
1234+
{
12331235
if (md[1]) {
12341236
this->tc_selection = selected_range::from_key(
12351237
this->tc_cursor.copy_with_x(md[1]->sf_begin),

test/expected/test_cmds.sh_b6a3bb78e9d60e5e1f5ce5b18e40d2f1662707ab.out

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,7 @@ For support questions, email:
837837
══════════════════════════════════════════════════════════════════════
838838
Attach a comment to the focused log line. The comment will be
839839
displayed right below the log message it is associated with. The
840-
comment can be formatted using markdown and you can add new-lines
841-
with '\n'.
840+
comment can contain Markdown directives for styling and linking.
842841
Parameter
843842
text The comment text
844843
See Also

test/expected/test_text_file.sh_08d527b6655b80eb3fc9f19d502b08ce28d71c80.out

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<!-- This is a comment for testing purposes -->
22

3-
[![Build](https://github.com/tstack/lnav/workflows/ci-build/badge.svg)](https://github.com/tstack/lnav/actions?query=workflow%3Aci-build)
4-
[![Docs](https://readthedocs.org/projects/lnav/badge/?version=latest&style=plastic)](https://docs.lnav.org)
5-
[![Coverage Status](https://coveralls.io/repos/github/tstack/lnav/badge.svg?branch=master)](https://coveralls.io/github/tstack/lnav?branch=master)
6-
[![lnav](https://snapcraft.io/lnav/badge.svg)](https://snapcraft.io/lnav)
7-
[![Gurubase](https://img.shields.io/badge/Gurubase-Ask%20LNAV%20Guru-006BFF)](https://gurubase.io/g/lnav)
3+
[![Build](https://github.com/tstack/lnav/workflows/ci-build/badge.svg)](https://github.com/tstack/lnav/actions?query=workflow%3Aci-build)
4+
[![Docs](https://readthedocs.org/projects/lnav/badge/?version=latest&style=plastic)](https://docs.lnav.org)
5+
[![Coverage Status](https://coveralls.io/repos/github/tstack/lnav/badge.svg?branch=master)](https://coveralls.io/github/tstack/lnav?branch=master)
6+
[![lnav](https://snapcraft.io/lnav/badge.svg)](https://snapcraft.io/lnav)
7+
[![Gurubase](https://img.shields.io/badge/Gurubase-Ask%20LNAV%20Guru-006BFF)](https://gurubase.io/g/lnav)
88

9-
[<img src="https://assets-global.website-files.com/6257adef93867e50d84d30e2/62594fddd654fc29fcc07359_cb48d2a8d4991281d7a6a95d2f58195e.svg" height="20" alt="Discord Logo"/>](https://discord.gg/erBPnKwz7R)
9+
[<img src="https://assets-global.website-files.com/6257adef93867e50d84d30e2/62594fddd654fc29fcc07359_cb48d2a8d4991281d7a6a95d2f58195e.svg" height="20" alt="Discord Logo"/>](https://discord.gg/erBPnKwz7R)
1010

11-
_This is the source repository for **lnav**, visit [https://lnav.org](https://lnav.org) for a high level overview._
11+
_This is the source repository for **lnav**, visit [https://lnav.org](https://lnav.org) for a high level overview._
1212

1313
# LNAV -- The Logfile Navigator
1414

@@ -20,25 +20,25 @@ set of files/directories, **lnav** will:
2020
- merge the files by time into a single view;
2121
- tail the files, follow renames, find new files in directories;
2222
- build an index of errors and warnings;
23-
- [pretty-print JSON-lines](https://docs.lnav.org/en/latest/formats.html#json-lines).
23+
- [pretty-print JSON-lines](https://docs.lnav.org/en/latest/formats.html#json-lines).
2424

2525
Then, in the **lnav** TUI, you can:
2626

27-
- jump quickly to the previous/next error ([press `e`/`E`](https://docs.lnav.org/en/latest/hotkeys.html#spatial-navigation));
28-
- search using regular expressions ([press `/`](https://docs.lnav.org/en/latest/hotkeys.html#spatial-navigation));
29-
- highlight text with a regular expression ([`:highlight`](https://docs.lnav.org/en/latest/commands.html#highlight-pattern) command);
30-
- filter messages using [regular expressions](https://docs.lnav.org/en/latest/usage.html#regular-expression-match) or [SQLite expressions](https://docs.lnav.org/en/latest/usage.html#sqlite-expression);
31-
- pretty-print structured text ([press `P`](https://docs.lnav.org/en/latest/ui.html#pretty));
32-
- view a histogram of messages over time ([press `i`](https://docs.lnav.org/en/latest/ui.html#hist));
33-
- analyze messages using SQLite ([press `;`](https://docs.lnav.org/en/latest/sqlext.html))
27+
- jump quickly to the previous/next error ([press `e`/`E`](https://docs.lnav.org/en/latest/hotkeys.html#spatial-navigation));
28+
- search using regular expressions ([press `/`](https://docs.lnav.org/en/latest/hotkeys.html#spatial-navigation));
29+
- highlight text with a regular expression ([`:highlight`](https://docs.lnav.org/en/latest/commands.html#highlight-pattern) command);
30+
- filter messages using [regular expressions](https://docs.lnav.org/en/latest/usage.html#regular-expression-match) or [SQLite expressions](https://docs.lnav.org/en/latest/usage.html#sqlite-expression);
31+
- pretty-print structured text ([press `P`](https://docs.lnav.org/en/latest/ui.html#pretty));
32+
- view a histogram of messages over time ([press `i`](https://docs.lnav.org/en/latest/ui.html#hist));
33+
- analyze messages using SQLite ([press `;`](https://docs.lnav.org/en/latest/sqlext.html))
3434

3535
## Screenshot
3636

3737
The following screenshot shows a mix of syslog and web access log
3838
files. Failed requests are shown in red. Identifiers, like IP
3939
address and PIDs are semantically highlighted.
4040

41-
[![Screenshot](docs/assets/images/lnav-front-page.png)](docs/assets/images/lnav-front-page.png)
41+
[![Screenshot](docs/assets/images/lnav-front-page.png)](docs/assets/images/lnav-front-page.png)
4242

4343
## Why not **just** use `tail`/`grep`/`less`?
4444

@@ -57,16 +57,16 @@ You can SSH into a demo node to play with lnav before installing.
5757
The "playground" account starts lnav with a couple of log files as
5858
an example:
5959

60-
[`$ ssh playground@demo.lnav.org`](ssh://playground@demo.lnav.org)
60+
[`$ ssh playground@demo.lnav.org`](ssh://playground@demo.lnav.org)
6161

6262
The "tutorial 1" account is an interactive tutorial that can teach
6363
you the basics of operation:
6464

65-
[`$ ssh tutorial1@demo.lnav.org`](ssh://tutorial1@demo.lnav.org)
65+
[`$ ssh tutorial1@demo.lnav.org`](ssh://tutorial1@demo.lnav.org)
6666

6767
## Installation
6868

69-
[Download a statically-linked binary for Linux/MacOS from the release page](https://github.com/tstack/lnav/releases/latest#release-artifacts)
69+
[Download a statically-linked binary for Linux/MacOS from the release page](https://github.com/tstack/lnav/releases/latest#release-artifacts)
7070

7171
### Brew on MacOS
7272

@@ -90,7 +90,7 @@ the log messages that were recognized[^1]. You can then use the
9090
usual hotkeys to move around the view (arrow keys or
9191
`j`/`k`/`h`/`l` to move down/up/left/right).
9292

93-
See the [Usage section](https://docs.lnav.org/en/latest/usage.html)
93+
See the [Usage section](https://docs.lnav.org/en/latest/usage.html)
9494
of the online documentation for more information.
9595

9696
[^1]: Files that do not contain log messages can be seen in the
@@ -101,28 +101,28 @@ of the online documentation for more information.
101101
On systems running `systemd-journald`, you can use `lnav` as the pager:
102102

103103
```
104-
$ journalctl | lnav
104+
$ journalctl | lnav
105105
```
106106

107107
or in follow mode:
108108

109109
```
110-
$ journalctl -f | lnav
110+
$ journalctl -f | lnav
111111
```
112112

113113
Since `journalctl`'s default output format omits the year, if you are
114114
viewing logs which span multiple years you will need to change the
115115
output format to include the year, otherwise `lnav` gets confused:
116116

117117
```
118-
$ journalctl -o short-iso | lnav
118+
$ journalctl -o short-iso | lnav
119119
```
120120

121121
It is also possible to use `journalctl`'s json output format and `lnav`
122122
will make use of additional fields such as PRIORITY and \_SYSTEMD_UNIT:
123123

124124
```
125-
$ journalctl -o json | lnav
125+
$ journalctl -o json | lnav
126126
```
127127

128128
In case some MESSAGE fields contain special characters such as
@@ -131,14 +131,14 @@ specifying `journalctl`'s `-a` option might be preferable in o
131131
to output those messages still in a non-binary representation:
132132

133133
```
134-
$ journalctl -a -o json | lnav
134+
$ journalctl -a -o json | lnav
135135
```
136136

137137
If using systemd v236 or newer, the output fields can be limited to
138138
the ones actually recognized by `lnav` for increased efficiency:
139139

140140
```
141-
$ journalctl -o json --output-fields=MESSAGE,PRIORITY,_PID,SYSLOG_IDENTIFIER,_SYSTEMD_UNIT | lnav
141+
$ journalctl -o json --output-fields=MESSAGE,PRIORITY,_PID,SYSLOG_IDENTIFIER,_SYSTEMD_UNIT | lnav
142142
```
143143

144144
If your system has been running for a long time, for increased
@@ -153,19 +153,19 @@ of log lines fed into `lnav` via `journalctl`'s `-b`
153153
Please file issues on this repository or use the discussions section.
154154
The following alternatives are also available:
155155

156-
- [support@lnav.org](mailto:support@lnav.org)
157-
- [Discord](https://discord.gg/erBPnKwz7R)
158-
- [Google Groups](https://groups.google.com/g/lnav)
156+
- [support@lnav.org](mailto:support@lnav.org)
157+
- [Discord](https://discord.gg/erBPnKwz7R)
158+
- [Google Groups](https://groups.google.com/g/lnav)
159159

160160
## Links
161161

162-
- [Main Site](https://lnav.org)
163-
- [**Documentation**](https://docs.lnav.org) on Read the Docs
164-
- [Internal Architecture](ARCHITECTURE.md)
162+
- [Main Site](https://lnav.org)
163+
- [**Documentation**](https://docs.lnav.org) on Read the Docs
164+
- [Internal Architecture](ARCHITECTURE.md)
165165

166166
## Contributing
167167

168-
- [Become a Sponsor on GitHub](https://github.com/sponsors/tstack)
168+
- [Become a Sponsor on GitHub](https://github.com/sponsors/tstack)
169169

170170
### Building From Source
171171

@@ -199,5 +199,5 @@ Run `./autogen.sh` if compiling from a cloned repository.
199199

200200
## See Also
201201

202-
[Angle-grinder](https://github.com/rcoh/angle-grinder) is a tool to slice and dice log files on the command-line.
202+
[Angle-grinder](https://github.com/rcoh/angle-grinder) is a tool to slice and dice log files on the command-line.
203203
If you're familiar with the SumoLogic query language, you might find this tool more comfortable to work with.

test/expected/test_text_file.sh_49e04528d748c7982cec2a7e2853462a0c74bcb1.out

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
# Table of Contents
66

7-
- [Table of Contents](#table-of-contents)
8-
- [Test](#test)
9-
- [Github Alerts](#github-alerts)
10-
- [Table](#table)
7+
- [Table of Contents](#table-of-contents)
8+
- [Test](#test)
9+
- [Github Alerts](#github-alerts)
10+
- [Table](#table)
1111

1212
## Test
1313

test/expected/test_text_file.sh_5b51b55dff7332c5bee2c9b797c401c5614d574a.out

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,35 +134,35 @@ view (reachable by pressing  t ).
134134
On systems running  systemd-journald , you can use  lnav  as the
135135
pager:
136136

137-
▌$ journalctl | lnav 
137+
▌$ journalctl | lnav 
138138

139139
or in follow mode:
140140

141-
▌$ journalctl -f | lnav 
141+
▌$ journalctl -f | lnav 
142142

143143
Since  journalctl 's default output format omits the year, if you are
144144
viewing logs which span multiple years you will need to change the
145145
output format to include the year, otherwise  lnav  gets confused:
146146

147-
▌$ journalctl -o short-iso | lnav 
147+
▌$ journalctl -o short-iso | lnav 
148148

149149
It is also possible to use  journalctl 's json output format and
150150
 lnav will make use of additional fields such as PRIORITY and
151151
_SYSTEMD_UNIT:
152152

153-
▌$ journalctl -o json | lnav 
153+
▌$ journalctl -o json | lnav 
154154

155155
In case some MESSAGE fields contain special characters such as ANSI
156156
color codes which are considered as unprintable by journalctl,
157157
specifying  journalctl 's  -a  option might be preferable in order to
158158
output those messages still in a non-binary representation:
159159

160-
▌$ journalctl -a -o json | lnav 
160+
▌$ journalctl -a -o json | lnav 
161161

162162
If using systemd v236 or newer, the output fields can be limited to
163163
the ones actually recognized by  lnav  for increased efficiency:
164164

165-
▌$ journalctl -o json --output-fields=MESSAGE,PRIORITY,_PID,SYSLOG_IDENTIFIER,_SYSTEMD_UNIT | lnav 
165+
▌$ journalctl -o json --output-fields=MESSAGE,PRIORITY,_PID,SYSLOG_IDENTIFIER,_SYSTEMD_UNIT | lnav 
166166

167167
If your system has been running for a long time, for increased
168168
efficiency you may want to limit the number of log lines fed into

0 commit comments

Comments
 (0)