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

Formats code blocks for better syntax highlighting [ci skip] #40079

Merged

Conversation

chiraggshah
Copy link
Contributor

Summary

The PR adds various languages to the fenced code blocks for better syntax highlighting

Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

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

A few of these don't quite fit, but most are great! 👍

@@ -461,7 +461,7 @@ Database Views

Imagine you need to work with a legacy database containing the following table:

```
```sql
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if this really benefits from highlighting...?

@@ -678,7 +678,7 @@ SELECT viewable_by, locked FROM clients

Be careful because this also means you're initializing a model object with only the fields that you've selected. If you attempt to access a field that is not in the initialized record you'll receive:

```
```ruby
Copy link
Member

Choose a reason for hiding this comment

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

This is technically not Ruby.

@@ -1236,13 +1236,13 @@ The code evaluating `Hotel::Image` needs to make sure

In these cases the interpreter issues a warning though:

```
```ruby
Copy link
Member

Choose a reason for hiding this comment

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

This is not really Ruby.

warning: toplevel constant Image referenced by Hotel::Image
```

This surprising constant resolution can be observed with any qualifying class:

```
```ruby
Copy link
Member

Choose a reason for hiding this comment

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

Because of the mixed content, I think the highlighting here detracts more than it adds.

@@ -208,7 +208,7 @@ Adding extra logging like this makes it easy to search for unexpected or unusual

When looking at database query output in logs, it may not be immediately clear why multiple database queries are triggered when a single method is called:

```
```ruby
Copy link
Member

Choose a reason for hiding this comment

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

Because of the mixed content, I think the highlighting here detracts more than it adds.

@@ -219,7 +219,7 @@ irb(main):001:0> Article.pamplemousse

After running `ActiveRecord::Base.verbose_query_logs = true` in the `bin/rails console` session to enable verbose query logs and running the method again, it becomes obvious what single line of code is generating all these discrete database calls:

```
```ruby
Copy link
Member

Choose a reason for hiding this comment

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

Because of the mixed content, I think the highlighting here detracts more than it adds.

@@ -666,7 +666,7 @@ Project.where("name = '#{params[:name]}'")

And now let's inject another query using the UNION statement:

```
```sql
Copy link
Member

Choose a reason for hiding this comment

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

This technically isn't valid SQL by itself, so the highlighting doesn't really work here.

@@ -734,7 +734,7 @@ This JavaScript code will simply display an alert box. The next examples do exac

These examples don't do any harm so far, so let's see how an attacker can steal the user's cookie (and thus hijack the user's session). In JavaScript you can use the `document.cookie` property to read and write the document's cookie. JavaScript enforces the same origin policy, that means a script from one domain cannot access cookies of another domain. The `document.cookie` property holds the cookie of the originating web server. However, you can read and write this property, if you embed the code directly in the HTML document (as it happens with XSS). Inject this anywhere in your web application to see your own cookie on the result page:

```
```js
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
```js
```html

@@ -4,7 +4,7 @@

Usage:

```
```bash
rails generate scaffold Pet name:string --database=animals
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rails generate scaffold Pet name:string --database=animals
$ bin/rails generate scaffold Pet name:string --database=animals

@@ -27,7 +27,7 @@

If you already have an abstract class and it follows a different pattern than Rails defaults, you can pass a parent class with the database argument.

```
```bash
rails generate scaffold Pet name:string --database=animals --parent=SecondaryBase
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rails generate scaffold Pet name:string --database=animals --parent=SecondaryBase
$ bin/rails generate scaffold Pet name:string --database=animals --parent=SecondaryBase

@chiraggshah chiraggshah force-pushed the syntax-highlighting-improvements branch from 2961a5c to 0302497 Compare August 21, 2020 10:16
@chiraggshah chiraggshah force-pushed the syntax-highlighting-improvements branch from 0302497 to 84d6a0e Compare August 21, 2020 10:17
@chiraggshah
Copy link
Contributor Author

@jonathanhefner Thanks for the review. I have made the suggested changes.

@jonathanhefner jonathanhefner merged commit ab4ab09 into rails:master Aug 21, 2020
@jonathanhefner
Copy link
Member

Thank you @chiraggshah!

@chiraggshah chiraggshah deleted the syntax-highlighting-improvements branch August 21, 2020 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants