Skip to content

Commit ae6ee0d

Browse files
authored
Asciidoctor: Fix cramped include (#628)
Fixes the cramped include preprocessor to be compatible with the elastic compat preprocessor. The trouble here is that the cramped include preprocessor adds a frozen `''` to the stream of lines and the elastic compat processor attempts to modify it. It is tempting to remove all of the string mutation from the elastic compat preprocessor but that isn't compatible with how preprocessors have to hook in to asciidoctor. Asciidoctor expects them to mutate the strings they are given. Or, to be more precise, it expects that it only needs to call `process` on each line once, and that calling it will mutate the line in place. Which isn't possible for the frozen empty line that the cramped include preprocessor adds. We instead fix the problem by adding a mutable empty line to the stream. Making asciidoctor happy while slightly upsetting me. A better integration test would have caught this, but for now we include the compat preprocessor in the cramped include preprocessor's unit test to check for it. I'll work on a better integration test presently.
1 parent ee2d3d2 commit ae6ee0d

File tree

6 files changed

+76
-34
lines changed

6 files changed

+76
-34
lines changed

Makefile

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,5 @@ asciidoctor_check:
1919
$(MAKE) -C resources/asciidoctor
2020

2121
.PHONY: integration_test
22-
integration_test: expected_files_check same_files_check
23-
24-
.PHONY: expected_files_check
25-
expected_files_check: /tmp/readme_asciidoc
26-
# Checking for expected html files
27-
[ -s $^/index.html ]
28-
[ -s $^/_conditions_of_use.html ]
29-
# Checking for copied images
30-
[ -s $^/resources/cat.jpg ]
31-
[ -s $^/images/icons/caution.png ]
32-
[ -s $^/images/icons/important.png ]
33-
[ -s $^/images/icons/note.png ]
34-
[ -s $^/images/icons/warning.png ]
35-
[ -s $^/images/icons/callouts/1.png ]
36-
[ -s $^/images/icons/callouts/2.png ]
37-
[ -s $^/snippets/blocks/1.json ]
38-
39-
.PHONY: same_files_check
40-
same_files_check: /tmp/readme_asciidoc /tmp/readme_asciidoctor
41-
# The `grep -v snippets` is a known issue to be resolved "soon"
42-
diff \
43-
<(cd /tmp/readme_asciidoc && find * -type f | sort \
44-
| grep -v snippets/blocks \
45-
) \
46-
<(cd /tmp/readme_asciidoctor && find * -type f | sort)
47-
48-
/tmp/readme_asciidoc:
49-
./build_docs.pl --in_standard_docker \
50-
--doc README.asciidoc --out /tmp/readme_asciidoc
51-
52-
/tmp/readme_asciidoctor:
53-
./build_docs.pl --in_standard_docker --asciidoctor \
54-
--doc README.asciidoc --out /tmp/readme_asciidoctor
22+
integration_test:
23+
$(MAKE) -C integtest

integtest/Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
SHELL = /bin/bash -eux -o pipefail
2+
MAKEFLAGS += --silent
3+
4+
.PHONY: check
5+
check: \
6+
readme_expected_files readme_same_files \
7+
includes_expected_files includes_same_files
8+
9+
define STANDARD_EXPECTED_FILES=
10+
[ -s $^/index.html ]
11+
[ -s $^/docs.js ]
12+
[ -s $^/styles.css ]
13+
[ -s $^/template.md5 ]
14+
endef
15+
16+
.PHONY: readme_expected_files
17+
readme_expected_files: /tmp/readme_asciidoc
18+
$(STANDARD_EXPECTED_FILES)
19+
# Checking for expected html files
20+
[ -s $^/_conditions_of_use.html ]
21+
# Checking for copied images
22+
[ -s $^/resources/cat.jpg ]
23+
[ -s $^/images/icons/caution.png ]
24+
[ -s $^/images/icons/important.png ]
25+
[ -s $^/images/icons/note.png ]
26+
[ -s $^/images/icons/warning.png ]
27+
[ -s $^/images/icons/callouts/1.png ]
28+
[ -s $^/images/icons/callouts/2.png ]
29+
[ -s $^/snippets/blocks/1.json ]
30+
31+
.PHONY: %_expected_files
32+
%_expected_files: /tmp/%_asciidoc
33+
$(STANDARD_EXPECTED_FILES)
34+
35+
.PHONY: %_same_files
36+
%_same_files: /tmp/%_asciidoc /tmp/%_asciidoctor
37+
diff \
38+
<(cd /tmp/$*_asciidoc && find * -type f | sort \
39+
| grep -v snippets/blocks \
40+
) \
41+
<(cd /tmp/$*_asciidoctor && find * -type f | sort)
42+
43+
define BD=
44+
/docs_build/build_docs.pl --in_standard_docker --out $@
45+
endef
46+
47+
/tmp/readme_asciidoc: /docs_build/README.asciidoc
48+
$(BD) --doc /docs_build/README.asciidoc
49+
50+
/tmp/readme_asciidoctor: /docs_build/README.asciidoc
51+
$(BD) --asciidoctor --doc /docs_build/README.asciidoc
52+
53+
# These don't declare dependencies because we don't know in general which files
54+
# are needed to build which asciidoc files.
55+
.PRECIOUS: /tmp/%_asciidoc # don't try to remove the directory. you can't
56+
/tmp/%_asciidoc:
57+
$(BD) --doc $*.asciidoc
58+
59+
.PRECIOUS: /tmp/%_asciidoctor # don't try to remove the directory. you can't
60+
/tmp/%_asciidoctor:
61+
$(BD) --asciidoctor --doc $*.asciidoc

integtest/included.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
I am tiny.

integtest/includes.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
= Title
2+
3+
== Chapter
4+
5+
I include simple between here
6+
7+
include::included.asciidoc[]
8+
9+
and here.

resources/asciidoctor/lib/cramped_include/extension.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class CrampedInclude < Asciidoctor::Extensions::Preprocessor
1919
def process(_document, reader)
2020
def reader.prepare_lines(data, opts = {})
21-
super << ''
21+
super << +''
2222
end
2323
reader
2424
end

resources/asciidoctor/spec/cramped_include_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# frozen_string_literal: true
22

33
require 'cramped_include/extension'
4+
require 'elastic_compat_preprocessor/extension'
45
require 'shared_examples/does_not_break_line_numbers'
56

67
RSpec.describe CrampedInclude do
78
before(:each) do
89
Asciidoctor::Extensions.register do
910
preprocessor CrampedInclude
11+
preprocessor ElasticCompatPreprocessor
1012
end
1113
end
1214

0 commit comments

Comments
 (0)