[markdown] recognize more code fence langs

This commit is contained in:
Tim Stack 2022-08-21 22:02:46 -07:00
parent 0d1304e8ec
commit 5751fe89c4
9 changed files with 69 additions and 25 deletions

View File

@ -143,7 +143,7 @@ Lnav follows the usual GNU style for configuring and installing software:
Run `./autogen.sh` if compiling from a cloned repository.
```
```console
$ ./configure
$ make
$ sudo make install

View File

@ -15,8 +15,8 @@ Download a [statically linked 64-bit binary](https://github.com/tstack/lnav/rele
Install from the [Snap Store](https://snapcraft.io/lnav):
```shell
% sudo snap install lnav
```console
$ sudo snap install lnav
```
## MacOS
@ -26,8 +26,8 @@ Download a [statically linked 64-bit binary](https://github.com/tstack/lnav/rele
Install using [Homebrew](https://formulae.brew.sh/formula/lnav):
```shell
% brew install lnav
```console
$ brew install lnav
```
## Source
@ -37,12 +37,12 @@ Download the [source](https://github.com/tstack/lnav/releases/download/v{{site.v
and install any dependencies. The following commands will unpack the source
tar ball, configure the build for your system, build, and then install:
```shell
% tar xvfz lnav-{{site.version}}.tar.gz
% cd lnav-{{site.version}}
% ./configure
% make
% make install
```console
$ tar xvfz lnav-{{site.version}}.tar.gz
$ cd lnav-{{site.version}}
$ ./configure
$ make
$ make install
```
### GitHub

View File

@ -126,8 +126,8 @@ flag to specify the commands or queries you want to execute. For example, to get
the top 10 client IP addresses from an apache access log file and write the
results to standard out in CSV format:
```shell
% lnav -n \
```console
$ lnav -n \
-c ';SELECT c_ip, count(*) AS total FROM access_log GROUP BY c_ip ORDER BY total DESC LIMIT 10' \
-c ':write-csv-to -' \
access.log

View File

@ -39,7 +39,7 @@ defaults to "std" if not given). For example, the following command can be used
to import the regex at "https://regex101.com/r/zpEnjV/2" into the format named "
re101_example_log":
```shell
```console
$ lnav -m regex101 import https://regex101.com/r/zpEnjV/2 re101_example_log
```
@ -53,7 +53,7 @@ If you have a log format with a regex that needs to be updated, you can push
the regex to regex101.com for editing with a command like (replace
"myformat_log"/"std" with the name of your format and regex):
```shell
```console
$ lnav -m format myformat_log regex std regex101 push
```
@ -63,7 +63,7 @@ the new regex101.com entry will be printed out. You can use that URL to edit the
regex to your needs. Once you're done editing the regex, you can pull the
changes down to a "patch" file using the following command:
```shell
```console
$ lnav -m format myformat_log regex std regex101 pull
```

View File

@ -192,6 +192,53 @@ md2attr_line::leave_block(const md4cpp::event_handler::block& bl)
code_detail->lang.size);
if (lang_sf == "lnav") {
readline_lnav_highlighter(block_text, block_text.length());
} else if (lang_sf == "sql" || lang_sf == "sqlite") {
readline_sqlite_highlighter(block_text, block_text.length());
} else if (lang_sf == "shell" || lang_sf == "bash") {
readline_shlex_highlighter(block_text, block_text.length());
} else if (lang_sf == "console"
|| lang_sf.iequal(
string_fragment::from_const("shellsession")))
{
static const pcrepp SH_PROMPT(R"([^\$>#%]*[\$>#%]\s+)");
attr_line_t new_block_text;
attr_line_t cmd_block;
int prompt_size = 0;
for (auto line : block_text.split_lines()) {
if (!cmd_block.empty()
&& endswith(cmd_block.get_string(), "\\\n"))
{
cmd_block.append(line).append("\n");
continue;
}
if (!cmd_block.empty()) {
readline_shlex_highlighter_int(
cmd_block,
cmd_block.length(),
line_range{prompt_size, (int) cmd_block.length()});
new_block_text.append(cmd_block);
cmd_block.clear();
}
pcre_context_static<10> pc;
pcre_input pi(line.get_string());
if (SH_PROMPT.match(pc, pi)) {
prompt_size = pc.all()->length();
line.with_attr(string_attr{
line_range{0, prompt_size},
VC_ROLE.value(role_t::VCR_LIST_GLYPH),
});
cmd_block.append(line).append("\n");
} else {
line.with_attr_for_all(VC_ROLE.value(role_t::VCR_COMMENT));
new_block_text.append(line).append("\n");
}
}
block_text = new_block_text;
}
auto code_lines = block_text.rtrim().split_lines();

View File

@ -45,10 +45,6 @@ static void readline_sqlite_highlighter_int(attr_line_t& al,
int x,
line_range sub);
static void readline_shlex_highlighter_int(attr_line_t& al,
int x,
line_range sub);
static bool
is_bracket(const std::string& str, int index, bool is_lit)
{
@ -307,7 +303,7 @@ readline_sqlite_highlighter(attr_line_t& al, int x)
al, x, line_range{0, (int) al.get_string().length()});
}
static void
void
readline_shlex_highlighter_int(attr_line_t& al, int x, line_range sub)
{
attr_line_builder alb(al);

View File

@ -40,6 +40,7 @@ void readline_command_highlighter(attr_line_t& line, int x);
void readline_sqlite_highlighter(attr_line_t& line, int x);
void readline_shlex_highlighter_int(attr_line_t& al, int x, line_range sub);
void readline_shlex_highlighter(attr_line_t& line, int x);
void readline_lnav_highlighter(attr_line_t& line, int x);

View File

@ -70,7 +70,7 @@ been loaded, you can use the following options:
the file "foo.log" and go to the tenth line in the file,
you can do:
lnav -c ':goto 10' foo.log 
lnav -c ':goto 10' foo.log 
This option can be given multiple times to execute
multiple operations in sequence.

View File

@ -164,9 +164,9 @@ software:
Run  ./autogen.sh  if compiling from a cloned repository.
$ ./configure 
$ make 
$ sudo make install 
$ ./configure 
$ make 
$ sudo make install 
See Also