Spaces in image alt texts are not supported

未关闭 适合新手
#1,870 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
markdown, ruby
领域
documentation

调研方向

该问题位于 lib/rdoc/markup/formatter.rb 中的行内链接处理:add_regexp_handling_RDOCLINK 使用的模式会在空白处停止;另外也位于 lib/rdoc/markup/to_html.rb 中图片分支对 URL 与替代文本的拆分逻辑。先复现 issue 中的 Ruby 代码片段,查看 img 输出中替代文本被截断的情况。当 ![Alt text](path/to/image.png) 生成值为 "Alt text" 的 alt 属性,并且有测试覆盖该情况时,即为完成。

由索引模型根据 Issue 内容生成。

描述

The documentation references the following example

![Alt text](path/to/image.png)

but

formatter = RDoc::Markup::ToHtml.new(RDoc::Options.new, nil)
RDoc::Markdown.parse("![Alt text](path/to/image.png)").accept(formatter)

produces "\n<p><img src=\"path/to/image.png\" alt=\"Alt\"> text</p>\n" - notice the "text" is not part of the alt attribute.

I think the problem is that markdown.rb correctly supports spaces in the internal representation as "rdoc-image:#{a[:link]}:#{a[:label]}" but formatter.rb specifically excludes spaces in

      def add_regexp_handling_RDOCLINK
        @markup.add_regexp_handling(/rdoc-[a-z]+:[^\s\]]+/, :RDOCLINK)
      end

So given rdoc-image:image.svg:Alt Text only rdoc-image:image.svg:Alt is matched and Text becomes ordinary paragraph text.

Maybe using a regex similar to the one in to_html.rb url, alt = $'.split(/:(?!\/)/, 2) would be a solution?

主要语言
Ruby
星标
928
派生
471
平均合并
2 天 4 分钟
30 天内合并 PR
13

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ruby/rdoc 的其他 Issue

查看 ruby/rdoc 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。