Skip to content

Commit f726fc6

Browse files
committed
now supports left and right text alignment. Bumped to 0.2.0.
1 parent 2bccdfe commit f726fc6

File tree

4 files changed

+53
-17
lines changed

4 files changed

+53
-17
lines changed

README.md

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
# Block align plugin for GitBooks
22

3-
A quick way of aligning markdown blocks in a GitBook.
3+
A quick way of aligning markdown blocks in a GitBook. This should work for websites and generated ebooks.
44

5-
Example:
5+
GitBook Example:
66

77
```markdown
8-
{% center %}Some text that should be centered{% endcenter %}
8+
{% left %} This **will be** aligned left. {% endleft %}
9+
10+
{% right %} This **will be** aligned right. {% endright %}
11+
12+
{% center %} This **will be** centered. {% endcenter %}
913
```
1014

1115
Result:
1216

13-
<p class="text-center">Some text that should be centered</p>
14-
1517
```html
16-
<p class="text-center">Some text that should be centered</p>
18+
<div class="ba-left"><p>This <strong>will be</strong> aligned left.</p></div>
19+
20+
<div class="ba-right"><p>This <strong>will be</strong> aligned right.</p></div>
21+
22+
<div class="ba-center"><p>This <strong>will be</strong> centered.</p></div>
1723
```
24+
25+
<div style="text-align: left;"><p>This <strong>will be</strong> aligned left.</p></div>
26+
27+
<div style="text-align: right;"><p>This <strong>will be</strong> aligned right.</p></div>
28+
29+
<div style="text-align: center;"><p>This <strong>will be</strong> centered.</p></div>

assets/plugin.css

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
.ba-text-center {
1+
.ba-left {
2+
text-align: left;
3+
}
4+
.ba-right {
5+
text-align: right;
6+
}
7+
.ba-center {
28
text-align: center;
39
}

index.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,40 @@ var parseMarkdown = function(text) {
1111
return parsed;
1212
};
1313

14+
var wrap = function(block, position='left') {
15+
var body = ('<div class="ba-'+ position + '">'
16+
+ parseMarkdown(block.body)
17+
+ '</div>');
18+
19+
return {
20+
body: body,
21+
parse: true
22+
};
23+
}
24+
1425
module.exports = {
15-
book: {
26+
website: {
27+
assets: './assets',
28+
css: [ 'plugin.css' ]
29+
},
30+
ebook: {
1631
assets: './assets',
1732
css: [ 'plugin.css' ]
1833
},
1934
blocks: {
35+
left: {
36+
process: function(block) {
37+
return wrap(block, 'left');
38+
}
39+
},
40+
right: {
41+
process: function(block) {
42+
return wrap(block, 'right');
43+
}
44+
},
2045
center: {
2146
process: function(block) {
22-
var body = ('<div class="ba-text-center">'
23-
+ parseMarkdown(block.body)
24-
+ '</div>');
25-
26-
return {
27-
body: body,
28-
parse: true
29-
};
47+
return wrap(block, 'center');
3048
}
3149
}
3250
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gitbook-plugin-block-align",
33
"description": "A quick way of aligning markdown blocks in a GitBook.",
4-
"version": "0.1.3",
4+
"version": "0.2.0",
55
"author": "Chris Born",
66
"license": "Apache-2.0",
77
"engines": {

0 commit comments

Comments
 (0)