Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hiding lines in other languages #1339

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't swallow space after boring prefixes
  • Loading branch information
thecodewarrior committed Oct 10, 2020
commit 8b5f3736e7cc4e6a4459fce3868cd82694b15fb6
7 changes: 3 additions & 4 deletions guide/src/format/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,16 +275,15 @@ mdBook will then test the regex on each line and follow this pattern:

Here is the pattern generated for a boring prefix (the `{}` in replaced with the prefix string):
```re
^(\s*)(?P<escape>\\)?{} ?(.*)$
^(\s*)(?P<escape>\\)?{}(.*)$
```
Breaking it down, we have
- `^(\s*)`
Match the indentation, and put it in a group to preserve it in the output.
- `(?P<escape>\\)?`
If we find a backslash this group will match and trigger the escape mechanism.
- `{} ?`
Match the prefix and optionally the space after it. Note how this isn't in a group, meaning it
won't be included in the final line.
- `{}`
Match the prefix. Note how this isn't in a group, meaning it won't be included in the final line.
- `(.*)$`
Match the rest of the line, and put it in a group to preserve it in the output.

Expand Down
8 changes: 4 additions & 4 deletions guide/src/format/mdbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ the prefix can be escaped using a backslash. With the python example above, this
print(a, end=' ')
a, b = b, a+b
print()
~ # hide me!
\~ # leave me be!
~# hide me!
\~# leave me be!
~fib(1000)
```</code></pre>

Expand All @@ -62,8 +62,8 @@ will render as
print(a, end=' ')
a, b = b, a+b
print()
~ # hide me!
\~ # leave me be!
~# hide me!
\~# leave me be!
~fib(1000)
```

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ impl BoringPattern {
fn new_simple(prefix: &str) -> BoringPattern {
BoringPattern {
regex: Regex::new(&format!(
r"^(\s*)(?P<escape>\\)?{} ?(.*)$",
r"^(\s*)(?P<escape>\\)?{}(.*)$",
regex::escape(prefix)
))
.unwrap(),
Expand Down