Skip to content

[Draft] Improving trix field #3609

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

Conversation

PedroAugustoRamalhoDuarte
Copy link
Contributor

Description

Fixes #2715

This PR enhances the Trix Avo field by leveraging Rails' rich_text_tag. Previously, Avo relied on its own attachment strategy, but in this PR, I refactored it to use Rails' direct upload solution, making it possible to edit and add attachments while creating a record.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

Manual review steps

  1. Step 1
  2. Step 2

Manual reviewer: please leave a comment with output from the test if that's the case.

@github-actions github-actions bot added the Fix label Jan 25, 2025
Copy link

codeclimate bot commented Jan 25, 2025

Code Climate has analyzed commit 9c2d284 and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Contributor

This PR has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Feb 23, 2025
@Paul-Bob Paul-Bob removed the Stale label Feb 24, 2025
Copy link
Contributor

This PR has been marked as stale because there was no activity for the past 15 days.

@github-actions github-actions bot added the Stale label Mar 12, 2025
Copy link
Contributor

Closing this because there was no activity for the past 15 days. Feel free to reopen if new information pops up ✌️

@github-actions github-actions bot closed this Mar 27, 2025
@PedroAugustoRamalhoDuarte
Copy link
Contributor Author

Hey @Paul-Bob,

I don’t have time to finish this PR right now, so I’ll close it for now. The main issue I encountered was that PDFs were not appearing in the body when rendered as HTML—they showed as "file not found" inside the preview.

To solve this, I made changes inside the serializer to ensure the frontend receives the correct HTML. Here’s the updated method:

def content
  # rubocop:disable Style/SafeNavigationChainLength
  content = object.content&.to_s&.gsub("&lt;iframe", "<iframe")&.gsub("&gt;&lt;/iframe&gt;", "></iframe>")
  # rubocop:enable Style/SafeNavigationChainLength

  matches = content&.scan(%r{<action-text-attachment([^>]*)>([\s\S]*?)</action-text-attachment>})

  matches&.each do |match|
    type = match[0].match(/content-type="(.*?)"/)[1]
    if type.include? "image/"
      content = content.sub(
        %r{<action-text-attachment([^>]*)>([\s\S]*?)</action-text-attachment>},
        match[1],
      )
      next
    end

    href = match[0].match(/href="(.*?)"/)[1]
    filename = match[0].match(/filename="(.*?)"/)[1]

    content = content.sub(
      %r{<action-text-attachment([^>]*)>([\s\S]*?)</action-text-attachment>},
      "<a href=\"#{href}\" download=\"#{filename}\">#{filename}</a>",
    )
  end

  content
rescue => e
  Sentry.capture_exception(e)
  "Não foi possível carregar o conteúdo da sua publicação"
end

@Paul-Bob
Copy link
Contributor

Hi @PedroAugustoRamalhoDuarte

Is it working for you now?

I haven’t been able to reproduce the issue on my end, and I haven’t had a chance to get hands-on with this PR yet.

If there’s a straightforward way to reproduce it, let me know

Thanks for sharing your solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve trix and action text support
2 participants