Skip to content

Commit

Permalink
Merge branch 'master' into MLJ-prepub-edits
Browse files Browse the repository at this point in the history
  • Loading branch information
d-gregorczyk authored Mar 31, 2023
2 parents 9fc4b58 + 0448aeb commit d3261be
Show file tree
Hide file tree
Showing 89 changed files with 5,476 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class AsciidocConverter(
val asciidoctor = Asciidoctor.Factory.create()

val anchorReplacements = mutableMapOf<String, LabelInfo>()
val customReferences = mutableSetOf<String>()

val requirementsBlockProcessor = RequirementsBlockProcessor()
asciidoctor.javaExtensionRegistry().block(requirementsBlockProcessor)
Expand All @@ -41,9 +40,9 @@ class AsciidocConverter(
)
asciidoctor.javaExtensionRegistry().treeprocessor(RequirementLevelProcessor())
asciidoctor.javaExtensionRegistry().preprocessor(DisableSectNumsProcessor())
asciidoctor.javaExtensionRegistry().preprocessor(ReferenceSanitizerPreprocessor())
asciidoctor.javaExtensionRegistry().preprocessor(ReferenceSanitizerPreprocessor(anchorReplacements))
asciidoctor.javaExtensionRegistry()
.postprocessor(ReferenceSanitizerPostprocessor(anchorReplacements, customReferences))
.postprocessor(ReferenceSanitizerPostprocessor(anchorReplacements))

asciidoctor.requireLibrary("asciidoctor-diagram") // enables plantuml
when (inputType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ enum class LabelSource {
SECTION,
TABLE_OR_FIGURE,
APPENDIX,
VOLUME
VOLUME,
UNKNOWN
}

data class LabelInfo(
Expand All @@ -25,8 +26,7 @@ data class LabelInfo(
)

class ReferenceSanitizerPostprocessor(
private val anchorLabels: Map<String, LabelInfo>,
private val customReferences: Set<String>
private val anchorLabels: Map<String, LabelInfo>
) : Postprocessor() {
override fun process(document: Document, output: String): String {
// skip numbering if xref style has been changed to reduce likelihood of broken references
Expand Down Expand Up @@ -84,6 +84,7 @@ class ReferenceSanitizerPostprocessor(
LabelSource.TABLE_OR_FIGURE -> anchor.text(anchorText ?: it.label)
LabelSource.APPENDIX -> anchor.text(anchorText ?: "$appendixSig${it.prefix}:${it.label}")
LabelSource.VOLUME -> anchor.text(anchorText ?: "$chapterSig${it.prefix}")
LabelSource.UNKNOWN -> anchor.text(anchorText ?: it.label)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import java.net.URLEncoder
import java.util.*


class ReferenceSanitizerPreprocessor : Preprocessor() {
class ReferenceSanitizerPreprocessor(
private val anchorReplacements: MutableMap<String, LabelInfo>
) : Preprocessor() {
private val variables = mutableMapOf<String, String>()

override fun process(document: org.asciidoctor.ast.Document, reader: PreprocessorReader) {
Expand All @@ -23,6 +25,7 @@ class ReferenceSanitizerPreprocessor : Preprocessor() {
val substitutedVariables = substituteVariables(refs[1].trim())
val encodedRefText = URLEncoder.encode(substitutedVariables, Charsets.UTF_8)
val transformed = "<<${refs[0]}$refSeparator$encodedRefText>>"
anchorReplacements[refs[0]] = LabelInfo(substitutedVariables, LabelSource.UNKNOWN)
logger.info { "Found reference with custom label: ${it.groupValues.first()} => $transformed" }
transformed
}
Expand Down
2 changes: 2 additions & 0 deletions .github/copy_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ cd ..
mkdir sdpi-supplement
cp -R asciidoc/images sdpi-supplement/images
cp -R asciidoc/js sdpi-supplement/js
cp -R asciidoc/css sdpi-supplement/css
cp -R asciidoc/fonts sdpi-supplement/fonts
rm -rf sdpi-supplement/.asciidoctor
rm -rf sdpi-supplement/readme.md
Loading

0 comments on commit d3261be

Please sign in to comment.