txt2tags 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/txt2tags.rb +45 -52
- data/lib/txt2tags/html5.rb +3 -1
- data/lib/txt2tags/null.rb +4 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a85a49a06442ffef7acdb141f72c3d7b8c79108a
|
4
|
+
data.tar.gz: 5ee6fc7dceff109e6f35cc1fdec4ae25cfcdb491
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26edd9068601e6931db3d80d2fe6b31399cef94ea9cd13fa0e2b5caba4c1ef15fcd1917cc0a99a09a2dbaa51eaed9db590293d64db8a382ab106250a80e6b2c4
|
7
|
+
data.tar.gz: ea1149f4520d5202a686423cd2705bf6f675b89a7bc277e39a0fe24e8c4a2866cb14c497c6db6d2b84be0b462d6bfbe1db263ad0eb0447caf306fae37cac7be4
|
data/lib/txt2tags.rb
CHANGED
@@ -10,9 +10,11 @@ class Txt2Tags
|
|
10
10
|
BEAUTIFIERS = {
|
11
11
|
monospace: Regexp.new('``(.*?)``'),
|
12
12
|
bold: Regexp.new('\*\*(.*?)\*\*'),
|
13
|
-
italic: Regexp.new('//(
|
13
|
+
italic: Regexp.new('//([^\]\[]*?)//'),
|
14
14
|
underline: Regexp.new('__(.*?)__'),
|
15
|
-
strike: Regexp.new('--(.*?)--')
|
15
|
+
strike: Regexp.new('--(.*?)--'),
|
16
|
+
link: Regexp.new('\[([^\]\[]*?)\s+([^\s\[\]]*?)\]'),
|
17
|
+
image: Regexp.new('\[([^\s\]\[]*?)\]')
|
16
18
|
}.freeze
|
17
19
|
|
18
20
|
# Only one linners transformations
|
@@ -64,67 +66,44 @@ class Txt2Tags
|
|
64
66
|
block = nil
|
65
67
|
ignore_line = false
|
66
68
|
|
67
|
-
|
68
|
-
|
69
|
-
begin
|
70
|
-
@input.rewind
|
71
|
-
rescue Errno::ESPIPE
|
72
|
-
end
|
69
|
+
# We can this multiples times
|
70
|
+
@input.rewind if @input.eof?
|
73
71
|
|
72
|
+
Enumerator.new do |y|
|
74
73
|
# Comments are discarded (lines beginnig with %)
|
75
74
|
@input.readlines.reject { |l| l.start_with?('%') }.each do |line|
|
76
75
|
# right space are discarded (line terminators, tabs and spaces)
|
77
76
|
line.rstrip!
|
78
77
|
|
79
|
-
|
80
|
-
if !block.nil?
|
81
|
-
# We find the end of a block?
|
82
|
-
if BLOCKS[block][:end_re].match line
|
83
|
-
# Send the end mark for this format
|
84
|
-
y.yield format::BLOCKS[block][:end]
|
85
|
-
|
86
|
-
# We can ignore the actual line?
|
87
|
-
if BLOCKS[block][:ignore_match_line]
|
88
|
-
block = nil
|
89
|
-
next
|
90
|
-
end
|
91
|
-
end
|
92
|
-
else
|
78
|
+
if block.nil?
|
93
79
|
# Searching for a new block...
|
94
|
-
BLOCKS.
|
95
|
-
|
96
|
-
|
80
|
+
block = BLOCKS.find { |b| b[1][:begin_re].match line }
|
81
|
+
|
82
|
+
# The begin of a block!
|
83
|
+
unless block.nil?
|
84
|
+
block = block[0]
|
97
85
|
|
98
|
-
# Yes!
|
99
|
-
block = m
|
100
86
|
# We can ignore the actual line?
|
101
87
|
ignore_line = BLOCKS[block][:ignore_match_line]
|
102
88
|
|
103
89
|
# Send the begin mark for this format
|
104
90
|
y.yield format::BLOCKS[block][:begin]
|
105
|
-
|
106
|
-
# We already figured out what to do, we do not have to keep looking
|
107
|
-
break
|
108
91
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
line.strip! if !block.nil? && BLOCKS[block][:strip]
|
120
|
-
|
121
|
-
# an apply the BEAUTIFIERS and TITLES transformations?
|
122
|
-
if block.nil? || (!block.nil? && BLOCKS[block][:apply_inline])
|
123
|
-
apply_marks!(format, line)
|
92
|
+
elsif BLOCKS[block][:end_re].match line
|
93
|
+
# We find the end of a block!
|
94
|
+
# Send the end mark for this format
|
95
|
+
y.yield format::BLOCKS[block][:end]
|
96
|
+
|
97
|
+
# We can ignore the actual line?
|
98
|
+
if BLOCKS[block][:ignore_match_line]
|
99
|
+
block = nil
|
100
|
+
next
|
101
|
+
end
|
124
102
|
end
|
125
103
|
|
126
104
|
# More on line!
|
127
|
-
y.yield line
|
105
|
+
y.yield process_line(line, block, format) unless ignore_line
|
106
|
+
ignore_line = false if ignore_line
|
128
107
|
end
|
129
108
|
|
130
109
|
# There are a close block pending?
|
@@ -132,14 +111,28 @@ class Txt2Tags
|
|
132
111
|
end
|
133
112
|
end
|
134
113
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
114
|
+
def process_line(line, block, format)
|
115
|
+
# We can strip spaces from the begin of this line?
|
116
|
+
processed = line
|
117
|
+
processed.strip! if !block.nil? && BLOCKS[block][:strip]
|
118
|
+
|
119
|
+
apply(processed, block, format)
|
120
|
+
end
|
121
|
+
|
122
|
+
def apply(line, block, format)
|
123
|
+
processed = line
|
124
|
+
|
125
|
+
# an apply the BEAUTIFIERS and TITLES transformations?
|
126
|
+
if block.nil? || (!block.nil? && BLOCKS[block][:apply_inline])
|
127
|
+
[:BEAUTIFIERS, :TITLES].each do |type|
|
128
|
+
type_array = Txt2Tags.const_get(type)
|
129
|
+
type_array.keys.each do |rule|
|
130
|
+
processed.gsub!(type_array[rule], format.const_get(type)[rule])
|
131
|
+
end
|
141
132
|
end
|
142
133
|
end
|
134
|
+
|
135
|
+
processed
|
143
136
|
end
|
144
137
|
|
145
138
|
# Discover available formats
|
data/lib/txt2tags/html5.rb
CHANGED
@@ -7,7 +7,9 @@ class Html5
|
|
7
7
|
bold: '<strong>\1</strong>',
|
8
8
|
italic: '<em>\1</em>',
|
9
9
|
underline: '<span style="text-decoration: underline;">\1</span>',
|
10
|
-
strike: '<span style="text-decoration: line-through;">\1</span>'
|
10
|
+
strike: '<span style="text-decoration: line-through;">\1</span>',
|
11
|
+
link: '<a href="\2">\1</a>',
|
12
|
+
image: '<img src="\1">'
|
11
13
|
}.freeze
|
12
14
|
|
13
15
|
TITLES = {
|
data/lib/txt2tags/null.rb
CHANGED
@@ -6,14 +6,16 @@ require_relative '../txt2tags'
|
|
6
6
|
# Copy and paste this file for a new format.
|
7
7
|
#
|
8
8
|
# This contain the replace part of a regexp
|
9
|
-
# "\1"
|
9
|
+
# "\1" and "\2" are the groups from the search part og regexps in main class
|
10
10
|
class Null
|
11
11
|
BEAUTIFIERS = {
|
12
12
|
monospace: 'm_\1_m',
|
13
13
|
bold: 'b_\1_b',
|
14
14
|
italic: 'i_\1_i',
|
15
15
|
underline: 'u_\1_u',
|
16
|
-
strike: 's_\1_s'
|
16
|
+
strike: 's_\1_s',
|
17
|
+
link: 'L_\1||\2_L',
|
18
|
+
image: 'I_\1_I'
|
17
19
|
}.freeze
|
18
20
|
|
19
21
|
TITLES = {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: txt2tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Henrique Rodrigues Pinheiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: htmlentities
|
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '0'
|
64
|
+
version: '2.0'
|
65
65
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|