Skip to content

Commit

Permalink
specifications: Preprocess the spec for properly rendering mermaid di…
Browse files Browse the repository at this point in the history
…agrams

In order for mermaid diagrams to render properly on both github and the
generated PDF, we need to preprocess the spec source and replace
[source,mermaid] occurences with [mermaid] ones.

Signed-off-by: Samuel Ortiz <sameo@rivosinc.com>
  • Loading branch information
sameo committed Nov 24, 2023
1 parent cc6b243 commit d1f5f40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions specification/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build:
--attribute=pdf-fontsdir=docs-resources/fonts \
--attribute=pdf-style=docs-resources/themes/riscv-pdf.yml \
--failure-level=ERROR \
--require=./preprocessor.rb \
--require=asciidoctor-bibtex \
--require=asciidoctor-diagram \
--require=asciidoctor-mathematical \
Expand Down
20 changes: 20 additions & 0 deletions specification/preprocessor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'asciidoctor'
require 'asciidoctor/extensions'

require 'asciidoctor/extensions'

Asciidoctor::Extensions.register do
preprocessor do
process do |document, reader|
new_lines = []
reader.readlines.each do |line|
if line.strip == "[source,mermaid]"
new_lines << "[mermaid]"
else
new_lines << line
end
end
Asciidoctor::Reader.new(new_lines)
end
end
end

0 comments on commit d1f5f40

Please sign in to comment.