github / github/markup

Revisiting Color in Markup

オープン
#2,054 コメント 8 件 リアクション 8 件 担当者 0 名 GitHub で見る
主要言語
Ruby
スター
6k
フォーク
3.4k
PR マージ指標
30日以内にマージされた PR はありません

説明

> Changes to the sanitize (step 2):
>
> ```
> color_transformer = lambda do |env|
> node = env[:node]
>
> # Only process element nodes with a style attribute
> return unless node.type == Nokogiri::XML::Node::ELEMENT_NODE
> return unless node['style']
>
> # Parse each declaration
> allowed_declarations = node['style'].split(';').filter_map do |declaration|
> property, value = declaration.split(':').map(&:strip)
> next unless property == 'color'
>
> # Allow only:
> # - Named colors: red, blue, darkslategray, etc. OR NOT?
> # - Hex colors: #fff, #ff6600
> # - RGB: rgb(0, 128, 255)
> # - HSL: hsl(120, 100%, 50%)
> valid_color = value.match?(
> /\A(
> \#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}) | # hex
> rgb\(\s*\d{1,3}\s*,\s*\d{1,3}\s*,\s*\d{1,3}\s*\) | # rgb()
> hsl\(\s*\d{1,3}\s*,\s*\d{1,3}%\s*,\s*\d{1,3}%\s*\) | # hsl()
> [a-zA-Z]{2,50} # named color
> )\z/x
> )
>
> "color: #{value}" if valid_color
> end
>
> if allowed_declarations&.any?
> node['style'] = allowed_declarations.join('; ')
> else
> node.remove_attribute('style')
> end
> end
>
> ```
>
> --- THEN ADD THIS TO THE SANITIZE CONFIG ---
>
> ```
> config = {
> elements: ['p', 'span', 'em', 'strong'],
> attributes: {
> :all => ['style']
> },
> css: {
> properties: ['color']
> },
> transformers: [color_transformer]
> }
>
> Sanitize.fragment(html, config)
> ```

_Originally posted by @perlygatekeeper in [#1440](https://github.com/github/markup/issues/1440#issuecomment-4314431057)_

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

対象ファイルやテストは指定されていません。まず、sanitize 設定とマークアップのレンダリングパスを特定し、次に提案されている color_transformer と CSS 設定を既存の動作と比較してください。サポートされている色の宣言が保持され、それ以外のスタイル内容が削除され、結果のフラグメントを対象とするテストがあることが完了の条件です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
ruby
領域
content, frontend
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
52/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。