Skip to content

Commit

Permalink
doc: escape braces in AsciiDoc
Browse files Browse the repository at this point in the history
This commit fixes a bug where AsciiDoc would drop any line containing a
'{foo}' because it interpreted it as an undefined attribute reference:

> Simple attribute references take the form {<name>}. If the attribute name
> is defined its text value is substituted otherwise the line containing the
> reference is dropped from the output.

See: https://www.methods.co.nz/asciidoc/chunked/ch30.html

We fix this by simply replacing all occurrences of '{' and '}' with
their escaped forms: '&#123;' and '&#125;'.

Fixes #1101
  • Loading branch information
BurntSushi committed Nov 6, 2018
1 parent fb62266 commit b41e596
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 6 additions & 1 deletion build.rs
Expand Up @@ -168,7 +168,12 @@ fn formatted_arg(arg: &RGArg) -> io::Result<String> {
}

fn formatted_doc_txt(arg: &RGArg) -> io::Result<String> {
let paragraphs: Vec<&str> = arg.doc_long.split("\n\n").collect();
let paragraphs: Vec<String> = arg.doc_long
.replace("{", "&#123;")
.replace("}", r"&#125;")
.split("\n\n")
.map(|s| s.to_string())
.collect();
if paragraphs.is_empty() {
return Err(ioerr(format!("missing docs for --{}", arg.name)));
}
Expand Down
10 changes: 5 additions & 5 deletions src/app.rs
Expand Up @@ -788,17 +788,17 @@ to one of eight choices: red, blue, green, cyan, magenta, yellow, white and
black. Styles are limited to nobold, bold, nointense, intense, nounderline
or underline.
The format of the flag is `{type}:{attribute}:{value}`. `{type}` should be
one of path, line, column or match. `{attribute}` can be fg, bg or style.
`{value}` is either a color (for fg and bg) or a text style. A special format,
`{type}:none`, will clear all color settings for `{type}`.
The format of the flag is '{type}:{attribute}:{value}'. '{type}' should be
one of path, line, column or match. '{attribute}' can be fg, bg or style.
'{value}' is either a color (for fg and bg) or a text style. A special format,
'{type}:none', will clear all color settings for '{type}'.
For example, the following command will change the match color to magenta and
the background color for line numbers to yellow:
rg --colors 'match:fg:magenta' --colors 'line:bg:yellow' foo.
Extended colors can be used for `{value}` when the terminal supports ANSI color
Extended colors can be used for '{value}' when the terminal supports ANSI color
sequences. These are specified as either 'x' (256-color) or 'x,x,x' (24-bit
truecolor) where x is a number between 0 and 255 inclusive. x may be given as
a normal decimal number or a hexadecimal number, which is prefixed by `0x`.
Expand Down

2 comments on commit b41e596

@okdana
Copy link
Contributor

@okdana okdana commented on b41e596 Nov 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered this method too. I'd ruled it out because it requires you to micro-manage the formatting in the Rust source, but i guess it's not like a lot of different people are touching it

You probably already get this, but just to leave a reminder somewhere, in addition to not putting {/} inside back-ticks, you'll also need to avoid putting them in indented literal blocks. (There aren't any instances of that in the options text right now, but there are a few --type-add examples in the 'configuration files' section that would break if this method were applied there.) FYI

@BurntSushi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye, thanks. And yeah, this isn't ideal. I'm not a huge fan of how it all works, but I don't have too many strenuous complaints. :)

Please sign in to comment.