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

feat: GitHub style callouts #2487

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions docs/adding-pages.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ To create section headers:

You need to create a `.nojekyll` in `./docs` to prevent GitHub Pages from ignoring files that begin with an underscore.

!> Docsify only looks for `_sidebar.md` in the current folder, and uses that, otherwise it falls back to the one configured using `window.$docsify.loadSidebar` config.
> [!IMPORTANT] Docsify only looks for `_sidebar.md` in the current folder, and uses that, otherwise it falls back to the one configured using `window.$docsify.loadSidebar` config.

Example file structure:

Expand Down Expand Up @@ -98,7 +98,7 @@ You can specify `alias` to avoid unnecessary fallback.
</script>
```

!> You can create a `README.md` file in a subdirectory to use it as the landing page for the route.
> [!IMPORTANT] You can create a `README.md` file in a subdirectory to use it as the landing page for the route.

## Set Page Titles from Sidebar Selection

Expand Down
4 changes: 2 additions & 2 deletions docs/cdn.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Uncompressed resources are available by omitting the `.min` from the filename.

Specifying the latest major version allows your site to receive all non-breaking enhancements ("minor" updates) and bug fixes ("patch" updates) as they are released. This is good option for those who prefer a zero-maintenance way of keeping their site up to date with minimal risk as new versions are published.

?> When a new major version is released, you will need to manually update the major version number after the `@` symbol in your CDN URLs.
> [!TIP] When a new major version is released, you will need to manually update the major version number after the `@` symbol in your CDN URLs.

<!-- prettier-ignore -->
```html
Expand All @@ -44,7 +44,7 @@ Specifying the latest major version allows your site to receive all non-breaking

Specifying an exact version prevents any future updates from affecting your site. This is good option for those who prefer to manually update their resources as new versions are published.

?> When a new version is released, you will need to manually update the version number after the `@` symbol in your CDN URLs.
> [!TIP] When a new version is released, you will need to manually update the version number after the `@` symbol in your CDN URLs.

