hitomalu_formatter 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 466cef2256b10fed9188c4852ba797d11949ea629d8b368f3c253cce0eb0cd6b
4
- data.tar.gz: f85b00ad233739445c5a8ff3fdb7f21c07cb3aca6d42d29ce3513d86048258e6
3
+ metadata.gz: '04239c9c7d366f97db31ee7a67a15936ad16fe3900d0816b32409b9b6d944dec'
4
+ data.tar.gz: 6a26df5123e66d197952a98c30e1179a2d2c9c5620d07d1c5916aaddda9afd50
5
5
  SHA512:
6
- metadata.gz: aa0e0784adb8646ef44e1a20b22478f3ba892ce9fb459d9e827d9af58594b54bd628e8fb410950166e7252e473b45b0fc34d9f3e906b413f782cc709fba99b7b
7
- data.tar.gz: ce6488768829e93fc71c72b6cc1cbefd597c90c7116a382cb9d490a52d7b89e634495b209aa08ef6fac4e71c27563c0f6caa79bfb3ffd48bb2faca06a2875dd2
6
+ metadata.gz: b2999cc3946c94771090f582c649359fac349209fe5aa953173767f9ab1235ec366c4b5dcb6c8d6432411527694970aae15663a749a8358c5f8e90d4a9a57e2b
7
+ data.tar.gz: bc946c6f1cea4481ca105cd42dc6cef6993baaa64d76e1b58e9a9644fb5f1a9effb1dbf40a527a11f5c9f386f427e5bde117523b57ce2006ec96dcd30be531d7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,6 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.3] - 2022-08-04
3
4
  ## [0.1.2] - 2022-08-03
4
5
 
5
6
  - a little fix
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hitomalu_formatter (0.1.2)
4
+ hitomalu_formatter (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -8,6 +8,7 @@ module Hitomalu
8
8
  # rp と rt は上に記載がないが、改行させたくないので追加
9
9
  # node.name が 'comment' であるコメントノードもインライン扱い
10
10
  INLINE_TAGS = [ 'a', 'abbr', 'acronym', 'audio', 'b', 'bdi', 'bdo', 'big', 'br', 'button', 'canvas', 'cite', 'code', 'comment', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'map', 'mark', 'meter', 'noscript', 'object', 'output', 'picture', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'select', 'slot', 'small', 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'tt', 'var', 'video', 'wbr' ]
11
+ INLINE_TAGS_REGEXP = INLINE_TAGS.join('|')
11
12
 
12
13
  def self.format(html)
13
14
  # 改行コード \n を \r\n に統一しておく
@@ -73,11 +74,11 @@ module Hitomalu
73
74
  body_str = body.to_s.gsub(/(\|mykaigyo\|)+/, "\r\n").gsub('|myspace|', ' ').gsub(/(<\/wbr>|\|mykaramojiretsu\||\A<body>(\n|\r\n)*|(\n|\r\n)*<\/body>\Z)/, "").gsub(/(?<!\r)\n/, "\r\n")
74
75
 
75
76
  # </span></div> のような閉じタグの間に改行が無かったら改行を入れる (Nokogiri の add_next_sibling は 20000回するとメモリを6GB以上使うので文字列処理でやる)
76
- # ただし、</ruby>の前には入れない(</rp>などの短いインライン要素が来るため)
77
+ # ただし、片方または両方がインライン要素の閉じタグだったら入れない
77
78
  prev_str = ""
78
79
  while body_str != prev_str do
79
80
  prev_str = body_str
80
- body_str = body_str.gsub(/(<\/[a-z]+>)(<\/(?!ruby))/, "\\1\r\n\\2")
81
+ body_str = body_str.gsub(/(<\/(?!(#{INLINE_TAGS_REGEXP}))[a-z]+>)(<\/(?!(#{INLINE_TAGS_REGEXP}))[a-z]+>)/, "\\1\r\n\\3")
81
82
  end
82
83
 
83
84
  # 開始タグの前に改行がなければ改行を入れる (add_prev_sibling は重いので文字列処理でやる) (文章の先頭からは消す)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HitomaluFormatter
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hitomalu_formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - t-hazawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-03 00:00:00.000000000 Z
11
+ date: 2022-08-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: []