Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

Update plugin to look like callouts in beta #11

Open
wants to merge 1 commit into
base: master
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
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Add the below to your `book.json` file, then run `gitbook install` :

```json
{
"plugins": ["hints"]
"plugins": [ "hints" ]
}
```

Expand All @@ -26,7 +26,7 @@ The above example will produce a styled alert, with an icon:

``` html
<div class="alert alert-info hints-alert">
<div class="hints-icon"><i class="fa fa-info"></i></div>
<div class="hints-icon"><i class="icon-info"></i></div>
<div class="hints-container">
<p>Important info: this note needs to be highlighted</p>
</div>
Expand All @@ -35,25 +35,7 @@ The above example will produce a styled alert, with an icon:

Available styles are:

- `info` (default)
- `tip`
- `danger`
- `working`

### Configuration

You can specify custom classes for the icons (or none) in your `book.json`:

```json
{
"plugins": ["hints"],
"pluginsConfig": {
"hints": {
"info": "fa fa-info-circle",
"tip": "fa fa-mortar-board",
"danger": "fa fa-exclamation-cicle",
"working": "fa fa-wrench"
}
}
}
```
- `info` (default)
- `success`
- `warning`
Binary file added assets/fonts/icomoon.eot
Binary file not shown.
14 changes: 14 additions & 0 deletions assets/fonts/icomoon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fonts/icomoon.ttf
Binary file not shown.
Binary file added assets/fonts/icomoon.woff
Binary file not shown.
38 changes: 38 additions & 0 deletions assets/icons.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
@font-face {
font-family: 'icomoon';
src: url('fonts/icomoon.eot?ocmtqn');
src: url('fonts/icomoon.eot?ocmtqn#iefix') format('embedded-opentype'),
url('fonts/icomoon.ttf?ocmtqn') format('truetype'),
url('fonts/icomoon.woff?ocmtqn') format('woff'),
url('fonts/icomoon.svg?ocmtqn#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}

[class^="icon-"], [class*=" icon-"] {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'icomoon' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;

/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

.icon-danger:before {
content: "\e901";
}
.icon-info:before {
content: "\e903";
}
.icon-success:before {
content: "\e902";
}
.icon-warning:before {
content: "\e900";
}
54 changes: 50 additions & 4 deletions assets/plugin-hints.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,55 @@
.alert {
border-left: 4px solid;
border-bottom: 0;
color: #444444;
overflow: auto;
padding-bottom: 0;
}

.alert-danger {
background: #fdf7f7;
border-color: #d9534f;
}

.alert-danger i {
color: #d9534f;
}

.alert-info {
background: #eff5ff;
border-color: #42acf3;
}

.alert-info i {
color: #42acf3;
}

.alert-success {
background: #f3f8f3;
border-color: #50af51;
}

.alert-success i {
color: #50af51;
}

.alert-warning {
background: #fcf8f2;
border-color: #f0ad4e;
}

.alert-warning i {
color: #f0ad4e;
}

i[class^="icon-"] {
font-size: 1.5em;
}

.hints-icon {
display: table-cell;
padding-right: 15px;
padding-left: 5px;
position: absolute;
}

.hints-container {
display: table-cell;
padding-left: 40px;
}
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var ALERT_STYLES = {
info:'info',
tip:'success',
danger:'danger',
working:'warning'
danger: 'danger',
info: 'info',
success: 'success',
warning: 'warning'
};

/**
Expand All @@ -12,7 +12,7 @@ var ALERT_STYLES = {
*/
function makeIcon(style, pluginConfig) {
var id = pluginConfig[style];
return '<div class="hints-icon"><i class="'+id+'"></i></div>';
return '<div class="hints-icon"><i class="icon-'+style+'"></i></div>';
}

/**
Expand All @@ -27,21 +27,22 @@ module.exports = {
book: {
assets: './assets',
css: [
'icons.css',
'plugin-hints.css'
]
},

blocks: {
hint: {
process: function (block) {
// Available styles: info, danger, tip, working
// Available styles: info, danger, success, warning
var style = block.kwargs.style || 'info';
var pluginConfig = this.config.get('pluginsConfig.hints');

return this
.renderBlock('markdown', block.body)
.then(function(renderedBody) {
return '<div class="alert alert-'+ALERT_STYLES[style]+' hints-alert">'
return '<div class="alert alert-' + ALERT_STYLES[style] + ' hints-alert">'
+ makeIcon(style, pluginConfig)
+ wrapInContainer(renderedBody)
+ '</div>';
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "gitbook-plugin-hints",
"description": "Defines four types of styled hint blocks: info, danger, tip, working.",
"description": "Defines four types of styled hint blocks: info, danger, success, warning.",
"main": "index.js",
"version": "1.0.2",
"version": "2.0.0",
"engines": {
"gitbook": ">2.x.x"
},
Expand All @@ -14,25 +14,21 @@
},
"gitbook": {
"properties": {
"info": {
"danger": {
"type": "string",
"title": "CSS class for the 'info' icons",
"default": "fa fa-info-circle"
"title": "CSS class for the 'danger' icons"
},
"tip": {
"info": {
"type": "string",
"title": "CSS class for the 'tip' icons",
"default": "fa fa-mortar-board"
"title": "CSS class for the 'info' icons"
},
"danger": {
"success": {
"type": "string",
"title": "CSS class for the 'danger' icons",
"default": "fa fa-exclamation-circle"
"title": "CSS class for the 'success' icons"
},
"working": {
"warning": {
"type": "string",
"title": "CSS class for the 'working' icons",
"default": "fa fa-wrench"
"title": "CSS class for the 'warning' icons"
}
}
}
Expand Down