Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use Escape Utils?#191

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
korny wants to merge8 commits intomaster
base:master
Choose a base branch
Loading
fromescape-utils
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletionscoderay.gemspec
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,6 +29,8 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
s.require_paths = ['lib']

s.add_dependency "escape_utils", "~> 1.2"

s.rubyforge_project = s.name
s.rdoc_options = '-SNw2', "-m#{readme_file}", '-t CodeRay Documentation'
s.extra_rdoc_files = readme_file
Expand Down
27 changes: 9 additions & 18 deletionslib/coderay/encoders/html.rb
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
require 'set'
require 'escape_utils'

module CodeRay
module Encoders
Expand DownExpand Up@@ -127,22 +128,6 @@ class HTML < Encoder

protected

def self.make_html_escape_hash
{
'&' => '&amp;',
'"' => '&quot;',
'>' => '&gt;',
'<' => '&lt;',
# "\t" => will be set to ' ' * options[:tab_width] during setup
}.tap do |hash|
# Escape ASCII control codes except \x9 == \t and \xA == \n.
(Array(0x00..0x8) + Array(0xB..0x1F)).each { |invalid| hash[invalid.chr] = ' ' }
end
end

HTML_ESCAPE = make_html_escape_hash
HTML_ESCAPE_PATTERN = /[\t"&><\0-\x8\xB-\x1F]/

TOKEN_KIND_TO_INFO = Hash.new do |h, kind|
h[kind] = kind.to_s.gsub(/_/, ' ').gsub(/\b\w/) { $&.capitalize }
end
Expand DownExpand Up@@ -181,7 +166,7 @@ def setup options

@break_lines = (options[:break_lines] == true)

@HTML_ESCAPE =HTML_ESCAPE.merge("\t" =>options[:tab_width] ? ' ' * options[:tab_width] : "\t")
@expand_tab = options[:tab_width] ? ' ' * options[:tab_width] : "\t"

@opened = []
@last_opened = nil
Expand DownExpand Up@@ -221,7 +206,13 @@ def finish options
def text_token text, kind
style = @span_for_kinds[@last_opened ? [kind, *@opened] : kind]

text = text.gsub(/#{HTML_ESCAPE_PATTERN}/o) { |m| @HTML_ESCAPE[m] } if text =~ /#{HTML_ESCAPE_PATTERN}/o
text = EscapeUtils.escape_html(text)
if text.index(/[\0-\t\xB-\x1F]/)
# Escape ASCII control codes except \x9 == \t and \xA == \n.
text.tr!("\0-\x8\xB-\x1F", ' ') if text.index(/[\0-\x8\xB-\x1F]/)
text.gsub!("\t", @expand_tab) if text.index("\t")
end

text = break_lines(text, style) if @break_lines && (style || @opened.size > 0) && text.index("\n")

if style
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp