Skip to content
Merged
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
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = defineConfig([{
...globals.commonjs,
...globals.node,
},
ecmaVersion: 6,
ecmaVersion: 2020,
sourceType: 'module',
parserOptions: {},
},
Expand Down
5 changes: 3 additions & 2 deletions samples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</head>
<body>
<h4>docsify-plugin-flexible-alerts</h4>
<a href="./v4/index.html">Demo for docsify@v4</a>
</body>
<p><a href="./v4/index.html">Demo for docsify@v4</a></p>
<p><a href="./v5/index.html">Demo for docsify@v5</a></p>
</body>
</html>
212 changes: 212 additions & 0 deletions samples/v5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# docsify-plugin-flexible-alerts

## Note

> [!NOTE]
> An alert of type 'note' using global style 'callout'.

<!-- -->
> [!NOTE|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'note' using global style 'callout'.<br/>
> In addition, title and icon are hidden which are both alert specific options.

<!-- -->
> [!NOTE|label:Specific heading]
> An alert of type 'note' using global style 'callout'.<br/>
> In addition, we use an alert specific title which overrides default ones.

<!-- -->
> [!NOTE|style:flat]
> An alert of type 'note' using specific style 'flat' and overrides global style 'callout'.

<!-- -->
> [!NOTE|style:flat|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'note' using specific style 'flat' and overrides global style 'callout'.
>
> In addition, title is hidden which is also an alert specific option.

## Info

> [!INFO]
> An alert of type 'info' using global style 'callout'.

<!-- -->
> [!INFO|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'info' using global style 'callout'.<br/>
> In addition, title and icon are hidden which are both alert specific options.

<!-- -->
> [!INFO|label:Specific heading]
> An alert of type 'info' using global style 'callout'.<br/>
> In addition, we use an alert specific title which overrides default ones.

<!-- -->
> [!INFO|style:flat]
> An alert of type 'info' using specific style 'flat' and overrides global style 'callout'.

<!-- -->
> [!INFO|style:flat|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'info' using specific style 'flat' and overrides global style 'callout'.
>
> In addition, title is hidden which is also an alert specific option.

## Tip

> [!TIP]
> An alert of type 'tip' using global style 'callout'.

<!-- -->
> [!TIP|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'tip' using global style 'callout'.<br/>
> In addition, title and icon are hidden which are both alert specific options.

<!-- -->
> [!TIP|label:Specific heading]
> An alert of type 'tip' using global style 'callout'.<br/>
> In addition, we use an alert specific title which overrides default ones.

<!-- -->
> [!TIP|style:flat]
> An alert of type 'tip' using specific style 'flat' and overrides global style 'callout'.

<!-- -->
> [!TIP|style:flat|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'tip' using specific style 'flat' and overrides global style 'callout'.
>
> In addition, title is hidden which is also an alert specific option.

## Warning

> [!WARNING]
> An alert of type 'warning' using global style 'callout'.

<!-- -->
> [!WARNING|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'warning' using global style 'callout'.<br/>
> In addition, title and icon are hidden which are both alert specific options.

<!-- -->
> [!WARNING|label:Specific heading]
> An alert of type 'warning' using global style 'callout'.<br/>
> In addition, we use an alert specific title which overrides default ones.

<!-- -->
> [!WARNING|style:flat]
> An alert of type 'warning' using specific style 'flat' and overrides global style 'callout'.

<!-- -->
> [!WARNING|style:flat|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'warning' using specific style 'flat' and overrides global style 'callout'.
>
> In addition, title is hidden which is also an alert specific option.

## Important

> [!IMPORTANT]
> An alert of type 'important' using global style 'callout'.

<!-- -->
> [!IMPORTANT|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'important' using global style 'callout'.<br/>
> In addition, title and icon are hidden which are both alert specific options.

<!-- -->
> [!IMPORTANT|label:Specific heading]
> An alert of type 'important' using global style 'callout'.<br/>
> In addition, we use an alert specific title which overrides default ones.

<!-- -->
> [!IMPORTANT|style:flat]
> An alert of type 'important' using specific style 'flat' and overrides global style 'callout'.

<!-- -->
> [!IMPORTANT|style:flat|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'important' using specific style 'flat' and overrides global style 'callout'.
>
> In addition, title is hidden which is also an alert specific option.

## Danger

> [!DANGER]
> An alert of type 'danger' using global style 'callout'.

<!-- -->
> [!DANGER|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'danger' using global style 'callout'.<br/>
> In addition, title and icon are hidden which are both alert specific options.

<!-- -->
> [!DANGER|label:Specific heading]
> An alert of type 'danger' using global style 'callout'.<br/>
> In addition, we use an alert specific title which overrides default ones.

<!-- -->
> [!DANGER|style:flat]
> An alert of type 'danger' using specific style 'flat' and overrides global style 'callout'.

<!-- -->
> [!DANGER|style:flat|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'danger' using specific style 'flat' and overrides global style 'callout'.
>
> In addition, title is hidden which is also an alert specific option.

## Attention

> [!ATTENTION]
> An alert of type 'attention' using global style 'callout'.

<!-- -->
> [!ATTENTION|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'attention' using global style 'callout'.<br/>
> In addition, title and icon are hidden which are both alert specific options.

<!-- -->
> [!ATTENTION|label:Specific heading]
> An alert of type 'attention' using global style 'callout'.<br/>
> In addition, we use an alert specific title which overrides default ones.

<!-- -->
> [!ATTENTION|style:flat]
> An alert of type 'attention' using specific style 'flat' and overrides global style 'callout'.

<!-- -->
> [!ATTENTION|style:flat|labelVisibility:hidden|iconVisibility:hidden]
> An alert of type 'attention' using specific style 'flat' and overrides global style 'callout'.
>
> In addition, title is hidden which is also an alert specific option.

## Examples concerning various issues

> [!TIP]
> This is the description.

<!-- -->
> [!TIP] This is the description.

<!-- -->
> [!ATTENTION]
> This is the description.

<!-- -->
> [!ATTENTION]
> This is the description.

<!-- -->
> [!TIP|label:An example of pom.xml]
> This is the description.

<!-- -->
> [!TIP|label:自定义标题]
> 可以显示中文标题。

<!-- -->
> [!warning]
> 可以显示中文标题。<br>
> 可以显示中文标题。

<!-- -->
> [!TIP|label:внимание|iconVisibility:visible]
> Это тест для сообщений

<!-- -->
> Regular blockquotes can be used further.
36 changes: 36 additions & 0 deletions samples/v5/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>docsify-plugin-flexible-alerts</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="description" content="Description">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<link rel="stylesheet" href="//unpkg.com/docsify/lib/themes/vue.css">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css" title="docsify-darklight-theme" type="text/css" />
</head>
<body>
<div id="app"></div>

<script>
window.$docsify = {
name: 'Plugin demo',
repo: '',
search: 'auto',
'flexible-alerts': {
comment: {
label: "Comment",
icon: "fas fa-comment",
className: "note"
}
}
}
</script>
<script src="//unpkg.com/docsify@5.0.0-rc.3/dist/docsify.min.js"></script>
<script src="//unpkg.com/docsify@5.0.0-rc.3/dist/plugins/search.min.js"></script>
<script src="../docsify-plugin-flexible-alerts.js"></script>
<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript">
</script>
</body>
</html>
31 changes: 25 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ import styles from './style.scss';
return callback ? callback(match[1]) : match[1];
};

hook.afterEach(function (html, next) {
const modifiedHtml = html.replace(/<\s*blockquote[^>]*>\s+?(?:<p>)?\[!(\w*)((?:\|[\w*:[\u002E\s\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF-]*)*?)]([\s\S]*?)(?:<\/p>)?<\s*\/\s*blockquote>/g, function (match, key, settings, value) {
hook.afterEach((html) => {
return html.replace(/<\s*blockquote[^>]*>\s?(?:<p>)?\[!(\w*)((?:\|[\w*:[\u002E\s\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF-]*)*?)]([\s\S]*?)(?:<\/p>)?<\s*\/\s*blockquote>/g, function (match, key, settings, value) {

if (!options[key.toLowerCase()] && options.typeMappings[key.toLowerCase()]) {
key = options.typeMappings[key.toLowerCase()];
Expand Down Expand Up @@ -110,11 +110,30 @@ import styles from './style.scss';
</div>`
);
});

next(modifiedHtml);
});
};

window.$docsify = window.$docsify || {};
window.$docsify.plugins = [].concat(install, window.$docsify.plugins);
const docsify = window.$docsify || {};
const docsifyMajorVersion = window.Docsify.version.split('.')[0];

if (docsifyMajorVersion <= 4) {
window.$docsify = {
...docsify,
plugins: [].concat(install, docsify.plugins)
};
} else {
// docsify v5 overrides the blockquote renderer to inject its own callout alert style.
// To support v5 with this plugin we need to ensure that the blockquote is rendered using the v4 style.
window.$docsify = {
...docsify,
plugins: [].concat(install, docsify.plugins),
markdown: {
renderer: {
blockquote: function ({tokens}) {
return `<blockquote>${this.parser.parse(tokens)}</blockquote>`;
}
}
}
};
}
}());