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

no new line char in code inside <pre> tag #77

Open
shivabhusal opened this issue Oct 2, 2019 · 1 comment
Open

no new line char in code inside <pre> tag #77

shivabhusal opened this issue Oct 2, 2019 · 1 comment

Comments

@shivabhusal
Copy link
Contributor

shivabhusal commented Oct 2, 2019

Input

<p>I ran into a weird situation today. Active Record objects stored in vars are removed when I switched from one tenant
    to another on the fly. This will create a weird test-failing scenario and you never know why its happening.</p>
<pre>
  def switch(name)
    yield(name)
  end
  
  @customers = [1,2,3]
  switch('shiva') do |name|
    puts name
    puts @customers
  end
  
  # Gives output
  # shiva
  # 1
  # 2
  # 3
</pre>

<p>&nbsp;</p>
<p>but when I do this</p>

<pre>
  @roles     = Role.all
  @customers = org.branches
  @list      = [1, 2]
  
  puts 'Role count' + @roles.count.to_s
  puts 'Customer count' + @customers.count.to_s
  puts 'list count' + @list.count.to_s
  
  Apartment::Tenant.switch!(org.database_name)
  puts '-------'
  puts 'Role count' + @roles.count.to_s
  puts 'Customer count' + @customers.count.to_s
  puts 'list count' + @list.count.to_s
</pre>

<p>output is</p>

<pre>
  Role count2
  Customer count2
  list count2
  -------
  Role count0
  Customer count0
  list count2
</pre>

<p>&nbsp;</p>
<h2>Reason</h2>

<pre>
  # apartment-2.2.0/lib/apartment/adapters/abstract_adapter.rb
  #   Switch to a new tenant
  #
  #   @param {String} tenant name
  #
  def switch!(tenant = nil)
    run_callbacks :switch do
      return reset if tenant.nil?
  
      connect_to_new(tenant).tap do
        <strong>Apartment.connection.clear_query_cache</strong>
      end
    end
  end
</pre>

is rendered into

I ran into a weird situation today. Active Record objects stored in vars are removed when I switched from one tenant to another on the fly. This will create a weird test-failing scenario and you never know why its happening.

    def switch(name) yield(name) end @customers = [1,2,3] switch('shiva') do |name| puts name puts @customers end # Gives output # shiva # 1 # 2 # 3

&nbsp;

but when I do this

    @roles = Role.all @customers = org.branches @list = [1, 2] puts 'Role count' + @roles.count.to\_s puts 'Customer count' + @customers.count.to\_s puts 'list count' + @list.count.to\_s Apartment::Tenant.switch!(org.database\_name) puts '-------' puts 'Role count' + @roles.count.to\_s puts 'Customer count' + @customers.count.to\_s puts 'list count' + @list.count.to\_s

output is

    Role count2 Customer count2 list count2 ------- Role count0 Customer count0 list count2

&nbsp;

## Reason

    # apartment-2.2.0/lib/apartment/adapters/abstract\_adapter.rb # Switch to a new tenant # # @param {String} tenant name # def switch!(tenant = nil) run\_callbacks :switch do return reset if tenant.nil? connect\_to\_new(tenant).tap do **Apartment.connection.clear\_query\_cache** end end end


Expected

It should have rendered newline chars \n inside <pre> tag where there is no <code> tag inside.
The HTML is extracted from by blog at https://cbabhusal.wordpress.com . Wordpress does not put <code> tag inside <pre> tag.

Code

ReverseMarkdown.convert(post['content'])
@shivabhusal
Copy link
Contributor Author

shivabhusal commented Oct 2, 2019

require 'spec_helper'

describe ReverseMarkdown::Converters::Pre do
  let(:converter) { ReverseMarkdown::Converters::Pre.new }

    it 'preserves new lines as <br> and \n' do
      node = node_for("<pre>one\ntwo\nthree<br>four</pre>")
      expect(converter.convert(node)).to include "\n\n    one\n    two\n    three\n    four\n\n"
    end
end

Run

 rspec spec/lib/reverse_markdown/converters/pre_spec.rb
..F.......

Failures:

  1) ReverseMarkdown::Converters::Pre for standard markdown preserves new lines as <br> and \n
     Failure/Error: expect(converter.convert(node)).to include "\n\n    one\n    two\n    three\n    four\n\n"
     
       expected "\n\n    one two three\n    four\n\n" to include "\n\n    one\n    two\n    three\n    four\n\n"
       Diff:
       @@ -1,2 +1,5 @@
       -\n\n    one\n    two\n    three\n    four\n\n
       +
       +
       +    one two three
       +    four
       
     # ./spec/lib/reverse_markdown/converters/pre_spec.rb:22:in `block (3 levels) in <top (required)>'

Finished in 0.0264 seconds (files took 0.31485 seconds to load)
10 examples, 1 failure

shivabhusal added a commit to shivabhusal/reverse_markdown that referenced this issue Oct 2, 2019
shivabhusal added a commit to shivabhusal/reverse_markdown that referenced this issue Oct 2, 2019
shivabhusal added a commit to shivabhusal/reverse_markdown that referenced this issue Oct 2, 2019
shivabhusal added a commit to shivabhusal/reverse_markdown that referenced this issue Oct 2, 2019
xijo added a commit that referenced this issue Oct 31, 2021
Lets \n to be present in <pre> tag. solves #77
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

No branches or pull requests

1 participant