-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coradoc integration #89
coradoc integration #89
Conversation
@@ -1,12 +1,36 @@ | |||
module ReverseAdoc | |||
module Converters | |||
class Ol < Base | |||
def convert(node, state = {}) | |||
def to_coradoc(node, state = {}) #FIXIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for to_coradoc is too high. [<11, 13, 4> 17.49/15]
Method has too many lines. [16/10]
Missing space after #.
Do not place comments on the same line as the def keyword.
@@ -1,9 +1,9 @@ | |||
module ReverseAdoc | |||
module Converters | |||
class Td < Base | |||
def convert(node, state = {}) | |||
def to_coradoc(node, state = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for to_coradoc is too high. [<17, 23, 8> 29.7/15]
Cyclomatic complexity for to_coradoc is too high. [7/6]
Method has too many lines. [19/10]
ReverseAdoc.config.with(options) do | ||
result = ReverseAdoc::Converters.lookup(root.name).convert(root) | ||
ReverseAdoc.cleaner.tidy(result) | ||
result = ReverseAdoc::Converters.lookup(root.name).to_coradoc(root) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless assignment to variable - result.
def convert(node, state = {}) | ||
" +\n" | ||
Coradoc::Generator.gen_adoc(to_coradoc(node, state)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to_coradoc
and convert
?
@@ -1,6 +1,9 @@ | |||
module ReverseAdoc | |||
module Converters | |||
class Drop < Base | |||
def to_coradoc(node, state = {}) | |||
convert(node, state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do?
content = treat_children(node, state).strip | ||
options = {} | ||
options[:id] = id if id | ||
options[:tdsinglepara] = true if state[:tdsinglepara] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what this is... let's delete it?
@@ -13,8 +13,18 @@ def convert(node, state = {}) | |||
node.at(".//p") && !singlepara | |||
style = "a" if adoccell | |||
delim = adoccell ? "\n" : " " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete all lines that are unused.
ReverseAdoc.cleaner.tidy(result) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need any cleaning after putting it into a Coradoc::Document
? The to_adoc results should be perfect.
end | ||
end | ||
def convert(node, state = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
@@ -36,7 +36,7 @@ | |||
|
|||
module ReverseAdoc | |||
class HtmlConverter | |||
def self.convert(input, options = {}) | |||
def self.to_coradoc(input, options = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [11/10]
expect(converter.convert(node)).to include "[[A]]\nvideo::example.mp3[options=\"loop\"]" | ||
it 'converts video with full set of attributes' do | ||
node = node_for("<video id='A' src='example.mp4' loop='loop'/>") | ||
expect(converter.convert(node)).to include "[[A]]\nvideo::example.mp4[options=\"loop\"]" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [92/80]
it 'converts audio with full set of attributes' do | ||
node = node_for("<audio id='A' src='example.mp3' loop='loop'/>") | ||
expect(converter.convert(node)).to include "[[A]]\nvideo::example.mp3[options=\"loop\"]" | ||
it 'converts video with full set of attributes' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Coradoc::Document::Inline::Image.new(id: id, | ||
title: title, src: src, alt: alt, width: width, height: height) | ||
end | ||
def convert(node, state = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
@@ -55,26 +55,25 @@ def copy_temp_file(imgdata) | |||
end | |||
end | |||
|
|||
def convert(node, state = {}) | |||
def to_coradoc(node, state = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method has too many lines. [12/10]
Unused method argument - state. If it's necessary, use _ or _state as an argument name to indicate that it won't be used.
@@ -7,6 +7,9 @@ | |||
module ReverseAdoc | |||
module Converters | |||
class Math < Base | |||
def to_coradoc(node, state = {}) #FIXIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
Do not place comments on the same line as the def keyword.
"#{content[/^\s*/]}\"#{content.strip}\"#{content[/\s*$/]}" | ||
Coradoc::Document::Inline::Quotation.new(content) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
"#{content[/^\s*/]}^#{content.strip}^#{content[/\s*$/]}" | ||
Coradoc::Document::Inline::Superscript.new(content) | ||
end | ||
def convert(node, state = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use empty lines between method definitions.
lib/reverse_adoc/converters/a.rb
Outdated
elsif href.to_s.start_with?('#') | ||
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_") | ||
if name.to_s.empty? | ||
Coradoc::Document::Inline::CrossReference.new(href) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A cross reference links an optional custom text to a target. The target can be an anchor in the document, or an anchor in a separate document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe combine this case with the next case into an initialize method that takes parameters.
anchor = id ? "[[#{id}]]\n" : "" | ||
content = treat_children(node, state)#.strip | ||
Coradoc::Document::Block.new(nil, lines: content.lines, type: :side) | ||
content = treat_children(node, state) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call “treat_children” just “parse” on the children?
content = treat_children(node, state).strip | ||
content = ReverseAdoc.cleaner.remove_newlines(content) | ||
Coradoc::Document::Block.new(nil, lines: content.lines, type: :quote, attributes: attrs) | ||
Coradoc::Document::Block::Quote.new(nil, lines: content, attributes: attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What’s the first nil argument? It looks weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's title, previous reverse_adoc code was inconsistent with regards to blocks, I will look into how exactly are different types of asciidoc blocks converted into html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there are actually 3 types of HTML source:
- Normal HTML
- Source generated by Metanorma
- Source: https://github.com/metanorma/mn-samples-iso
- HTML: https://metanorma.github.io/mn-samples-iso/
- Source generated by Word
- (@opoudjis what are the examples?)
@xyz65535 once you're done please help work on this: Thanks! |
attributes = Coradoc::Document::AttributeList.new | ||
options = options(node) | ||
attributes.add_named("options", options) if options.any? | ||
Coradoc::Document::Video.new(title, id: id, src: src, attributes: attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [85/80]
@@ -32,12 +32,16 @@ | |||
it { is_expected.to match /a \*strong with leading and trailing\* whitespace/ } | |||
it { is_expected.to match /a \*strong with extra leading and trailing\* whitespace/ } | |||
|
|||
it { is_expected.to match /H~2~O/ } | |||
it { is_expected.to match /A\^2\^B/ } | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blank line detected.
# it "still cleans up whitespaces that aren't inside a link" do | ||
# input = "now __italic __with following [under__scored](link)" | ||
# result = cleaner.clean_tag_borders(input) | ||
# expect(result).to eq "now __italic__with following [under__scored](link)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [83/80]
# it "still cleans up whitespaces that aren't inside a link" do | ||
# input = "now __italic __with following [under__scored](link)" | ||
# result = cleaner.clean_tag_borders(input) | ||
# expect(result).to eq "now __italic__ with following [under__scored](link)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [84/80]
@@ -19,6 +19,6 @@ | |||
it 'can deal with cite attribute' do | |||
input = node_for("<blockquote cite='http://www.example.com'><p>Some text.</p><p>Some more text.</p></blockquote>") | |||
result = converter.convert(input) | |||
expect(result).to eq "\n\n[quote, http://www.example.com]\n____\nSome text.\n\nSome more text.\n____\n\n" | |||
expect(result).to eq "\n\n[quote,http://www.example.com]\n____\nSome text.\n\nSome more text.\n____\n\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [108/80]
require "uri" | ||
|
||
module ReverseAdoc | ||
module Converters | ||
class A < Base | ||
def convert(node, state = {}) | ||
def to_coradoc(node, state ={}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for to_coradoc is too high. [<6, 22, 9> 24.52/15]
Cyclomatic complexity for to_coradoc is too high. [9/6]
Method has too many lines. [17/10]
Perceived complexity for to_coradoc is too high. [10/7]
Surrounding space missing in default value assignment.
anchor = id ? "[[#{id}]]\n" : "" | ||
content = treat_children(node, state).strip | ||
"\n\n****\n" << treat_children(node, state) << "\n****\n\n" | ||
Coradoc::Generator.gen_adoc(to_coradoc(node,state)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Space missing after comma.
attributes = Coradoc::Document::AttributeList.new | ||
options = options(node) | ||
attributes.add_named("options", options) if options.any? | ||
Coradoc::Document::Audio.new(title, id: id, src: src, attributes: attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [85/80]
autoplay = node['autoplay'] | ||
loop_attr = node['loop'] | ||
controls = node['controls'] | ||
def to_coradoc(node, state = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused method argument - state. If it's necessary, use _ or _state as an argument name to indicate that it won't be used.
|
||
before && after | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra empty line detected at class body end.
attributes.add_positional(width) if width | ||
attributes.add_positional(height) if height | ||
|
||
Coradoc::Document::Image::BlockImage.new(title, id, src, attributes: attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [88/80]
attributes = Coradoc::Document::AttributeList.new | ||
# attributes.add_named("id", id) if id | ||
if alt# && !alt.to_s.empty? | ||
attributes.add_positional(alt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.
[anchor, title, "image::", src, "[", attrs, "]"].join("") | ||
attributes = Coradoc::Document::AttributeList.new | ||
# attributes.add_named("id", id) if id | ||
if alt# && !alt.to_s.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a space before an end-of-line comment.
@@ -55,26 +55,35 @@ def copy_temp_file(imgdata) | |||
end | |||
end | |||
|
|||
def convert(node, state = {}) | |||
def to_coradoc(node, state = {}) | |||
id = node['id'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
@@ -55,26 +55,35 @@ def copy_temp_file(imgdata) | |||
end | |||
end | |||
|
|||
def convert(node, state = {}) | |||
def to_coradoc(node, state = {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for to_coradoc is too high. [<8, 15, 6> 18.03/15]
Cyclomatic complexity for to_coradoc is too high. [7/6]
Method has too many lines. [21/10]
Perceived complexity for to_coradoc is too high. [8/7]
Unused method argument - state. If it's necessary, use _ or _state as an argument name to indicate that it won't be used.
before = true | ||
end | ||
if !before | ||
before = true if node.to_s[0] =~ /\s/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider merging nested conditions into outer if conditions.
Use match? instead of =~ when MatchData is not used.
def constrained?(node) | ||
before = node.at_xpath("preceding::node()[1]").to_s[-1] | ||
if before | ||
before = (before =~ (/\s/)) ? true : false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Omit parentheses for ternary conditions.
|
||
def constrained?(node) | ||
before = node.at_xpath("preceding::node()[1]").to_s[-1] | ||
if before |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the return of the conditional for variable assignment and comparison.
|
||
#def trailing_whitespace?(node) | ||
|
||
def constrained?(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for constrained? is too high. [<8, 16, 11> 21/15]
Cyclomatic complexity for constrained? is too high. [10/6]
Method has too many lines. [19/10]
Perceived complexity for constrained? is too high. [12/7]
end | ||
end | ||
|
||
#def trailing_whitespace?(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
42d46b2
into
metanorma:xyz65535-coradoc-integration
* coradoc integration --------- Co-authored-by: Ronald Tse <[email protected]>
#84
Metanorma PR checklist