rb_markdown 0.1.0
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 +7 -0
- data/src/markdown/abstract_tag.rb +47 -0
- data/src/markdown/bold_tag.rb +20 -0
- data/src/markdown/code_tag.rb +20 -0
- data/src/markdown/engine.rb +17 -0
- data/src/markdown/italic_tag.rb +20 -0
- data/src/rb_markdown.rb +6 -0
- metadata +62 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: c34e60501d0dc15c3235871a905f87f04a9243a0
|
|
4
|
+
data.tar.gz: 7486c070f4d9d88a715a8761716ebd3d68acfa1e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d8047e835e3c3abf4874525cb16260668066248dadbd3662ffd44506cfb28df5c03eda7e1e502336db7a77f423e32c5c6ddfa517fc09a2281ce063f6bd4111f7
|
|
7
|
+
data.tar.gz: 2dd51fda985bf2b72226e0fec461e127508f165f8e9066a144cd3b771b93d51c9f5d475e7f9d9eb94c82cbf8b9b666112be941c6b265362c1f4addc9b3ea9802
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Markdown
|
|
2
|
+
module AbstractTag
|
|
3
|
+
def initialize(value)
|
|
4
|
+
case value
|
|
5
|
+
when String
|
|
6
|
+
@string = value
|
|
7
|
+
when AbstractTag
|
|
8
|
+
@tag = value
|
|
9
|
+
else
|
|
10
|
+
raise ArgumentError.new("Invalid value of '#{value.class.name}' class")
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def to_ansi
|
|
15
|
+
string = @string || @tag.to_ansi
|
|
16
|
+
pattern = Regexp.new(
|
|
17
|
+
"(^|.+?)" \
|
|
18
|
+
"(?:#{tokens.map{ |token| "\\" + token.chars.join("\\") }.join('|')})" \
|
|
19
|
+
"(.+?)" \
|
|
20
|
+
"(?:#{tokens.map{ |token| "\\" + token.chars.join("\\") }.join('|')})" \
|
|
21
|
+
"($|.+)"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
loop do
|
|
25
|
+
string = string.sub(pattern) do
|
|
26
|
+
Regexp.last_match[1] + convert(Regexp.last_match[2]) + Regexp.last_match[3]
|
|
27
|
+
end
|
|
28
|
+
break if !Regexp.last_match
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
string
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
protected
|
|
35
|
+
|
|
36
|
+
# @return [Array<String>]
|
|
37
|
+
def tokens
|
|
38
|
+
raise NotImplementedError.new
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @param string [String]
|
|
42
|
+
# @return [String]
|
|
43
|
+
def convert(string)
|
|
44
|
+
raise NotImplementedError.new
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_relative "./abstract_tag"
|
|
2
|
+
|
|
3
|
+
module Markdown
|
|
4
|
+
class BoldTag
|
|
5
|
+
include AbstractTag
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
# @return [Array<String>]
|
|
10
|
+
def tokens
|
|
11
|
+
["**", "__"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param string [String]
|
|
15
|
+
# @return [String]
|
|
16
|
+
def convert(string)
|
|
17
|
+
string.bold
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_relative "./abstract_tag"
|
|
2
|
+
|
|
3
|
+
module Markdown
|
|
4
|
+
class CodeTag
|
|
5
|
+
include AbstractTag
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
# @return [Array<String>]
|
|
10
|
+
def tokens
|
|
11
|
+
["`"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param string [String]
|
|
15
|
+
# @return [String]
|
|
16
|
+
def convert(string)
|
|
17
|
+
string.cyan
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require_relative "./bold_tag"
|
|
2
|
+
require_relative "./code_tag"
|
|
3
|
+
require_relative "./italic_tag"
|
|
4
|
+
|
|
5
|
+
module Markdown
|
|
6
|
+
class Engine
|
|
7
|
+
def initialize(string)
|
|
8
|
+
@string = string
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def to_ansi
|
|
12
|
+
# The tags are ordered by priority.
|
|
13
|
+
# For example: `Bold` should run before `Italic`.
|
|
14
|
+
CodeTag.new(ItalicTag.new(BoldTag.new(@string))).to_ansi
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require_relative "./abstract_tag"
|
|
2
|
+
|
|
3
|
+
module Markdown
|
|
4
|
+
class ItalicTag
|
|
5
|
+
include AbstractTag
|
|
6
|
+
|
|
7
|
+
protected
|
|
8
|
+
|
|
9
|
+
# @return [Array<String>]
|
|
10
|
+
def tokens
|
|
11
|
+
["*", "_"]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# @param string [String]
|
|
15
|
+
# @return [String]
|
|
16
|
+
def convert(string)
|
|
17
|
+
string.italic
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/src/rb_markdown.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rb_markdown
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Aurélien Delogu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-01-06 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rb_monkey
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.1.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.1.0
|
|
27
|
+
description:
|
|
28
|
+
email: aurelien.delogu@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- src/markdown/abstract_tag.rb
|
|
34
|
+
- src/markdown/bold_tag.rb
|
|
35
|
+
- src/markdown/code_tag.rb
|
|
36
|
+
- src/markdown/engine.rb
|
|
37
|
+
- src/markdown/italic_tag.rb
|
|
38
|
+
- src/rb_markdown.rb
|
|
39
|
+
homepage:
|
|
40
|
+
licenses: []
|
|
41
|
+
metadata: {}
|
|
42
|
+
post_install_message:
|
|
43
|
+
rdoc_options: []
|
|
44
|
+
require_paths:
|
|
45
|
+
- src
|
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
requirements:
|
|
48
|
+
- - ">="
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '0'
|
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
requirements: []
|
|
57
|
+
rubyforge_project:
|
|
58
|
+
rubygems_version: 2.6.14.4
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 4
|
|
61
|
+
summary: A tiny markdown engine
|
|
62
|
+
test_files: []
|