coradoc 1.1.8 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/Rakefile +3 -12
- data/exe/coradoc +21 -2
- data/lib/coradoc/cli.rb +185 -91
- data/lib/coradoc/configurable.rb +527 -0
- data/lib/coradoc/coradoc.rb +463 -0
- data/lib/coradoc/core_model/annotation_block.rb +57 -0
- data/lib/coradoc/core_model/base.rb +172 -0
- data/lib/coradoc/core_model/bibliography.rb +41 -0
- data/lib/coradoc/core_model/bibliography_entry.rb +48 -0
- data/lib/coradoc/core_model/block.rb +63 -0
- data/lib/coradoc/core_model/children_content.rb +53 -0
- data/lib/coradoc/core_model/comment_block.rb +10 -0
- data/lib/coradoc/core_model/definition_item.rb +46 -0
- data/lib/coradoc/core_model/definition_list.rb +28 -0
- data/lib/coradoc/core_model/element_attribute.rb +26 -0
- data/lib/coradoc/core_model/example_block.rb +10 -0
- data/lib/coradoc/core_model/footnote.rb +92 -0
- data/lib/coradoc/core_model/horizontal_rule_block.rb +10 -0
- data/lib/coradoc/core_model/id_generator.rb +16 -0
- data/lib/coradoc/core_model/image.rb +66 -0
- data/lib/coradoc/core_model/inline_element.rb +140 -0
- data/lib/coradoc/core_model/list_block.rb +135 -0
- data/lib/coradoc/core_model/list_item.rb +142 -0
- data/lib/coradoc/core_model/listing_block.rb +13 -0
- data/lib/coradoc/core_model/literal_block.rb +10 -0
- data/lib/coradoc/core_model/metadata.rb +79 -0
- data/lib/coradoc/core_model/open_block.rb +10 -0
- data/lib/coradoc/core_model/paragraph_block.rb +10 -0
- data/lib/coradoc/core_model/pass_block.rb +10 -0
- data/lib/coradoc/core_model/quote_block.rb +12 -0
- data/lib/coradoc/core_model/reviewer_block.rb +10 -0
- data/lib/coradoc/core_model/sidebar_block.rb +10 -0
- data/lib/coradoc/core_model/source_block.rb +10 -0
- data/lib/coradoc/core_model/structural_element.rb +94 -0
- data/lib/coradoc/core_model/table.rb +148 -0
- data/lib/coradoc/core_model/term.rb +53 -0
- data/lib/coradoc/core_model/text_content.rb +22 -0
- data/lib/coradoc/core_model/toc.rb +105 -0
- data/lib/coradoc/core_model/toc_generator.rb +151 -0
- data/lib/coradoc/core_model/verse_block.rb +12 -0
- data/lib/coradoc/core_model.rb +77 -0
- data/lib/coradoc/document_builder.rb +184 -0
- data/lib/coradoc/document_manipulator.rb +203 -0
- data/lib/coradoc/errors.rb +312 -0
- data/lib/coradoc/format_module.rb +49 -0
- data/lib/coradoc/hooks.rb +176 -0
- data/lib/coradoc/input.rb +17 -7
- data/lib/coradoc/logger.rb +54 -0
- data/lib/coradoc/output.rb +17 -6
- data/lib/coradoc/performance_regression.rb +109 -0
- data/lib/coradoc/processor_registry.rb +50 -0
- data/lib/coradoc/query.rb +455 -0
- data/lib/coradoc/registry.rb +156 -0
- data/lib/coradoc/serializer/registry.rb +150 -0
- data/lib/coradoc/transform.rb +11 -0
- data/lib/coradoc/validation.rb +646 -0
- data/lib/coradoc/version.rb +1 -1
- data/lib/coradoc/visitor.rb +283 -0
- data/lib/coradoc.rb +40 -19
- metadata +67 -277
- data/.editorconfig +0 -15
- data/.envrc +0 -1
- data/.irbrc +0 -1
- data/.pryrc.sample +0 -1
- data/.rubocop.yml +0 -14
- data/.rubocop_todo.yml +0 -179
- data/CHANGELOG.md +0 -9
- data/CODE_OF_CONDUCT.md +0 -84
- data/Dockerfile +0 -19
- data/Gemfile +0 -16
- data/LICENSE.txt +0 -21
- data/Makefile +0 -35
- data/README.Docker.adoc +0 -57
- data/README.adoc +0 -119
- data/coradoc.gemspec +0 -40
- data/docker-compose.yml +0 -14
- data/exe/reverse_adoc +0 -81
- data/exe/w2a +0 -60
- data/flake.lock +0 -114
- data/flake.nix +0 -135
- data/lib/coradoc/converter.rb +0 -144
- data/lib/coradoc/document.rb +0 -77
- data/lib/coradoc/element/admonition.rb +0 -18
- data/lib/coradoc/element/attribute.rb +0 -36
- data/lib/coradoc/element/attribute_list.rb +0 -138
- data/lib/coradoc/element/audio.rb +0 -33
- data/lib/coradoc/element/author.rb +0 -24
- data/lib/coradoc/element/base.rb +0 -92
- data/lib/coradoc/element/bibliography.rb +0 -24
- data/lib/coradoc/element/bibliography_entry.rb +0 -24
- data/lib/coradoc/element/block/core.rb +0 -76
- data/lib/coradoc/element/block/example.rb +0 -23
- data/lib/coradoc/element/block/listing.rb +0 -21
- data/lib/coradoc/element/block/literal.rb +0 -21
- data/lib/coradoc/element/block/open.rb +0 -22
- data/lib/coradoc/element/block/pass.rb +0 -21
- data/lib/coradoc/element/block/quote.rb +0 -19
- data/lib/coradoc/element/block/reviewer_comment.rb +0 -19
- data/lib/coradoc/element/block/side.rb +0 -19
- data/lib/coradoc/element/block/sourcecode.rb +0 -21
- data/lib/coradoc/element/block.rb +0 -17
- data/lib/coradoc/element/break.rb +0 -11
- data/lib/coradoc/element/comment_block.rb +0 -22
- data/lib/coradoc/element/comment_line.rb +0 -18
- data/lib/coradoc/element/document_attributes.rb +0 -33
- data/lib/coradoc/element/header.rb +0 -22
- data/lib/coradoc/element/image/block_image.rb +0 -32
- data/lib/coradoc/element/image/core.rb +0 -58
- data/lib/coradoc/element/image/inline_image.rb +0 -12
- data/lib/coradoc/element/image.rb +0 -10
- data/lib/coradoc/element/include.rb +0 -18
- data/lib/coradoc/element/inline/anchor.rb +0 -19
- data/lib/coradoc/element/inline/attribute_reference.rb +0 -19
- data/lib/coradoc/element/inline/bold.rb +0 -25
- data/lib/coradoc/element/inline/cross_reference.rb +0 -46
- data/lib/coradoc/element/inline/footnote.rb +0 -24
- data/lib/coradoc/element/inline/hard_line_break.rb +0 -11
- data/lib/coradoc/element/inline/highlight.rb +0 -25
- data/lib/coradoc/element/inline/italic.rb +0 -25
- data/lib/coradoc/element/inline/link.rb +0 -42
- data/lib/coradoc/element/inline/monospace.rb +0 -25
- data/lib/coradoc/element/inline/quotation.rb +0 -20
- data/lib/coradoc/element/inline/small.rb +0 -19
- data/lib/coradoc/element/inline/span.rb +0 -37
- data/lib/coradoc/element/inline/subscript.rb +0 -20
- data/lib/coradoc/element/inline/superscript.rb +0 -20
- data/lib/coradoc/element/inline/underline.rb +0 -19
- data/lib/coradoc/element/inline.rb +0 -23
- data/lib/coradoc/element/list/core.rb +0 -51
- data/lib/coradoc/element/list/definition.rb +0 -29
- data/lib/coradoc/element/list/ordered.rb +0 -17
- data/lib/coradoc/element/list/unordered.rb +0 -17
- data/lib/coradoc/element/list.rb +0 -13
- data/lib/coradoc/element/list_item.rb +0 -98
- data/lib/coradoc/element/list_item_definition.rb +0 -32
- data/lib/coradoc/element/paragraph.rb +0 -37
- data/lib/coradoc/element/revision.rb +0 -27
- data/lib/coradoc/element/section.rb +0 -62
- data/lib/coradoc/element/table.rb +0 -91
- data/lib/coradoc/element/tag.rb +0 -19
- data/lib/coradoc/element/term.rb +0 -22
- data/lib/coradoc/element/text_element.rb +0 -92
- data/lib/coradoc/element/title.rb +0 -62
- data/lib/coradoc/element/video.rb +0 -50
- data/lib/coradoc/generator.rb +0 -19
- data/lib/coradoc/input/adoc.rb +0 -30
- data/lib/coradoc/input/docx.rb +0 -64
- data/lib/coradoc/input/html/LICENSE.txt +0 -25
- data/lib/coradoc/input/html/README.adoc +0 -308
- data/lib/coradoc/input/html/cleaner.rb +0 -142
- data/lib/coradoc/input/html/config.rb +0 -77
- data/lib/coradoc/input/html/converters/a.rb +0 -52
- data/lib/coradoc/input/html/converters/aside.rb +0 -16
- data/lib/coradoc/input/html/converters/audio.rb +0 -29
- data/lib/coradoc/input/html/converters/base.rb +0 -108
- data/lib/coradoc/input/html/converters/blockquote.rb +0 -22
- data/lib/coradoc/input/html/converters/br.rb +0 -15
- data/lib/coradoc/input/html/converters/bypass.rb +0 -81
- data/lib/coradoc/input/html/converters/code.rb +0 -23
- data/lib/coradoc/input/html/converters/div.rb +0 -19
- data/lib/coradoc/input/html/converters/dl.rb +0 -62
- data/lib/coradoc/input/html/converters/drop.rb +0 -26
- data/lib/coradoc/input/html/converters/em.rb +0 -21
- data/lib/coradoc/input/html/converters/figure.rb +0 -25
- data/lib/coradoc/input/html/converters/h.rb +0 -42
- data/lib/coradoc/input/html/converters/head.rb +0 -23
- data/lib/coradoc/input/html/converters/hr.rb +0 -15
- data/lib/coradoc/input/html/converters/ignore.rb +0 -20
- data/lib/coradoc/input/html/converters/img.rb +0 -110
- data/lib/coradoc/input/html/converters/li.rb +0 -17
- data/lib/coradoc/input/html/converters/mark.rb +0 -19
- data/lib/coradoc/input/html/converters/markup.rb +0 -31
- data/lib/coradoc/input/html/converters/math.rb +0 -38
- data/lib/coradoc/input/html/converters/ol.rb +0 -65
- data/lib/coradoc/input/html/converters/p.rb +0 -23
- data/lib/coradoc/input/html/converters/pass_through.rb +0 -17
- data/lib/coradoc/input/html/converters/pre.rb +0 -55
- data/lib/coradoc/input/html/converters/q.rb +0 -16
- data/lib/coradoc/input/html/converters/strong.rb +0 -20
- data/lib/coradoc/input/html/converters/sub.rb +0 -22
- data/lib/coradoc/input/html/converters/sup.rb +0 -22
- data/lib/coradoc/input/html/converters/table.rb +0 -319
- data/lib/coradoc/input/html/converters/td.rb +0 -81
- data/lib/coradoc/input/html/converters/text.rb +0 -32
- data/lib/coradoc/input/html/converters/th.rb +0 -18
- data/lib/coradoc/input/html/converters/tr.rb +0 -22
- data/lib/coradoc/input/html/converters/video.rb +0 -29
- data/lib/coradoc/input/html/converters.rb +0 -59
- data/lib/coradoc/input/html/errors.rb +0 -14
- data/lib/coradoc/input/html/html_converter.rb +0 -168
- data/lib/coradoc/input/html/plugin.rb +0 -131
- data/lib/coradoc/input/html/plugins/plateau.rb +0 -213
- data/lib/coradoc/input/html/postprocessor.rb +0 -220
- data/lib/coradoc/input/html.rb +0 -61
- data/lib/coradoc/legacy_parser.rb +0 -200
- data/lib/coradoc/oscal.rb +0 -99
- data/lib/coradoc/output/adoc.rb +0 -19
- data/lib/coradoc/output/coradoc_tree_debug.rb +0 -21
- data/lib/coradoc/parser/asciidoc/admonition.rb +0 -24
- data/lib/coradoc/parser/asciidoc/attribute_list.rb +0 -89
- data/lib/coradoc/parser/asciidoc/base.rb +0 -87
- data/lib/coradoc/parser/asciidoc/bibliography.rb +0 -29
- data/lib/coradoc/parser/asciidoc/block.rb +0 -94
- data/lib/coradoc/parser/asciidoc/citation.rb +0 -30
- data/lib/coradoc/parser/asciidoc/content.rb +0 -64
- data/lib/coradoc/parser/asciidoc/document_attributes.rb +0 -25
- data/lib/coradoc/parser/asciidoc/header.rb +0 -29
- data/lib/coradoc/parser/asciidoc/inline.rb +0 -195
- data/lib/coradoc/parser/asciidoc/list.rb +0 -115
- data/lib/coradoc/parser/asciidoc/paragraph.rb +0 -54
- data/lib/coradoc/parser/asciidoc/section.rb +0 -61
- data/lib/coradoc/parser/asciidoc/table.rb +0 -32
- data/lib/coradoc/parser/asciidoc/term.rb +0 -41
- data/lib/coradoc/parser/asciidoc/text.rb +0 -158
- data/lib/coradoc/parser/base.rb +0 -40
- data/lib/coradoc/parser.rb +0 -11
- data/lib/coradoc/reverse_adoc.rb +0 -18
- data/lib/coradoc/transformer.rb +0 -476
- data/lib/coradoc/util.rb +0 -12
- data/lib/reverse_adoc.rb +0 -20
- data/utils/inspect_asciidoc.rb +0 -29
- data/utils/parser_analyzer.rb +0 -66
- data/utils/round_trip.rb +0 -53
data/flake.nix
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
description = "Ruby Dev Env";
|
|
3
|
-
inputs = {
|
|
4
|
-
nixpkgs.url = "github:nixos/nixpkgs/master";
|
|
5
|
-
flake-utils.url = "github:numtide/flake-utils";
|
|
6
|
-
devshell.url = "github:numtide/devshell/main";
|
|
7
|
-
flake-compat = {
|
|
8
|
-
url = "github:edolstra/flake-compat";
|
|
9
|
-
flake = false;
|
|
10
|
-
};
|
|
11
|
-
};
|
|
12
|
-
outputs =
|
|
13
|
-
{ self
|
|
14
|
-
, nixpkgs
|
|
15
|
-
, flake-utils
|
|
16
|
-
, devshell
|
|
17
|
-
, flake-compat
|
|
18
|
-
, ...
|
|
19
|
-
}:
|
|
20
|
-
flake-utils.lib.eachDefaultSystem (system:
|
|
21
|
-
let
|
|
22
|
-
cwd = builtins.toString ./.;
|
|
23
|
-
overlays = map (x: x.overlays.default) [
|
|
24
|
-
devshell
|
|
25
|
-
];
|
|
26
|
-
pkgs = import nixpkgs { inherit system overlays; };
|
|
27
|
-
runtimeDependencies = with pkgs; [
|
|
28
|
-
graphviz
|
|
29
|
-
inkscape
|
|
30
|
-
jre
|
|
31
|
-
plantuml
|
|
32
|
-
xml2rfc
|
|
33
|
-
];
|
|
34
|
-
in
|
|
35
|
-
rec {
|
|
36
|
-
|
|
37
|
-
# nix develop
|
|
38
|
-
devShell = pkgs.devshell.mkShell {
|
|
39
|
-
|
|
40
|
-
env = [
|
|
41
|
-
];
|
|
42
|
-
commands = [
|
|
43
|
-
{
|
|
44
|
-
name = "soffice-test";
|
|
45
|
-
# name = "soffice"; # This for some reason will stall the shell.
|
|
46
|
-
command = "${pkgs.libreoffice-bin}/Applications/LibreOffice.app/Contents/MacOS/soffice \"$@\"";
|
|
47
|
-
help = "Run libreoffice CLI";
|
|
48
|
-
category = "App";
|
|
49
|
-
}
|
|
50
|
-
{
|
|
51
|
-
name = "reverse_adoc";
|
|
52
|
-
command = "exe/reverse_adoc \"$@\"";
|
|
53
|
-
help = "Run reverse_adoc CLI";
|
|
54
|
-
category = "App";
|
|
55
|
-
}
|
|
56
|
-
{
|
|
57
|
-
name = "coradoc";
|
|
58
|
-
command = "exe/coradoc \"$@\"";
|
|
59
|
-
help = "Run coradoc CLI";
|
|
60
|
-
category = "App";
|
|
61
|
-
}
|
|
62
|
-
{
|
|
63
|
-
name = "release";
|
|
64
|
-
command = "bundle exec rake release \"$@\"";
|
|
65
|
-
help = "Run rake release, which adds a tag and pushes to RubyGems";
|
|
66
|
-
category = "Ruby";
|
|
67
|
-
}
|
|
68
|
-
{
|
|
69
|
-
name = "lint";
|
|
70
|
-
command = "bundle exec rubocop \"$@\"";
|
|
71
|
-
help = "Run rubocop";
|
|
72
|
-
category = "Ruby";
|
|
73
|
-
}
|
|
74
|
-
{
|
|
75
|
-
name = "update-flakes";
|
|
76
|
-
command = "make update-flakes \"$@\"";
|
|
77
|
-
help = "Update all flakes";
|
|
78
|
-
category = "Nix";
|
|
79
|
-
}
|
|
80
|
-
] ++
|
|
81
|
-
# Only append these if there is no .tool-verions file
|
|
82
|
-
# to avoid conflicts:
|
|
83
|
-
(if ! builtins.pathExists ./.tool-versions then
|
|
84
|
-
[{
|
|
85
|
-
|
|
86
|
-
name = "irb";
|
|
87
|
-
command = "bundle exec irb \"$@\"";
|
|
88
|
-
help = "Run console IRB (has completion menu)";
|
|
89
|
-
category = "Ruby";
|
|
90
|
-
}
|
|
91
|
-
{
|
|
92
|
-
name = "console";
|
|
93
|
-
command = "bundle exec irb \"$@\"";
|
|
94
|
-
help = "Run console IRB (has completion menu)";
|
|
95
|
-
category = "Ruby";
|
|
96
|
-
}
|
|
97
|
-
{
|
|
98
|
-
name = "pry";
|
|
99
|
-
command = "bundle exec pry \"$@\"";
|
|
100
|
-
help = "Run pry";
|
|
101
|
-
category = "Ruby";
|
|
102
|
-
}
|
|
103
|
-
{
|
|
104
|
-
name = "rspec";
|
|
105
|
-
command = "bundle exec rspec \"$@\"";
|
|
106
|
-
help = "Run test suite";
|
|
107
|
-
category = "Ruby";
|
|
108
|
-
}]
|
|
109
|
-
else [ ]);
|
|
110
|
-
|
|
111
|
-
packages = with pkgs; [
|
|
112
|
-
# rubocop # Install with your Gemfile / gemspec
|
|
113
|
-
# ruby # Install with your favourite Ruby version manager, etc.
|
|
114
|
-
# rubyPackages.solargraph # Bring your own
|
|
115
|
-
# rubyfmt # Broken
|
|
116
|
-
bash
|
|
117
|
-
curl
|
|
118
|
-
fd
|
|
119
|
-
gnused
|
|
120
|
-
jq
|
|
121
|
-
ripgrep
|
|
122
|
-
rubyPackages.ruby-lsp
|
|
123
|
-
rubyPackages.sorbet-runtime
|
|
124
|
-
wget
|
|
125
|
-
# libreoffice-still # unsupported in darwin
|
|
126
|
-
# libreoffice-unwrapped # unsupported in darwin
|
|
127
|
-
# libreoffice # unsupported in darwin
|
|
128
|
-
# libreoffice-bin # soffice returns nothing. Wrapper to call LibreOffice.App/Contents/MacOS/soffice implemented in devShell's command
|
|
129
|
-
pkg-config # for building native extensions
|
|
130
|
-
] ++
|
|
131
|
-
runtimeDependencies;
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
}
|
data/lib/coradoc/converter.rb
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
require "fileutils"
|
|
2
|
-
|
|
3
|
-
module Coradoc
|
|
4
|
-
class Converter
|
|
5
|
-
attr_accessor :input, :output, :config
|
|
6
|
-
|
|
7
|
-
def initialize(input = nil, output = nil, **config)
|
|
8
|
-
@input = input || $stdin
|
|
9
|
-
@output = output || $stdout
|
|
10
|
-
|
|
11
|
-
@config = {
|
|
12
|
-
input_options: {},
|
|
13
|
-
output_options: {},
|
|
14
|
-
}.merge(config)
|
|
15
|
-
|
|
16
|
-
yield if block_given?
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.call(...)
|
|
20
|
-
new(...).convert
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def input_processor
|
|
24
|
-
if config[:input_processor]
|
|
25
|
-
Input[config[:input_processor]]
|
|
26
|
-
else
|
|
27
|
-
Input.select_processor(input)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def output_processor
|
|
32
|
-
if config[:output_processor]
|
|
33
|
-
Output[config[:output_processor]]
|
|
34
|
-
else
|
|
35
|
-
Output.select_processor(output)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def convert(data = nil)
|
|
40
|
-
input_processor.processor_id
|
|
41
|
-
output_id = output_processor.processor_id
|
|
42
|
-
|
|
43
|
-
unless data
|
|
44
|
-
input = self.input
|
|
45
|
-
input = File.open(input, "rb") if input.is_a? String
|
|
46
|
-
data = input.read
|
|
47
|
-
input_path = input.path if input.respond_to? :path
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Some input processors may prefer filenames
|
|
51
|
-
if input_processor.respond_to? :processor_wants_filenames
|
|
52
|
-
unless input.respond_to? :path
|
|
53
|
-
raise NoInputPathError,
|
|
54
|
-
"no input path given, but #{input_processor} wants that form. Ensure you don't read from standard input."
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
data = input.path
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
# We may need to configure destination path.
|
|
61
|
-
output = self.output
|
|
62
|
-
if output.is_a? String
|
|
63
|
-
FileUtils.mkdir_p(File.dirname(output))
|
|
64
|
-
output = File.open(output, "wb")
|
|
65
|
-
end
|
|
66
|
-
output_path = output.path if output.respond_to?(:path)
|
|
67
|
-
|
|
68
|
-
input_options = config[:input_options]
|
|
69
|
-
input_options = input_options.merge(destination: output_path) if output_path
|
|
70
|
-
input_options = input_options.merge(sourcedir: File.dirname(input_path)) if input_path
|
|
71
|
-
|
|
72
|
-
data = input_processor.processor_execute(data, input_options)
|
|
73
|
-
|
|
74
|
-
# Two options are possible at this point:
|
|
75
|
-
# Either we have a document we want to write to some output, or
|
|
76
|
-
# we have a Hash, that contains a list of files and their
|
|
77
|
-
# documents (where a nil key denotes the main file). Let's normalize
|
|
78
|
-
# those cases.
|
|
79
|
-
data = { nil => data } unless data.is_a? Hash
|
|
80
|
-
|
|
81
|
-
# Let's check an edge case of non-nil keys and no output path
|
|
82
|
-
if !output_path && data.keys.any? { |i| !i.nil? }
|
|
83
|
-
raise NoOutputPathError,
|
|
84
|
-
"no output path given, while wanting to write multiple files"
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
data = output_processor.processor_execute(data, config[:output_options])
|
|
88
|
-
|
|
89
|
-
if input_processor.respond_to?(:processor_postprocess)
|
|
90
|
-
data = input_processor.processor_postprocess(
|
|
91
|
-
data, input_options.merge(output_processor: output_id)
|
|
92
|
-
)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
# Now we have all, let's write.
|
|
96
|
-
data.each do |filename, content|
|
|
97
|
-
if filename.nil?
|
|
98
|
-
file = output
|
|
99
|
-
else
|
|
100
|
-
dirname = File.dirname(output_path)
|
|
101
|
-
file = "#{dirname}/#{filename}"
|
|
102
|
-
FileUtils.mkdir_p(File.dirname(file))
|
|
103
|
-
file = File.open(file, "wb")
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
file.write(content)
|
|
107
|
-
file.close
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
class ConverterArgumentError < ArgumentError; end
|
|
112
|
-
|
|
113
|
-
class NoInputPathError < ConverterArgumentError; end
|
|
114
|
-
class NoOutputPathError < ConverterArgumentError; end
|
|
115
|
-
class NoProcessorError < ConverterArgumentError; end
|
|
116
|
-
|
|
117
|
-
module CommonInputOutputMethods
|
|
118
|
-
def define(const)
|
|
119
|
-
@processors[const.processor_id] = const
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
def [](id)
|
|
123
|
-
@processors[id.to_sym]
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
def keys
|
|
127
|
-
@processors.keys
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
def select_processor(filename)
|
|
131
|
-
filename = filename.path if filename.respond_to? :path
|
|
132
|
-
unless filename.is_a? String
|
|
133
|
-
raise Converter::NoProcessorError,
|
|
134
|
-
"Can't find a path for #{filename}. You must manually select the processor."
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
@processors.values.find do |i|
|
|
138
|
-
i.processor_match?(filename)
|
|
139
|
-
end or raise Converter::NoProcessorError,
|
|
140
|
-
"You must manually select the processor for #{filename}"
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
end
|
data/lib/coradoc/document.rb
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
require_relative "element/base"
|
|
2
|
-
require_relative "element/title"
|
|
3
|
-
require_relative "element/block"
|
|
4
|
-
require_relative "element/bibliography"
|
|
5
|
-
require_relative "element/bibliography_entry"
|
|
6
|
-
require_relative "element/comment_block"
|
|
7
|
-
require_relative "element/comment_line"
|
|
8
|
-
require_relative "element/include"
|
|
9
|
-
require_relative "element/section"
|
|
10
|
-
require_relative "element/attribute"
|
|
11
|
-
require_relative "element/attribute_list"
|
|
12
|
-
require_relative "element/admonition"
|
|
13
|
-
require_relative "element/text_element"
|
|
14
|
-
require_relative "element/author"
|
|
15
|
-
require_relative "element/revision"
|
|
16
|
-
require_relative "element/header"
|
|
17
|
-
require_relative "element/document_attributes"
|
|
18
|
-
require_relative "element/paragraph"
|
|
19
|
-
require_relative "element/table"
|
|
20
|
-
require_relative "element/tag"
|
|
21
|
-
require_relative "element/list"
|
|
22
|
-
require_relative "element/inline"
|
|
23
|
-
require_relative "element/image"
|
|
24
|
-
require_relative "element/audio"
|
|
25
|
-
require_relative "element/video"
|
|
26
|
-
require_relative "element/break"
|
|
27
|
-
require_relative "element/term"
|
|
28
|
-
|
|
29
|
-
module Coradoc
|
|
30
|
-
class Document
|
|
31
|
-
class << self
|
|
32
|
-
def from_adoc(filename)
|
|
33
|
-
ast = Coradoc::Parser.parse(filename)
|
|
34
|
-
Coradoc::Transformer.transform(ast)
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def from_ast(elements)
|
|
38
|
-
@sections = []
|
|
39
|
-
|
|
40
|
-
elements.each do |element|
|
|
41
|
-
case element
|
|
42
|
-
when Coradoc::Element::DocumentAttributes
|
|
43
|
-
@document_attributes = element
|
|
44
|
-
|
|
45
|
-
when Coradoc::Element::Header
|
|
46
|
-
@header = element
|
|
47
|
-
|
|
48
|
-
when Coradoc::Element::Section
|
|
49
|
-
@sections << element
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
new(
|
|
54
|
-
document_attributes: @document_attributes,
|
|
55
|
-
header: @header,
|
|
56
|
-
sections: @sections,
|
|
57
|
-
)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
attr_accessor :header, :document_attributes, :sections
|
|
62
|
-
|
|
63
|
-
def initialize(options = {})
|
|
64
|
-
@document_attributes = options.fetch(:document_attributes,
|
|
65
|
-
Coradoc::Element::DocumentAttributes.new)
|
|
66
|
-
@header = options.fetch(:header, Coradoc::Element::Header.new(""))
|
|
67
|
-
@sections = options.fetch(:sections, [])
|
|
68
|
-
self
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def to_adoc
|
|
72
|
-
Coradoc::Generator.gen_adoc(@header) +
|
|
73
|
-
Coradoc::Generator.gen_adoc(@document_attributes) +
|
|
74
|
-
Coradoc::Generator.gen_adoc(@sections)
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Admonition < Base
|
|
4
|
-
attr_accessor :type, :content, :line_break
|
|
5
|
-
|
|
6
|
-
def initialize(content, type, options = {})
|
|
7
|
-
@content = content
|
|
8
|
-
@type = type.downcase.to_sym
|
|
9
|
-
@line_break = options.fetch(:line_break, "")
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def to_adoc
|
|
13
|
-
content = Coradoc::Generator.gen_adoc(@content)
|
|
14
|
-
"#{type.to_s.upcase}: #{content}#{@line_break}"
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Attribute < Base
|
|
4
|
-
attr_accessor :key, :value
|
|
5
|
-
|
|
6
|
-
def initialize(key, value, _options = {})
|
|
7
|
-
@key = key.to_s
|
|
8
|
-
@value = if extensions_value?(value.to_s)
|
|
9
|
-
build_values(value.to_s)
|
|
10
|
-
else
|
|
11
|
-
value.to_s.strip
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def extensions_value?(value)
|
|
16
|
-
v = value.split(",").map(&:strip)
|
|
17
|
-
v.intersect? %w[xml html pdf xml adoc rxl]
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
private
|
|
21
|
-
|
|
22
|
-
def build_values(value)
|
|
23
|
-
values = value.split(",").map(&:strip)
|
|
24
|
-
values.length > 1 ? values : values.first
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
class Glossaries
|
|
29
|
-
attr_reader :items
|
|
30
|
-
|
|
31
|
-
def initialize(items)
|
|
32
|
-
@items = items
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class AttributeList < Base
|
|
4
|
-
attr_accessor :positional, :named, :rejected_positional, :rejected_named
|
|
5
|
-
|
|
6
|
-
declare_children :positional, :named
|
|
7
|
-
|
|
8
|
-
def initialize(*positional, **named)
|
|
9
|
-
@positional = positional || []
|
|
10
|
-
@named = named || {}
|
|
11
|
-
@rejected_positional = []
|
|
12
|
-
@rejected_named = []
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def inspect
|
|
16
|
-
"AttributeList: " +
|
|
17
|
-
[
|
|
18
|
-
@positional.map(&:inspect).join(", "),
|
|
19
|
-
@named.map { |k, v| "#{k}: #{v.inspect}" }.join(", "),
|
|
20
|
-
(@rejected_positional.empty? or "rejected: #{@rejected_positional.inspect}"),
|
|
21
|
-
(@rejected_positional.empty? or "rejected: #{@rejected_named.inspect}"),
|
|
22
|
-
].reject { |i| i == true || i.empty? }.join(", ")
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def add_positional(*attr)
|
|
26
|
-
@positional += attr
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def add_named(name, value)
|
|
30
|
-
@named[name] = value
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def any?
|
|
34
|
-
!empty?
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def empty?
|
|
38
|
-
@positional.empty? && @named.empty?
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def validate_attr(attr, matcher)
|
|
42
|
-
matcher === attr
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def validate_positional(validators)
|
|
46
|
-
@positional.each_with_index do |value, i|
|
|
47
|
-
# TODO: Decide what to do with this value
|
|
48
|
-
_positional_name = validators[i][0]
|
|
49
|
-
|
|
50
|
-
validator = validators[i][1]
|
|
51
|
-
|
|
52
|
-
unless validator && validate_attr(value, validator)
|
|
53
|
-
@positional[i] = nil
|
|
54
|
-
@rejected_positional << [i, value]
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
@positional.pop while !@positional.empty? && @positional.last.nil?
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def validate_named(validators)
|
|
62
|
-
@named.each_with_index do |(name, value), _i|
|
|
63
|
-
name = name.to_sym
|
|
64
|
-
validator = validators[name]
|
|
65
|
-
|
|
66
|
-
unless validator && validate_attr(value, validator)
|
|
67
|
-
@named.delete(name)
|
|
68
|
-
@rejected_named << [name, value]
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def to_adoc(show_empty = true)
|
|
74
|
-
return "[]" if [@positional, @named].all?(:empty?)
|
|
75
|
-
|
|
76
|
-
adoc = +""
|
|
77
|
-
if !@positional.empty?
|
|
78
|
-
adoc << @positional.map do |p|
|
|
79
|
-
[nil, ""].include?(p) ? '""' : p
|
|
80
|
-
end.join(",")
|
|
81
|
-
end
|
|
82
|
-
adoc << "," if @positional.any? && @named.any?
|
|
83
|
-
adoc << @named.map do |k, v|
|
|
84
|
-
if v.is_a?(String)
|
|
85
|
-
if (v[0] == '"' && v[-1] == '"') || (v[0] == "'" && v[-1] == "'")
|
|
86
|
-
elsif v.include?(",") || v.include?('"')
|
|
87
|
-
v = v.gsub("\"", "\\\"")
|
|
88
|
-
v = "\"#{v}\""
|
|
89
|
-
end
|
|
90
|
-
elsif v.is_a?(Array)
|
|
91
|
-
v = "\"#{v.join(',')}\""
|
|
92
|
-
end
|
|
93
|
-
[k.to_s, "=", v].join
|
|
94
|
-
end.join(",")
|
|
95
|
-
|
|
96
|
-
if !empty? || (empty? && show_empty)
|
|
97
|
-
"[#{adoc}]"
|
|
98
|
-
elsif empty? && !show_empty
|
|
99
|
-
adoc
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
module Matchers
|
|
104
|
-
def one(*args)
|
|
105
|
-
One.new(*args)
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
class One
|
|
109
|
-
def initialize(*possibilities)
|
|
110
|
-
@possibilities = possibilities
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def ===(other)
|
|
114
|
-
@possibilities.any? { |i| i === other }
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def many(*args)
|
|
119
|
-
Many.new(*args)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
# TODO: Find a way to only reject some values but not all?
|
|
123
|
-
class Many
|
|
124
|
-
def initialize(*possibilities)
|
|
125
|
-
@possibilities = possibilities
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def ===(other)
|
|
129
|
-
other = other.split(",") if other.is_a?(String)
|
|
130
|
-
|
|
131
|
-
other.is_a?(Array) &&
|
|
132
|
-
other.all? { |i| @possibilities.any? { |p| p === i } }
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Audio < Base
|
|
4
|
-
attr_accessor :id, :title, :src, :options, :anchor, :attributes
|
|
5
|
-
|
|
6
|
-
declare_children :id, :title, :anchor, :attributes
|
|
7
|
-
|
|
8
|
-
def initialize(title, options = {})
|
|
9
|
-
@title = title
|
|
10
|
-
@id = options.fetch(:id, nil)
|
|
11
|
-
@anchor = Inline::Anchor.new(@id) if @id
|
|
12
|
-
@src = options.fetch(:src, "")
|
|
13
|
-
@attributes = options.fetch(:attributes, [])
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def to_adoc
|
|
17
|
-
anchor = @anchor.nil? ? "" : "#{@anchor.to_adoc}\n"
|
|
18
|
-
title = ".#{@title}\n" unless @title.empty?
|
|
19
|
-
attrs = @attributes.empty? ? "\[\]" : @attributes.to_adoc
|
|
20
|
-
[anchor, title, "audio::", @src, attrs].join("")
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
extend AttributeList::Matchers
|
|
24
|
-
VALIDATORS_NAMED = {
|
|
25
|
-
title: String,
|
|
26
|
-
start: Integer,
|
|
27
|
-
end: Integer,
|
|
28
|
-
options: many("nofollow", "noopener", "inline", "interactive"),
|
|
29
|
-
opts: many("nofollow", "noopener", "inline", "interactive"),
|
|
30
|
-
}.freeze
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Author < Base
|
|
4
|
-
attr_accessor :email, :last_name, :first_name
|
|
5
|
-
|
|
6
|
-
declare_children :email, :last_name, :first_name
|
|
7
|
-
|
|
8
|
-
def initialize(first_name, last_name, email, middle_name = nil)
|
|
9
|
-
@first_name = first_name
|
|
10
|
-
@last_name = last_name
|
|
11
|
-
@email = email
|
|
12
|
-
@middle_name = middle_name
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def to_adoc
|
|
16
|
-
adoc = @first_name.to_s
|
|
17
|
-
adoc << " #{@middle_name}" if @middle_name
|
|
18
|
-
adoc << " #{@last_name}"
|
|
19
|
-
adoc << " <#{@email}>\n" if @email
|
|
20
|
-
adoc
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
data/lib/coradoc/element/base.rb
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
module Coradoc
|
|
2
|
-
module Element
|
|
3
|
-
class Base
|
|
4
|
-
# The idea here, is that HTML content generators may often introduce
|
|
5
|
-
# a lot of unnecessary markup, that only makes sense in the HTML+CSS
|
|
6
|
-
# context. The idea is that certain cases can be simplified, making it
|
|
7
|
-
# so that the result is equivalent, but much simpler, allowing us to
|
|
8
|
-
# generate a nicer AsciiDoc syntax for those cases.
|
|
9
|
-
def simplify_block_content(content)
|
|
10
|
-
content = Array(content)
|
|
11
|
-
collected_content = []
|
|
12
|
-
content.each do |i|
|
|
13
|
-
case i
|
|
14
|
-
when Coradoc::Element::Section
|
|
15
|
-
return content unless i.safe_to_collapse?
|
|
16
|
-
|
|
17
|
-
collected_content << i.anchor if i.anchor
|
|
18
|
-
|
|
19
|
-
simplified = simplify_block_content(i.contents)
|
|
20
|
-
|
|
21
|
-
if simplified && !simplified.empty?
|
|
22
|
-
collected_content << simplified
|
|
23
|
-
end
|
|
24
|
-
else
|
|
25
|
-
collected_content << i
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
collected_content = collected_content.compact
|
|
30
|
-
|
|
31
|
-
# We can safely do this optimization only if there's just one other
|
|
32
|
-
# element inside this structure.
|
|
33
|
-
if collected_content.length <= 1
|
|
34
|
-
collected_content
|
|
35
|
-
else
|
|
36
|
-
content
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def self.declare_children(*children)
|
|
41
|
-
@children = (@children || []).dup + children
|
|
42
|
-
access_children
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Make each child available for access
|
|
46
|
-
def self.access_children
|
|
47
|
-
@children.each do |child|
|
|
48
|
-
attr_accessor child
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def self.visit(element, &block)
|
|
53
|
-
return element if element.nil?
|
|
54
|
-
|
|
55
|
-
element = yield element, :pre
|
|
56
|
-
element = if element.respond_to? :visit
|
|
57
|
-
element.visit(&block)
|
|
58
|
-
elsif element.is_a? Array
|
|
59
|
-
element.map { |child| visit(child, &block) }.flatten.compact
|
|
60
|
-
elsif element.is_a? Hash
|
|
61
|
-
result = {}
|
|
62
|
-
element.each do |k, v|
|
|
63
|
-
result[k] = visit(v, &block)
|
|
64
|
-
end
|
|
65
|
-
result
|
|
66
|
-
else
|
|
67
|
-
element
|
|
68
|
-
end
|
|
69
|
-
yield element, :post
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def self.children_accessors
|
|
73
|
-
@children || []
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def children_accessors
|
|
77
|
-
self.class.children_accessors
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def visit(&block)
|
|
81
|
-
children_accessors.each do |accessor|
|
|
82
|
-
child = public_send(accessor)
|
|
83
|
-
result = self.class.visit(child, &block)
|
|
84
|
-
if result != child
|
|
85
|
-
public_send(:"#{accessor}=", result)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
self
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|