Skip to content

Commit 68dcb73

Browse files
authored
Merge pull request #2 from RayOffiah/add-roles-to-source-listing-and-callout-list
Add roles to source listing and callout list
2 parents d65b44b + f278e09 commit 68dcb73

File tree

8 files changed

+494
-5
lines changed

8 files changed

+494
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Record of bug fixes, enhancements, and changes.
44

5+
## [1.0.0] – 22-06-16
6+
7+
### Added
8+
- Added roles to the source block and the callout list so that CSS folk can pick them out to make style changes (For example, adjusting the gap between callout items in the source code block.)
9+
510
## [0.0.6-beta6] – 2022-06-11
611

712
### Changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,46 @@ Or install it yourself as:
8080

8181
## Usage
8282

83-
TODO: Write usage instructions here
83+
To use the extension, you need to register it before calling one of the Asciidoc `convert` functions to render the output.
84+
85+
```ruby
86+
require 'asciidoctor-external-callout'
87+
require 'asciidoctor'
88+
89+
Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'), safe: :unsafe, backend: :html5
90+
```
91+
92+
## Use with the [IntelliJ Asciidoc Plugin](https://plugins.jetbrains.com/plugin/7391-asciidoc)
93+
94+
If you're not using the excellent Asciidoc plugin then you're really missing out.
95+
One if it's lesser known features is that it supports Asciidoc extensions written in Ruby:
96+
97+
1. Create a new folder structure in the root of your IntelliJ project called `.asciidoctor/lib`.
98+
2. Copy the file `asciidoctor-external-calllout.rb` from this distribution to `.asciidoctor/lib`.
99+
100+
Now, when you preview an Asciidoc file with the plugin enabled, external callouts will now show up in the preview.
101+
102+
## Formatting
103+
104+
By default, the callout extension will put a single space between callouts that occur on the same line. If you want to adjust this, then you need to create a style that puts a horizontal margin between the callouts:
105+
106+
```css
107+
div.external-callout-block i.conum {
108+
margin-left: 10px;
109+
margin-right: 10px;
110+
}
111+
```
112+
The callout attaches a class called `external-callout-block` to each source listing it processes. You can use this to differentiate between standard callouts, and callouts written by the extension.
113+
114+
The extension also adds a class called `external-callout-list` to the list of definitions at the bottom of the source block. (There's probably no need to adjust the styling for this.)
115+
116+
Then to convert a document with a stylesheet, use something like this:
117+
118+
```ruby
119+
Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'),
120+
safe: :unsafe, backend: :html5,
121+
attributes: {'stylesheet' => './callout.css'}
122+
```
84123

85124
## Development
86125

asciidoctor-external-callout.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Gem::Specification.new do |spec|
99
spec.email = ["[email protected]"]
1010

1111
spec.summary = "Asciidoc extension for adding callouts without marking up the source listing block."
12-
# spec.description = "TODO: Write a longer description or delete this line."
12+
spec.description = "If you can't add callout markers to your source listing" \
13+
"(if you need to keep a shell script runnable for example), then use this."
1314
spec.homepage = "https://github.com/RayOffiah/asciidoctor-external-callout-ruby"
1415
spec.license = "MIT"
1516
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")

lib/asciidoctor-external-callout.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
Asciidoctor::Extensions::register do
1717

18+
CALLOUT_SOURCE_BLOCK_ROLE = 'external-callout-block'
19+
CALLOUT_ORDERED_LIST_ROLE = 'external-callout-list'
20+
1821
LOCATION_TOKEN_RX = /@(\d+)|@\/([^\/]+?)\//
1922
LOCATION_TOKEN_ARRAY_RX = /^(@\d+|@\/[^\/]+?\/)((\s+@\d+)|(\s+@\/[^\/]+?\/))*$/
2023

@@ -37,6 +40,9 @@
3740

3841
list.context = :colist
3942

43+
owner_block.add_role(CALLOUT_SOURCE_BLOCK_ROLE) unless owner_block.has_role?(CALLOUT_SOURCE_BLOCK_ROLE)
44+
list.add_role(CALLOUT_ORDERED_LIST_ROLE) unless list.has_role?(CALLOUT_ORDERED_LIST_ROLE)
45+
4046
end
4147

4248
end

lib/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Asciidoctor
44
module External
55
module Callout
6-
VERSION = "0.0.6-beta7"
6+
VERSION = "1.0.0"
77
end
88
end
99
end

test/asciidoctor-default.css

Lines changed: 426 additions & 0 deletions
Large diffs are not rendered by default.

test/asciidoctor-external-callout_test.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,22 @@ def teardown
1212
end
1313

1414
def test_basic_conversion
15-
document = Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'), safe: :unsafe, backend: :html5
15+
document = Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'),
16+
safe: :unsafe, backend: :html5,
17+
attributes: {'stylesheet' => './callout.css'}
1618
assert document.instance_of? Document
1719
assert_equal 5, document.blocks.length
1820
assert_equal document.blocks[1].context, :paragraph
1921
assert_equal 4, document.blocks[4].items.length
2022
assert_equal 'The `use_dsl` line', document.blocks[4].items[0].instance_variable_get(:@text)
23+
assert_equal true, document.blocks[4].has_role?('external-callout-list')
2124
end
2225

2326
def test_callout_marker
24-
document = Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'), safe: :unsafe, backend: :html5
27+
document = Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'sample.adoc'),
28+
safe: :unsafe, backend: :html5,
29+
attributes: {'stylesheet' => './callout.css'}
30+
2531
assert document.blocks[0].context == :listing
2632
assert document.blocks[0].lines.length == 30
2733
assert document.blocks[0].lines[2].include? 'use_dsl <1>'

test/callout.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import url(asciidoctor-default.css);
2+
3+
div.external-callout-block i.conum {
4+
margin-left: 10px;
5+
margin-right: 10px;
6+
}

0 commit comments

Comments
 (0)