Module: MnConvert

Defined in:
lib/mnconvert.rb,
lib/mnconvert/version.rb

Defined Under Namespace

Modules: InputFormat

Constant Summary collapse

MNCONVERT_JAR_NAME =
"mnconvert.jar".freeze
MNCONVERT_JAR_PATH =
File.join(File.dirname(__FILE__), "..", "bin",
MNCONVERT_JAR_NAME)
VERSION =
"1.89.0"
MNCONVERT_JAR_VERSION =
VERSION

Class Method Summary collapse

Class Method Details

.convert(input_file, opts = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/mnconvert.rb', line 42

def self.convert(input_file, opts = {})
  validate(opts)

  cmd = [*java_cmd, input_file, *optional_opts(opts)].join(" ")

  puts cmd if opts[:debug]
  output_str, error_str, status = Open3.capture3(cmd)
  p output_str if opts[:debug]

  unless status.success?
    raise error_str
  end
end

.helpObject



30
31
32
33
34
# File 'lib/mnconvert.rb', line 30

def self.help
  cmd = ["java", *jvm_options, "-jar", MNCONVERT_JAR_PATH].join(" ")
  message, = Open3.capture3(cmd)
  message
end

.jvm_optionsObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mnconvert.rb', line 14

def self.jvm_options
  # Java 24+ caps XML entity size at 100000 by default, which large
  # Metanorma documents exceed; set no limits on the command line
  # so users do not need JAVA_TOOL_OPTIONS (whose "Picked up ..." banner
  # breaks Jing callers: metanorma/metanorma-pdfa#98).
  options = ["-Xss5m", "-Xmx1024m",
             "-Djdk.xml.maxGeneralEntitySizeLimit=0",
             "-Djdk.xml.totalEntitySizeLimit=0"]

  if RbConfig::CONFIG["host_os"].match?(/darwin|mac os/)
    options << "-Dapple.awt.UIElement=true"
  end

  options
end

.versionObject



36
37
38
39
40
# File 'lib/mnconvert.rb', line 36

def self.version
  cmd = ["java", *jvm_options, "-jar", MNCONVERT_JAR_PATH, "-v"].join(" ")
  message, = Open3.capture3(cmd)
  message.strip
end