<!-- prettier-ignore -->
```html
Expand Down
8 changes: 4 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ Key `bindings` are defined as case insensitive string values separated by `+`. M

The `callback` function receive a [keydown event](https://developer.mozilla.org/en-US/docs/Web/API/Element/keydown_event) as an argument.

!> Let site visitors know your custom key bindings are available! If a binding is associated with a DOM element, consider inserting a `<kbd>` element as a visual cue (e.g., <kbd>alt</kbd> + <kbd>a</kbd>) or adding [title](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title) and [aria-keyshortcuts](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-keyshortcuts) attributes for hover/focus hints.
> [!IMPORTANT] Let site visitors know your custom key bindings are available! If a binding is associated with a DOM element, consider inserting a `<kbd>` element as a visual cue (e.g., <kbd>alt</kbd> + <kbd>a</kbd>) or adding [title](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title) and [aria-keyshortcuts](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-keyshortcuts) attributes for hover/focus hints.

```js
window.$docsify = {
Expand Down Expand Up @@ -376,7 +376,7 @@ window.$docsify = {

Website logo as it appears in the sidebar. You can resize it using CSS.

!> Logo will only be visible if `name` prop is also set. See [name](#name) configuration.
> [!IMPORTANT] Logo will only be visible if `name` prop is also set. See [name](#name) configuration.

```js
window.$docsify = {
Expand Down Expand Up @@ -919,7 +919,7 @@ For more details, see [#1131](https://github.com/docsifyjs/docsify/issues/1131).

## themeColor ⚠️

!> Deprecated as of v5. Use the `--theme-color` [theme property](themes#theme-properties) to [customize](themes#customization) your theme color.
> [!IMPORTANT] Deprecated as of v5. Use the `--theme-color` [theme property](themes#theme-properties) to [customize](themes#customization) your theme color.

- Type: `String`

Expand All @@ -933,7 +933,7 @@ window.$docsify = {

## topMargin ⚠️

!> Deprecated as of v5. Use the `--scroll-padding-top` [theme property](themes#theme-properties) to specify a scroll margin when using a sticky navbar.
> [!IMPORTANT] Deprecated as of v5. Use the `--scroll-padding-top` [theme property](themes#theme-properties) to specify a scroll margin when using a sticky navbar.

- Type: `Number|String`
- Default: `0`
Expand Down
4 changes: 2 additions & 2 deletions docs/custom-navbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

If you need custom navigation, you can create a HTML-based navigation bar.

!> Note that documentation links begin with `#/`.
> [!IMPORTANT] Note that documentation links begin with `#/`.

```html
<!-- index.html -->
Expand Down Expand Up @@ -51,7 +51,7 @@ To create drop-down menus:
- [chinese](/zh-cn/)
```

!> You need to create a `.nojekyll` in `./docs` to prevent GitHub Pages from ignoring files that begin with an underscore.
> [!IMPORTANT] You need to create a `.nojekyll` in `./docs` to prevent GitHub Pages from ignoring files that begin with an underscore.

`_navbar.md` is loaded from each level directory. If the current directory doesn't have `_navbar.md`, it will fall back to the parent directory. If, for example, the current path is `/guide/quick-start`, the `_navbar.md` will be loaded from `/guide/_navbar.md`.

Expand Down
10 changes: 5 additions & 5 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ It is recommended that you save your files to the `./docs` subfolder of the `mai

![GitHub Pages](_images/deploy-github-pages.png)

!> You can also save files in the root directory and select `main branch`.
You'll need to place a `.nojekyll` file in the deploy location (such as `/docs` or the gh-pages branch)
> [!IMPORTANT] You can also save files in the root directory and select `main branch`.
> You'll need to place a `.nojekyll` file in the deploy location (such as `/docs` or the gh-pages branch)

## GitLab Pages

If you are deploying your master branch, create a `.gitlab-ci.yml` with the following script:

?> The `.public` workaround is so `cp` doesn't also copy `public/` to itself in an infinite loop.
> [!TIP] The `.public` workaround is so `cp` doesn't also copy `public/` to itself in an infinite loop.

```YAML
pages:
Expand All @@ -37,11 +37,11 @@ pages:
- master
```

!> You can replace script with `- cp -r docs/. public`, if `./docs` is your Docsify subfolder.
> [!IMPORTANT] You can replace script with `- cp -r docs/. public`, if `./docs` is your Docsify subfolder.

## Firebase Hosting

!> You'll need to install the Firebase CLI using `npm i -g firebase-tools` after signing into the [Firebase Console](https://console.firebase.google.com) using a Google Account.
> [!IMPORTANT] You'll need to install the Firebase CLI using `npm i -g firebase-tools` after signing into the [Firebase Console](https://console.firebase.google.com) using a Google Account.

Using a terminal, determine and navigate to the directory for your Firebase Project. This could be `~/Projects/Docs`, etc. From there, run `firebase init` and choose `Hosting` from the menu (use **space** to select, **arrow keys** to change options and **enter** to confirm). Follow the setup instructions.

Expand Down
8 changes: 4 additions & 4 deletions docs/embed-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Example:

If you embed the file as `iframe`, `audio` and `video`, then you may need to set the attributes of these tags.

?> Note, for the `audio` and `video` types, docsify adds the `controls` attribute by default. When you want add more attributes, the `controls` attribute need to be added manually if need be.
> [!TIP] Note, for the `audio` and `video` types, docsify adds the `controls` attribute by default. When you want add more attributes, the `controls` attribute need to be added manually if need be.

```md
[filename](_media/example.mp4 ':include :type=video controls width=100%')
Expand All @@ -101,13 +101,13 @@ Embedding any type of source code file, you can specify the highlighted language

[](_media/example.html ':include :type=code text')

?> How to set highlight? You can see [here](language-highlight.md).
> [!TIP] How to set highlight? You can see [here](language-highlight.md).

## Embed a gist

You can embed a gist as markdown content or as a code block - this is based on the approach at the start of [Embed Files](#embed-files) section, but uses a raw gist URL as the target.

?> **No** plugin or app config change is needed here to make this work. In fact, the "Embed" `script` tag that is copied from a gist will _not_ load even if you make plugin or config changes to allow an external script.
> [!TIP] **No** plugin or app config change is needed here to make this work. In fact, the "Embed" `script` tag that is copied from a gist will _not_ load even if you make plugin or config changes to allow an external script.

### Identify the gist's metadata

Expand All @@ -132,7 +132,7 @@ Here are two examples based on the sample gist:
- https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/content.md
- https://gist.githubusercontent.com/anikethsaha/f88893bb563bb7229d6e575db53a8c15/raw/script.js

?> Alternatively, you can get a raw URL directly clicking the _Raw_ button on a gist file. But, if you use that approach, just be sure to **remove** the revision number between `raw/` and the filename so that the URL matches the pattern above instead. Otherwise your embedded gist will **not** show the latest content when the gist is updated.
> [!TIP] Alternatively, you can get a raw URL directly clicking the _Raw_ button on a gist file. But, if you use that approach, just be sure to **remove** the revision number between `raw/` and the filename so that the URL matches the pattern above instead. Otherwise your embedded gist will **not** show the latest content when the gist is updated.

Continue with one of the sections below to embed the gist on a Docsify page.

Expand Down
78 changes: 56 additions & 22 deletions docs/helpers.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,106 @@ docsify extends Markdown syntax to make your documents more readable.

## Callouts

### Important content
Docsify supports [GitHub style](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts) callouts (also known as "admonitions" or "alerts").

Important content like:
<!-- prettier-ignore -->
> [!CAUTION]
> **Caution** callouts communicate negative potential consequences of an action.

```markdown
!> **Time** is money, my friend!
```
<!-- prettier-ignore -->
> [!IMPORTANT]
> **Important** callouts communicate information necessary for users to succeed.

is rendered as:
<!-- prettier-ignore -->
> [!NOTE]
> **Note** callouts communicate information that users should take into account.

!> **Time** is money, my friend!
<!-- prettier-ignore -->
> [!TIP]
> **Tip** callouts communicate optional information to help a user be more successful.

### Tips
<!-- prettier-ignore -->
> [!WARNING]
> **Warning** callouts communicate potential risks user should be aware of.

General tips like:
**Markdown**

<!-- prettier-ignore -->
```markdown
?> _TODO_ unit test
> [!CAUTION]
> **Caution** callouts communicate negative potential consequences of an action.

> [!IMPORTANT]
> **Important** callouts communicate information necessary for users to succeed.

> [!NOTE]
> **Note** callouts communicate information that users should take into account.

> [!TIP]
> **Tip** callouts communicate optional information to help a user be more successful.

> [!WARNING]
> **Warning** callouts communicate potential risks user should be aware of.
```

are rendered as:
### Legacy Style ⚠️

?> _TODO_ unit test
The following Docsify v4 callout syntax has been deprecated and will be removed in a future version.
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be great to add a console.warn when the respective piece of code runs, so people will know. We could also tell people to use major versions in deprecation messages, to start to get versionless people knowing what will be happening, so they can prepare. Wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it would be great to add a console.warn when the respective piece of code runs

Easy enough. Happy to add it. I may consolidate console deprecation warnings as well so they are easier to track and the output can be standardized.

We could also tell people to use major versions in deprecation messages, to start to get versionless people knowing what will be happening

This one may introduce some false positives simply because of the many different ways Docsify can be loaded, but I think a simple search for a <script> tag with a src value that matches the following criteria could work:

  • Source domain is different than route domain (i.e., markdown page domain)
  • Source domain contains a TLD (e.g. .com, .net, .org, etc.)
  • Source value matches \\docsify(\.min)?\.js
  • Source match is not preceded by a number (covers @version/ and /version/ CDN URLs)

This would match the following URLs and trigger the console warning:

The following URLs would be ignored:

FWIW, I may opt to implement this in a separate PR. Replying here for convenience. :)

Copy link
Member

@Koooooo-7 Koooooo-7 Aug 13, 2024

Choose a reason for hiding this comment

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

We could also tell people to use major versions in deprecation messages, to start to get versionless people knowing what will be happening

This one may introduce some false positives simply because of the many different ways Docsify can be loaded, but I think a simple search for a <script> tag with a src value that matches the following criteria could work...

As per the experience of I work the compatibility release, it seems too complicated for us to handle too much cases.

“There is an old saying: ‘Better to wrongfully kill a thousand than to let one escape.’”

If we can ensure that we notify as many people as possible who will be affected, notifying additional people who may not be impacted is acceptable.

So I suppose we could make the versionDetector simply like this:

Firstly, We check some common CDN providers (unpack, jsdelivr) import path format with versions.

Then, for other importing cases, we only try to find the docsify.min.js and the docsify.js content. No matter what the path folder /5/ nor the domain is, cos we don't know how users host docsify on which server, which place, which ip, which domain, which CDN...As long as it retrieves new docsify resources without versioning, it gets caught by the versionDetector.

When the site contains either resources name of them (docsify.min.js / docsify.js), we throw out a warning such as:

[docsify] versionless importing detect:
Use versionless may get the unpredictable breaking changes, please use the major versions or strict to one version instead.
More details: https://docsifyjs.org/docs/quickstart.md#specifying-docsify-versions

Conclusion:
If users import the resource online (host site on a domain or a raw IP are both okay ), they would get the warning.
If users deploy docsify internally or locally, they won't get a docsify warning, cos they won't get any docsify update also. version control doesn't matter for them. Once they manually upgrade docsify with versionDetector, they would get the warning then.


Besides, we provide a versionDetector config to manually suppress the warning and checking, when they don't care about any breaking changes or the resource import place is not a generic resources versioning control path (e.g. https://dontblameme.com/libs/update/20240401/docsify.min.js).

window.$docsify = {
  versionDetector: false
};

or am I too straightforward?


!> Legacy **Important** callouts are deprecated.

?> Legacy **Tip** callouts are deprecated.

**Markdown**

```markdown
!> Legacy **Important** callouts are deprecated.

?> Legacy **Tip** callouts are deprecated.
```

## Link attributes

### disabled

```md
```markdown
[link](/demo ':disabled')
```

### href

Sometimes we will use some other relative path for the link, and we have to tell docsify that we don't need to compile this link. For example:

```md
```markdown
[link](/demo/)
```

It will be compiled to `<a href="/#/demo/">link</a>` and will load `/demo/README.md`. Maybe you want to jump to `/demo/index.html`.

Now you can do that

```md
```markdown
[link](/demo/ ':ignore')
```

You will get `<a href="/demo/">link</a>`html. Do not worry, you can still set the title for the link.

```md
```markdown
[link](/demo/ ':ignore title')

<a href="/demo/" title="title">link</a>
```

### target

```md
```markdown
[link](/demo ':target=_blank')
[link](/demo2 ':target=_self')
```

## Task lists

```md
```markdown
- [ ] foo
- bar
- [x] baz
Expand All @@ -91,19 +125,19 @@ You will get `<a href="/demo/">link</a>`html. Do not worry, you can still set th

### Class names

```md
```markdown
![logo](https://docsify.js.org/_media/icon.svg ':class=someCssClass')
```

### IDs

```md
```markdown
![logo](https://docsify.js.org/_media/icon.svg ':id=someCssId')
```

### Sizes

```md
```markdown
![logo](https://docsify.js.org/_media/icon.svg ':size=WIDTHxHEIGHT')
![logo](https://docsify.js.org/_media/icon.svg ':size=50x100')
![logo](https://docsify.js.org/_media/icon.svg ':size=100')
Expand All @@ -119,7 +153,7 @@ You will get `<a href="/demo/">link</a>`html. Do not worry, you can still set th

## Heading IDs

```md
```markdown
### Hello, world! :id=hello-world
```

Expand Down
6 changes: 6 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
disabled
/>

<!-- Prism Theme -->
<!-- <link
rel="stylesheet"
href="//cdn.jsdelivr.net/npm/[email protected]/themes/prism-twilight.min.css"
/> -->

sy-records marked this conversation as resolved.
Show resolved Hide resolved
<!-- Site styles -->
<style>
/* Plugin: Carbon Ads */
Expand Down
4 changes: 2 additions & 2 deletions docs/language-highlight.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function add(a, b) {

Support for additional [languages](https://prismjs.com/#supported-languages) is available by loading the Prism [grammar files](https://cdn.jsdelivr.net/npm/prismjs@1/components/):

!> Prism grammar files must be loaded after Docsify.
> [!IMPORTANT] Prism grammar files must be loaded after Docsify.

```html
<script src="//cdn.jsdelivr.net/npm/prismjs@1/components/prism-bash.min.js"></script>
Expand All @@ -79,7 +79,7 @@ Support for additional [languages](https://prismjs.com/#supported-languages) is

Docsify's official [themes](themes) are compatible with Prism syntax highlighting themes.

!> Prism themes must be loaded after Docsify themes.
> [!IMPORTANT] Prism themes must be loaded after Docsify themes.

```html
<!-- Light and dark mode -->
Expand Down
4 changes: 2 additions & 2 deletions docs/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ window.$docsify = {
};
```

?> Configuration Options Reference: [marked documentation](https://marked.js.org/#/USING_ADVANCED.md)
> [!TIP] Configuration Options Reference: [marked documentation](https://marked.js.org/#/USING_ADVANCED.md)

You can completely customize the parsing rules.

Expand All @@ -31,7 +31,7 @@ window.$docsify = {

## Supports mermaid

!> Currently, docsify doesn't support the async mermaid render (the latest mermaid version supported is `v9.3.0`).
> [!IMPORTANT] Currently, docsify doesn't support the async mermaid render (the latest mermaid version supported is `v9.3.0`).

```js
// <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.css">
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Install the plugin and configure the track id.

Renders a larger collection of emoji shorthand codes. Without this plugin, Docsify is able to render only a limited number of emoji shorthand codes.

!> Deprecated as of v4.13. Docsify no longer requires this plugin for full emoji support.
> [!IMPORTANT] Deprecated as of v4.13. Docsify no longer requires this plugin for full emoji support.

```html
<script src="//cdn.jsdelivr.net/npm/docsify@5/dist/plugins/emoji.min.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Run the local server with `docsify serve`. You can preview your site in your bro
docsify serve docs
```

?> For more use cases of `docsify-cli`, head over to the [docsify-cli documentation](https://github.com/docsifyjs/docsify-cli).
> [!TIP] For more use cases of `docsify-cli`, head over to the [docsify-cli documentation](https://github.com/docsifyjs/docsify-cli).

## Manual initialization

Expand Down Expand Up @@ -76,7 +76,7 @@ Download or create an `index.html` template using the following markup:

### Specifying docsify versions

?> Note that in both of the examples below, docsify URLs will need to be manually updated when a new major version of docsify is released (e.g. `v5.x.x` => `v6.x.x`). Check the docsify website periodically to see if a new major version has been released.
> [!TIP] Note that in both of the examples below, docsify URLs will need to be manually updated when a new major version of docsify is released (e.g. `v5.x.x` => `v6.x.x`). Check the docsify website periodically to see if a new major version has been released.

Specifying a major version in the URL (`@5`) will allow your site to receive non-breaking enhancements (i.e. "minor" updates) and bug fixes (i.e. "patch" updates) automatically. This is the recommended way to load docsify resources.

Expand Down
Loading
Loading