Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

REXML::Formatters::Transitive not found.

未關閉
#228 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

  • #230 來自 @Beagle123 —— 已關閉,未合併

評估

難度
4/5
預估耗時
3-5 天
新手友好度
25/100
Issue 類型
功能
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
ruby
領域
backend

研究方向

先閱讀 Transitive.rb 和 Pretty.rb,比較可用 formatter 的行為以及文字節點的處理方式。檢查 REXML 如何提供 formatter,接著判斷保留長文字節點時的預期行為,並透過針對性的涵蓋範圍加以確認,再考慮將該 issue 視為完成。

由索引模型根據 Issue 內容生成。

描述

Hi:

I tried to use REXML::Formatters::Transitive in my code, but it wasn't found in the package.

Here is the output of irb:

eric@trig:~$ irb
irb(main):001:0> require "rexml"
=> true
irb(main):002:0> REXML::Formatters::Transitive
(irb):2:in `<main>': uninitialized constant REXML::Formatters::Transitive (NameError)
        from /home/eric/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/irb-1.4.1/exe/irb:11:in `<top (required)>'                                                                                                       
        from /home/eric/.rbenv/versions/3.1.6/bin/irb:25:in `load'                                        
        from /home/eric/.rbenv/versions/3.1.6/bin/irb:25:in `<main>'                                      
irb(main):003:0> 
^C                                                                                                        
irb(main):003:0> 

I tried using the code from github, Transitive.rb, but the output was bad. All the tags were broken onto two lines.

However, I had great success with subclassing Pretty.rb, and outputting the text nodes without formatting which is the result that I wanted. I would suggest making this Formatter:

class PrettyPreserveText < REXML::Formatters::Pretty
  def write_text( node, output )
    output << node.to_s()
  end
end

This is a great result. It has all the benefits of Pretty.rb while preserving long text nodes. It seems like a good idea to preserve text nodes "as-is." In fact, I would suggest changing the Pretty formater to output the unaltered text. When I used Pretty, it worked great except that it would indent every line of a long text string to make it look good. This obviously is rarely a good idea. The users need to be able to control the content of text strings. That's not the job of a formatter.

Thanks for all your work.

Eric

主要語言
Ruby
星號
181
分支
105
平均合併
8 天 16 小時
30 天內合併 PR
2

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

ruby/rexml 的其他 Issue

查看 ruby/rexml 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。