HTML tag and attribute matcher (#15091)
* HTML tag and attribute matcher This regex was designed for the following matches. It should ignore plain text <tag> </tag> <hr/> <div class="signout_confirm-wrapper"> " target="_blank" rel="noopener me" class="profile-header__meta__item p-1"> class="crayons-layout crayons-layout--limited-l crayons-layout--2-cols crayons-layout--2-cols--1-2 pt-4 m:pt-0" href="javascript:void(0);" id="asdf" class="sas" data-profile-user-id="asdf">sads</s> data-tag="" * added rails sanitizer * removed swap file * Update bin/untranslated_erb Co-authored-by: Michael Kohl <me@citizen428.net> * revert gitignore Co-authored-by: Michael Kohl <me@citizen428.net>
This commit is contained in:
parent
4cb48768f9
commit
6a8fcf6f33
1 changed files with 16 additions and 12 deletions
|
|
@ -1,7 +1,9 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'rails-html-sanitizer'
|
||||
|
||||
class I18nExtractor
|
||||
ERB_TAG = /<%(.*?)%>/
|
||||
HTML_TAG = /<(.*?)>/
|
||||
HTML_TAG = /<[^>]*>|<\/[^>]*>|[^>]*\/>|\".+">|">|<\w+(.+|)|.+="(.+)|"/
|
||||
SEPERATOR = '_@@@_'
|
||||
SKIP_TAGS = [[/<script/i,/<\/script>/i],[/<%/,/%>/],[/<style/i,/\/style>/i]]
|
||||
|
||||
|
|
@ -12,23 +14,25 @@ class I18nExtractor
|
|||
end
|
||||
|
||||
def extract
|
||||
File.open(@filename).each_with_index do |line,i|
|
||||
sanitizer = Rails::Html::FullSanitizer.new
|
||||
i = 0
|
||||
File.foreach(@filename) do |line|
|
||||
i += 1
|
||||
next if in_script_block?(line)
|
||||
text = line.gsub(ERB_TAG, SEPERATOR).gsub(HTML_TAG,SEPERATOR).strip
|
||||
arr = text.split SEPERATOR
|
||||
arr.each do |e|
|
||||
if e.strip.size > 1
|
||||
unless @files_with_results.include?(@filename)
|
||||
@files_with_results << @filename
|
||||
printf "\n\n\e[4m#{@filename}\e[00m\n\n"
|
||||
end
|
||||
printf("%3s:%s\n",i+1,e.strip)
|
||||
striped_line = sanitizer.sanitize(line).chomp.strip.gsub(HTML_TAG, '')
|
||||
next if striped_line.empty?
|
||||
if striped_line.length > 1
|
||||
unless @files_with_results.include?(@filename)
|
||||
@files_with_results << @filename
|
||||
printf "\n\n\e[4m#{@filename}\e[00m\n"
|
||||
end
|
||||
printf("%3s:%s\n",i+1,striped_line)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
private
|
||||
|
||||
def in_script_block?(s)
|
||||
return true if s.nil? || s.strip.size == 0
|
||||
jump_in_tag = SKIP_TAGS.find{ |start_tag,end_tag| s =~ start_tag}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue