-
Notifications
You must be signed in to change notification settings - Fork 141
Fix tagging documentation #689
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| #### `filterTags`: Toggling alternative contents in a page | ||
|
|
||
| You can use tags to selectively filter HTML elements when building a site. | ||
|
|
||
| Tags are specified by the `tags` attribute, **and can be attached to any HTML element**. During rendering, only elements that match tags specified in the `site.json` files will be rendered. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Attaching tags to elements: | ||
| ```html | ||
| # Print 'Hello world' | ||
|
|
||
| <p tags="language--java">System.out.println("Hello world");</p> | ||
| <p tags="language--C#">Console.WriteLine("Hello world");</p> | ||
| <p tags="language--python">print("Hello world")</p> | ||
| ``` | ||
|
|
||
| You need to specify the tags to include in `site.json`, under the `tags` option: | ||
|
|
||
| ```json | ||
| { | ||
| ... | ||
| "tags": ["language--java"] | ||
| } | ||
| ``` | ||
|
|
||
| All other tagged elements will be filtered out. In this case, only the element with the `language--java` tag will be rendered. This is helpful when creating multiple versions of a page without having to maintain separate copies. | ||
|
|
||
| </div> | ||
|
|
||
| If the `tags` option is not specified in `site.json`, all tagged elements will be rendered. | ||
|
|
||
| **You can also use multiple tags in a single HTML element. Specify each tag in the `tags` attribute** separated by a space. An element will be rendered if **any of the tags** matches the one in `site.json`. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Attaching multiple tags to an element: | ||
| ```html | ||
| # For loops | ||
|
|
||
| <p tags="language--java language--C#">for (int i = 0; i < 5; i++) { ... }</p> | ||
| ``` | ||
|
|
||
| As long as the `language--java` or `language--C#` tag is specified, the code snippet will be rendered. | ||
|
|
||
| </div> | ||
|
|
||
| Alternatively, you can specify tags to render for a page in the front matter. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Specifying tags in front matter: | ||
| ```html | ||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--java"] | ||
| </frontmatter> | ||
| ``` | ||
| </div> | ||
|
|
||
| <span id="short" class="d-none"> | ||
|
|
||
| ```html | ||
| <p tags="language--java advanced">System.out.println("Hello world");</p> | ||
| <p tags="language--C# basic">Console.WriteLine("Hello world");</p> | ||
| ``` | ||
| ```html | ||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--java"] | ||
| </frontmatter> | ||
| ``` | ||
| </span> | ||
|
|
||
| Tags in `site.json` will be merged with the ones in the front matter, and are processed after front matter tags. See [Hiding Tags]({{ baseUrl }}/userGuide/tweakingThePageStructure.html#hiding-tags) for more information. | ||
|
|
||
| #### Advanced Tagging Tips | ||
|
|
||
| You can use a `*` in a tag name to match elements more generally. A `*` in a tag will match any number of characters at its position. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Using general tags: | ||
| ```html | ||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--*"] | ||
| </frontmatter> | ||
|
|
||
| <p tags="language--java">System.out.println("Hello world");</p> | ||
| <p tags="language--C#">Console.WriteLine("Hello world");</p> | ||
| <p tags="language--python">print("Hello world")</p> | ||
| ``` | ||
|
|
||
| All 3 `<p>`s will be shown. | ||
|
|
||
| </div> | ||
|
|
||
| #### Hiding Tags | ||
|
|
||
| Using `-` at the start of a tag hides all tags matching the expression. This is helpful for disabling a group of tags and enabling a particular tag. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Using general tags: | ||
| ```html | ||
| index.md | ||
|
|
||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--java"] | ||
| </frontmatter> | ||
|
|
||
| <p tags="language--java">System.out.println("Hello world");</p> | ||
| <p tags="language--C#">Console.WriteLine("Hello world");</p> | ||
| <p tags="language--python">print("Hello world")</p> | ||
| ``` | ||
|
|
||
| ```json | ||
| site.json | ||
|
|
||
| { | ||
| ... | ||
| "tags": ["-language--*", "language--C#"] | ||
| } | ||
| ``` | ||
|
|
||
| `language--java` is overridden by `-language--*`, so only `language--C#` is shown. | ||
|
|
||
| </div> | ||
|
|
||
| This only works because tags are processed left to right, so all `language--*` tags are hidden before `language--C#`. Tags in `site.json` are processed after tags in `<frontmatter>`. | ||
|
|
||
| <span id="short" class="d-none"> | ||
| ```html | ||
| # Print 'Hello world' | ||
|
|
||
| <p tags="language--java">System.out.println("Hello world");</p> | ||
| <p tags="language--C#">Console.WriteLine("Hello world");</p> | ||
| <p tags="language--python">print("Hello world")</p> | ||
| ``` | ||
| ```json | ||
| { | ||
| ... | ||
| "plugins" : [ | ||
| "filterTags" | ||
| ], | ||
| "pluginsContext" : { | ||
| "filterTags" : { | ||
| "tags": ["language--java"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| </span> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,134 +1,5 @@ | ||
| ## Tags | ||
|
|
||
| You can use tags to selectively filter HTML elements when building a site. | ||
|
|
||
| Tags are specified by the `tags` attribute, **and can be attached to any HTML element**. During rendering, only elements that match tags specified in the `site.json` files will be rendered. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Attaching tags to elements: | ||
| ```html | ||
| # Print 'Hello world' | ||
|
|
||
| <p tags="language--java">System.out.println("Hello world");</p> | ||
| <p tags="language--C#">Console.WriteLine("Hello world");</p> | ||
| <p tags="language--python">print("Hello world")</p> | ||
| ``` | ||
|
|
||
| You need to specify the tags to include in `site.json`, under the `tags` option: | ||
|
|
||
| ```json | ||
| { | ||
| ... | ||
| "tags": ["language--java"] | ||
| } | ||
| ``` | ||
|
|
||
| All other tagged elements will be filtered out. In this case, only the element with the `language--java` tag will be rendered. This is helpful when creating multiple versions of a page without having to maintain separate copies. | ||
|
|
||
| </div> | ||
|
|
||
| If the `tags` option is not specified in `site.json`, all tagged elements will be rendered. | ||
|
|
||
| **You can also use multiple tags in a single HTML element. Specify each tag in the `tags` attribute** separated by a space. An element will be rendered if **any of the tags** matches the one in `site.json`. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Attaching multiple tags to an element: | ||
| ```html | ||
| # For loops | ||
|
|
||
| <p tags="language--java language--C#">for (int i = 0; i < 5; i++) { ... }</p> | ||
| ``` | ||
|
|
||
| As long as the `language--java` or `language--C#` tag is specified, the code snippet will be rendered. | ||
|
|
||
| </div> | ||
|
|
||
| Alternatively, you can specify tags to render for a page in the front matter. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Specifying tags in front matter: | ||
| ```html | ||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--java"] | ||
| </frontmatter> | ||
| ``` | ||
| </div> | ||
| <include src="../plugins/filterTags.mbdf" /> | ||
|
|
||
| <span id="short" class="d-none"> | ||
|
|
||
| ```html | ||
| <p tags="language--java advanced">System.out.println("Hello world");</p> | ||
| <p tags="language--C# basic">Console.WriteLine("Hello world");</p> | ||
| ``` | ||
| ```html | ||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--java"] | ||
| </frontmatter> | ||
| ``` | ||
| <include src="../plugins/filterTags.mbdf#short" /> | ||
| </span> | ||
|
|
||
| Tags in `site.json` will be merged with the ones in the front matter, and are processed after front matter tags. See [Hiding Tags]({{ baseUrl }}/userGuide/tweakingThePageStructure.html#hiding-tags) for more information. | ||
|
|
||
| ## Advanced Tagging Tips | ||
|
|
||
| ### General Tags | ||
|
|
||
| You can use a `*` in a tag name to match elements more generally. A `*` in a tag will match any number of characters at its position. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Using general tags: | ||
| ```html | ||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--*"] | ||
| </frontmatter> | ||
|
|
||
| <p tags="language--java">System.out.println("Hello world");</p> | ||
| <p tags="language--C#">Console.WriteLine("Hello world");</p> | ||
| <p tags="language--python">print("Hello world")</p> | ||
| ``` | ||
|
|
||
| All 3 `<p>`s will be shown. | ||
|
|
||
| </div> | ||
|
|
||
| ### Hiding Tags | ||
|
|
||
| Using `-` at the start of a tag hides all tags matching the expression. This is helpful for disabling a group of tags and enabling a particular tag. | ||
|
|
||
| <div class="indented"> | ||
|
|
||
| {{ icon_example }} Using general tags: | ||
| ```html | ||
| index.md | ||
|
|
||
| <frontmatter> | ||
| title: "Hello World" | ||
| tags: ["language--java"] | ||
| </frontmatter> | ||
|
|
||
| <p tags="language--java">System.out.println("Hello world");</p> | ||
| <p tags="language--C#">Console.WriteLine("Hello world");</p> | ||
| <p tags="language--python">print("Hello world")</p> | ||
| ``` | ||
|
|
||
| ```json | ||
| site.json | ||
|
|
||
| { | ||
| ... | ||
| "tags": ["-language--*", "language--C#"] | ||
| } | ||
| ``` | ||
|
|
||
| `language--java` is overridden by `-language--*`, so only `language--C#` is shown. | ||
|
|
||
| </div> | ||
|
|
||
| This only works because tags are processed left to right, so all `language--*` tags are hidden before `language--C#`. Tags in `site.json` are processed after tags in `<frontmatter>`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.