metanorma 0.3.8 → 0.3.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 537c8c191cf1d55b37090f34b5cabd7f5332c0fc38f0378ef38499a2973d2666
4
- data.tar.gz: 2bcb82454d81c2bae64dd41e77bd6800f8557974cffa607a3cd709a6e15785c5
3
+ metadata.gz: 8162aba3ac1d75ae0feca29816f033aa318b6ea07198414dca00faf7e1ab0ae2
4
+ data.tar.gz: 8ffcb1addda80439b364d9c8b502cec40e0ffa3a113b3fb744bc7354b915f5e0
5
5
  SHA512:
6
- metadata.gz: 200991c8752ba12ba868a570f86254372e5a4ba35ce0b02c00102d25145ae91cc1e93c6bd81e62836129b8b537d058f67ce52e51b177e3c474366d03080b928a
7
- data.tar.gz: 8a94fee5cd05b87190ebecd89b387e63a773f7e6f0c6619d6dddb1fe800b8b05471ea3ec36f286971bc4b19c347aed05aa6a7feacf689ee079168dfea6755744
6
+ metadata.gz: cfcf0e8e9eab44f5838aa487fa1e0bcfc0551b3c2601ce40c8a4886a4946ac404e6fe62853939919fcc4c9003458e62014f3cbb9dc8d3ed205b18b984ed0072d
7
+ data.tar.gz: d4b10d194fd843cf1238442524e6cf41e0ad1486443bdb7e6706899badd835b5f571774db7f4376d0c49b9d75e4ab8f369e1eef80f55c6b6db6dace41fd7f331
data/Gemfile.lock CHANGED
@@ -3,13 +3,14 @@ PATH
3
3
  specs:
4
4
  metanorma (0.3.8)
5
5
  asciidoctor
6
+ htmlentities
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
11
  addressable (2.6.0)
11
12
  public_suffix (>= 2.0.2, < 4.0)
12
- algoliasearch (1.25.2)
13
+ algoliasearch (1.26.0)
13
14
  httpclient (~> 2.8, >= 2.8.3)
14
15
  json (>= 1.5.1)
15
16
  asciidoctor (1.5.8)
@@ -67,15 +68,15 @@ GEM
67
68
  thread_safe
68
69
  uuidtools
69
70
  isoics (0.1.7)
70
- json (2.1.0)
71
+ json (2.2.0)
71
72
  liquid (4.0.1)
72
- metanorma-iso (1.1.1)
73
+ metanorma-iso (1.1.2)
73
74
  asciidoctor (~> 1.5.7)
74
75
  iev (~> 0.2.0)
75
76
  isodoc (~> 0.9.8)
76
77
  metanorma-standoc (~> 1.1.0)
77
78
  ruby-jing
78
- metanorma-standoc (1.1.2)
79
+ metanorma-standoc (1.1.3)
79
80
  asciidoctor (~> 1.5.7)
80
81
  concurrent-ruby
81
82
  html2doc (~> 0.8.0)
data/README.adoc CHANGED
@@ -144,6 +144,7 @@ Usage: metanorma [options] <file>
144
144
  -a, --asciimath Preserve AsciiMath in Metanorma XML, instead of transforming it into MathML
145
145
  -R, --relaton FILENAME Export Relaton XML (bibdata) for this document to FILENAME
146
146
  (Also triggered through -x rxl)
147
+ -S, --sourcecode DIR Export sourcecode fragments from this document to directory DIR
147
148
  -h, --help Show this message
148
149
  ----
149
150
 
@@ -1,5 +1,6 @@
1
1
  require "fileutils"
2
2
  require "nokogiri"
3
+ require "htmlentities"
3
4
 
4
5
  module Metanorma
5
6
  class Compile
@@ -15,6 +16,7 @@ module Metanorma
15
16
  extensions = get_extensions(options) or return nil
16
17
  (file, isodoc = process_input(filename, options)) or return nil
17
18
  relaton_export(isodoc, options)
19
+ sourcecode_export(isodoc, options[:sourcecode])
18
20
  process_extensions(extensions, file, isodoc, options)
19
21
  end
20
22
 
@@ -31,6 +33,7 @@ module Metanorma
31
33
  options[:type] ||= o[:type]&.to_sym
32
34
  dir = filename.sub(%r(/[^/]+$), "/")
33
35
  options[:relaton] ||= "#{dir}/#{o[:relaton]}" if o[:relaton]
36
+ options[:sourcecode] ||= "#{dir}/#{o[:sourcecode]}" if o[:sourcecode]
34
37
  options[:extension_keys] ||= o[:extensions]&.split(/,[ ]*/)&.map(&:to_sym)
35
38
  options[:extension_keys] = nil if options[:extension_keys] == [:all]
36
39
  options[:format] ||= :asciidoc
@@ -115,6 +118,24 @@ module Metanorma
115
118
  File.open(options[:relaton], "w:UTF-8") { |f| f.write bibdata.to_xml }
116
119
  end
117
120
 
121
+ def clean_sourcecode(xml)
122
+ xml.xpath(".//callout | .//annotation | .//xmlns:callout | .//xmlns:annotation").each do |x|
123
+ x.remove
124
+ end
125
+ xml.xpath(".//br | .//xmlns:br").each { |x| x.replace("\n") }
126
+ HTMLEntities.new.decode(xml.children.to_xml)
127
+ end
128
+
129
+ def sourcecode_export(isodoc, dirname)
130
+ return unless dirname
131
+ xml = Nokogiri::XML(isodoc)
132
+ FileUtils.rm_rf dirname
133
+ FileUtils.mkdir_p dirname
134
+ xml.xpath("//sourcecode | //xmlns:sourcecode").each_with_index do |s, i|
135
+ File.open("#{dirname}/#{i}", "w:UTF-8") { |f| f.write clean_sourcecode(s.dup) }
136
+ end
137
+ end
138
+
118
139
  def process_extensions(extensions, file, isodoc, options)
119
140
  extensions.each do |ext|
120
141
  isodoc_options = @processor.extract_options(file)
@@ -1,3 +1,3 @@
1
1
  module Metanorma
2
- VERSION = "0.3.8"
2
+ VERSION = "0.3.9"
3
3
  end
data/metanorma.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.required_ruby_version = '>= 2.3.0'
26
26
 
27
27
  spec.add_runtime_dependency 'asciidoctor'
28
+ spec.add_runtime_dependency 'htmlentities'
28
29
 
29
30
  spec.add_development_dependency "bundler", "~> 2.0.1"
30
31
  spec.add_development_dependency "rake", "~> 12.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metanorma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.8
4
+ version: 0.3.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-31 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: htmlentities
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement