Skip to content

Commit 8ace2c9

Browse files
authored
Merge pull request #4
* Adding code that restyles ordered lists as callout lists if they have…
1 parent ee23027 commit 8ace2c9

7 files changed

Lines changed: 113 additions & 13 deletions

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
/spec/reports/
88
/tmp/
99
/.idea
10-
**/sample.html
11-
**/sample_global_search.html
12-
**/callout-list-block-sample.html
13-
**/sample.pdf
10+
/test/*.html
11+
/test/*.pdf
1412
*.gem
1513
/Gemfile.lock
1614
/.asciidoctor

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22

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

5+
## [1.2.0] – 2022-07-30
6+
7+
### Added
8+
- If you add the role `[calloutlist]` to an ordered list then it will be styled to look like a callout list. This allows you to add callouts to annotated images etc.
9+
510
## [1.1.3] – 2022-07-07-16
611

712
### Fixed
8-
913
- The global and case-insensitive flags (ig) are now parsing correctly: using ii or gg will cause prevent the callout block from being processed. Thanks to Hakim Cassimally for finding the bug.
1014
- Escaped slash characters were not being processed in the search. Thanks to Hakim Cassimally for finding the bug.
1115

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ Using the text search method means that the location of the callout will move wi
7070
**@/_text_/gi**
7171
: And of course, you can combine the two, though I'm not sure why you'd want to.
7272

73+
## Standalone callout lists
74+
You can create a standalone callout list by adding the `calloutlist` role to an ordered list. This simply styles the list to make it look like a list of callouts so you can use it as a reference to annoted images etc.
75+
```asciidoc
76+
[calloutlist]
77+
. This list can be used to add references to annotated images
78+
. The list will look like a standard callout list.
79+
```
80+
7381
## Installation
7482

7583
Add this line to your application's Gemfile:

lib/asciidoctor-external-callout.rb

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
CALLOUT_SOURCE_BLOCK_ROLE ||= 'external-callout-block'
1919
CALLOUT_ORDERED_LIST_ROLE ||= 'external-callout-list'
2020

21+
STANDALONE_CALLOUT_LIST_STYLE ||= 'calloutlist'
22+
2123
LOCATION_TOKEN_RX ||= /@(\d+)|(@\/(?:\\\/|[^\/])+?\/[ig]{0,2})/
2224
LOCATION_TOKEN_ARRAY_RX ||= /^(@\d+|@\/(?:\\\/|[^\/]|)+?\/[ig]{0,2})((\s+@\d+)|(\s+@\/(?:\\\/|[^\/]|)+?\/[ig]{0,2}))*$/
2325

@@ -33,18 +35,30 @@
3335
# The makes sure it's the right kind of list.
3436
document.find_by context: :olist do |list|
3537

36-
if external_callout_list? list
38+
# if there is as calloutlist style attached to the block
39+
# then simply style the block as a colist. This will allow folk
40+
# to create callout blocks that can be attached to annotated images etc.
3741

38-
owner_block = owning_block list
42+
if list.style.include? STANDALONE_CALLOUT_LIST_STYLE
3943

40-
owner_block.subs.replace(owner_block.subs + [:callouts]).uniq
44+
list.context = :colist
4145

42-
process_callouts(list, owner_block)
46+
else
4347

44-
list.context = :colist
48+
if external_callout_list? list
49+
50+
owner_block = owning_block list
4551

46-
owner_block.add_role(CALLOUT_SOURCE_BLOCK_ROLE) unless owner_block.has_role?(CALLOUT_SOURCE_BLOCK_ROLE)
47-
list.add_role(CALLOUT_ORDERED_LIST_ROLE) unless list.has_role?(CALLOUT_ORDERED_LIST_ROLE)
52+
owner_block.subs.replace(owner_block.subs + [:callouts]).uniq
53+
54+
process_callouts(list, owner_block)
55+
56+
list.context = :colist
57+
58+
owner_block.add_role(CALLOUT_SOURCE_BLOCK_ROLE) unless owner_block.has_role?(CALLOUT_SOURCE_BLOCK_ROLE)
59+
list.add_role(CALLOUT_ORDERED_LIST_ROLE) unless list.has_role?(CALLOUT_ORDERED_LIST_ROLE)
60+
61+
end
4862

4963
end
5064

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 = "1.1.4"
6+
VERSION = "1.2.0"
77
end
88
end
99
end

test/asciidoctor-external-callout_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,16 @@ def test_for_escaped_slash
108108
end
109109
end
110110

111+
def test_for_standalone_callout
112+
113+
document = Asciidoctor.convert_file File.join(File.dirname(__FILE__), 'standalone-callout-sample.adoc'),
114+
safe: :unsafe, backend: :html5,
115+
attributes: {'stylesheet' => './callout.css'}
116+
117+
118+
assert document.blocks[document.blocks.length - 1].context = :colist
119+
120+
end
121+
111122
end
112123

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
= Test Document
2+
3+
:source-highlighter: highlight.js
4+
:icons: font
5+
6+
[source, ruby]
7+
----
8+
class ExternalCalloutTreeProcessor < Extensions::TreeProcessor
9+
10+
use_dsl
11+
12+
def process(document)
13+
14+
document.find_by context: :listing, style: 'source'.each do |src|
15+
16+
Open3.popen3 cmd do |stdin, stdout, _, wait_thr|
17+
stdin.write src.source
18+
stdin.close
19+
20+
result = []
21+
22+
while (line = stdout.gets)
23+
result << line
24+
end
25+
26+
result << 'Eureka'
27+
28+
src.lines.replace result
29+
wait_thr.value
30+
31+
end
32+
33+
end
34+
35+
end
36+
37+
end
38+
----
39+
40+
Can we add in an extra paragraph here?
41+
42+
How about a table?
43+
44+
|===
45+
| Header Cell 1 | Header Cell 2
46+
47+
| Row 1 Cell 1
48+
| Row 1 Cell 2
49+
50+
| Row 2 Cell 1
51+
| Row 2 Cell 2
52+
|===
53+
54+
. The `use_dsl` line @3
55+
. The process def at @5
56+
. Document object used at @5 @7
57+
. Result first used @/result/
58+
. There is no line zero @0
59+
. There is no line five hundred @500
60+
61+
//-
62+
[calloutlist]
63+
. This is a standalone callout
64+
. Which we can restyle
65+
. as a callout list

0 commit comments

Comments
 (0)