nx-auto-link 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1a35dab4ab807fe9655750107a0f3f62332a71e455109a5cc89cd2c7b7a9e29
4
- data.tar.gz: e8a9cf02e775d545959fd6c5bfba30f40899bb586994ebdda937cbe780311c56
3
+ metadata.gz: d0b8099543ae186654c0f25c40cf786d2a4abe336f13b0f21e3bb74cc1310558
4
+ data.tar.gz: 06dc49d102579db04e5f44955b750415d89b8bff9751ec89c1e9ab79f55e9235
5
5
  SHA512:
6
- metadata.gz: a5d21cecac8f3822b0f03180b0674358ca6f10fceebb966ea5667068c1ba5268931893a11e2fef3088cb2e894861536cc33b116fdb46bbb7558964b5905e3f62
7
- data.tar.gz: 111d8d87346207e4bbac288f1a8488776f4220adbac6b7a710f631c0540024abe8203a321a87c22bf7940dbba5ad81bd359a1dab49b331b3af40cb6946c4e653
6
+ metadata.gz: b9c1d2e3a2201f8d1b32d0aef367ee7c23f337d9acf275967fe7d25ba43ba105213131239e5550401e43fc3bcd8dedc96169a98d42cf0d6fc4e9053645d62b25
7
+ data.tar.gz: bb1a19364f9b57558eed29935fb90b4630bc84e36420b3929b937c73fcfd0fb1ed692f6806f629f8d73e2c0eb7d30609663e9a3b7ad4805b316963be4428b11a
data/README.md CHANGED
@@ -11,8 +11,6 @@ gem 'nx-auto-link', git: 'git@github.com:afeiship/nx-auto-link.git'
11
11
 
12
12
  ## usage
13
13
  ```rb
14
- Nx::AutoLink::start(html, tags)
15
-
16
14
  html = '<article class="jsw-content">
17
15
  <p>
18
16
  首先要先下载安装包或者建议:
@@ -27,6 +25,21 @@ tags = [
27
25
  { name: "建议", url: "http://www.baidu.com/tag/1.html" },
28
26
  { name: "python", url: "http://www.baidu.com/tag/5.html" },
29
27
  ];
28
+
29
+ result = Nx::AutoLink::start(html, tags)
30
+ puts result
31
+ ```
32
+ > output:
33
+ ```html
34
+ <article class="jsw-content">
35
+ <p>
36
+ 首先要先<a role="tag" title="下载" href="http://www.baidu.com/tag/2.html">下载</a>安装包或者<a role="tag" title="建议" href="http://www.baidu.com/tag/1.html">建议</a>:
37
+ </p>
38
+ <p>
39
+ ①win7,win8,win10系统,建议下载<a role="tag" title="python" href="http://www.baidu.com/tag/5.html">python</a>3.7.4版本:
40
+ </p>
41
+ </article>
42
+
30
43
  ```
31
44
 
32
45
  ## build/publish
data/lib/nx/auto-link.rb CHANGED
@@ -13,16 +13,16 @@ module Nx
13
13
  # ]
14
14
 
15
15
  paragraphs.each do |item|
16
- processed_html = item.content
16
+ processed_html = item.inner_html
17
17
  tags.reject { |tag| tag[:processed] }.each do |tag|
18
18
  tag_name = tag[:name]
19
19
  tag_url = tag[:url]
20
- if item.content.include?(tag_name)
20
+ if item.inner_html.include?(tag_name)
21
21
  tag[:processed] = true
22
- processed_html = processed_html.sub(
23
- tag_name,
24
- "<a role=\"tag\" title=\"#{tag_name}\" href=\"#{tag_url}\">#{tag_name}</a>"
25
- )
22
+ tag_str = "<a role=\"tag\" title=\"#{tag_name}\" href=\"#{tag_url}\">#{tag_name}</a>"
23
+ unless processed_html.include?(tag_str)
24
+ processed_html = processed_html.sub(tag_name, tag_str)
25
+ end
26
26
  end
27
27
  end
28
28
  item.inner_html = processed_html
data/lib/nx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nx
2
2
  class AutoLink
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nx-auto-link
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - afeiship
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-03 00:00:00.000000000 Z
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri