Skip to content
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

Merged

Conversation

xyz65535
Copy link
Contributor

@xyz65535 xyz65535 commented Apr 17, 2024

#84

Metanorma PR checklist

@@ -1,12 +1,36 @@
module ReverseAdoc
module Converters
class Ol < Base
def convert(node, state = {})
def to_coradoc(node, state = {}) #FIXIT
Copy link

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 = {})
Copy link

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)
Copy link

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.

lib/reverse_adoc/converters/aside.rb Outdated Show resolved Hide resolved
lib/reverse_adoc/converters/blockquote.rb Outdated Show resolved Hide resolved
lib/reverse_adoc/converters/blockquote.rb Outdated Show resolved Hide resolved
def convert(node, state = {})
" +\n"
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
Copy link
Contributor

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)
Copy link
Contributor

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]
Copy link
Contributor

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?

lib/reverse_adoc/converters/pre.rb Outdated Show resolved Hide resolved
lib/reverse_adoc/converters/table.rb Outdated Show resolved Hide resolved
@@ -13,8 +13,18 @@ def convert(node, state = {})
node.at(".//p") && !singlepara
style = "a" if adoccell
delim = adoccell ? "\n" : " "
Copy link
Contributor

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.

Comment on lines +55 to +56
ReverseAdoc.cleaner.tidy(result)
end
Copy link
Contributor

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 = {})
Copy link

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

Copy link

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 = {})
Copy link

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\"]"
Copy link

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
Copy link

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 = {})
Copy link

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 = {})
Copy link

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
Copy link

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

Copy link

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 = {})
Copy link

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.

elsif href.to_s.start_with?('#')
href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
if name.to_s.empty?
Coradoc::Document::Inline::CrossReference.new(href)
Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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:

  1. Normal HTML
  2. Source generated by Metanorma
  1. Source generated by Word

@ronaldtse
Copy link
Contributor

@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)
Copy link

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/ }

Copy link

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)"
Copy link

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)"
Copy link

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"
Copy link

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 ={})
Copy link

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))
Copy link

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)
Copy link

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 = {})
Copy link

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

Copy link

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.

@ronaldtse ronaldtse changed the base branch from main to xyz65535-coradoc-integration April 26, 2024 10:16
attributes.add_positional(width) if width
attributes.add_positional(height) if height

Coradoc::Document::Image::BlockImage.new(title, id, src, attributes: attributes)
Copy link

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)
Copy link

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?
Copy link

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']
Copy link

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 = {})
Copy link

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/
Copy link

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
Copy link

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
Copy link

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)
Copy link

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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after #.

@ronaldtse ronaldtse merged commit 42d46b2 into metanorma:xyz65535-coradoc-integration Apr 26, 2024
2 of 6 checks passed
ronaldtse added a commit that referenced this pull request Apr 26, 2024
* coradoc integration

---------

Co-authored-by: Ronald Tse <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants